Options
All
  • Public
  • Public/Protected
  • All
Menu

@project-serum/anchor - v0.26.0

Index

Type Aliases

AccountNamespace<IDL>: { [ M in keyof AllAccountsMap<IDL>]: AccountClient<IDL> }

The namespace provides handles to an AccountClient object for each account in a program.

Usage

account.<account-client>

Example

To fetch a Counter account from the above example,

const counter = await program.account.counter.fetch(address);

For the full API, see the AccountClient reference.

Type Parameters

Accounts<A>: { [ N in A["name"]]: Account<A & { name: N }> }

A set of accounts mapping one-to-one to the program's accounts struct, i.e., the type deriving #[derive(Accounts)].

The name of each field should match the name for that account in the IDL.

If multiple accounts are nested in the rust program, then they should be nested here.

Type Parameters

  • A extends IdlAccountItem = IdlAccountItem

Address: PublicKey | string

An address to identify an account on chain. Can be a PublicKey, or Base 58 encoded string.

Context<A>: { accounts?: A; instructions?: TransactionInstruction[]; options?: ConfirmOptions; postInstructions?: TransactionInstruction[]; preInstructions?: TransactionInstruction[]; remainingAccounts?: AccountMeta[]; signers?: Signer[] }

Context provides all non-argument inputs for generating Anchor transactions.

Type Parameters

Type declaration

  • Optional accounts?: A

    Accounts used in the instruction context.

  • Optional instructions?: TransactionInstruction[]
    deprecated

    use preInstructions instead. Instructions to run before a given method. Often this is used, for example to create accounts prior to executing a method.

  • Optional options?: ConfirmOptions

    Commitment parameters to use for a transaction.

  • Optional postInstructions?: TransactionInstruction[]

    Instructions to run after a given method. Often this is used, for example to close accounts after executing a method.

  • Optional preInstructions?: TransactionInstruction[]

    Instructions to run before a given method. Often this is used, for example to create accounts prior to executing a method.

  • Optional remainingAccounts?: AccountMeta[]

    All accounts to pass into an instruction after the main accounts. This can be used for optional or otherwise unknown accounts.

  • Optional signers?: Signer[]

    Accounts that must sign a given transaction.

CustomAccountResolver<IDL>: ((params: { accounts: AccountsGeneric; args: any[]; idlIx: AllInstructions<IDL>; programId: PublicKey; provider: Provider }) => Promise<{ accounts: AccountsGeneric; resolved: number }>)

Type Parameters

  • IDL extends Idl

Type declaration

    • (params: { accounts: AccountsGeneric; args: any[]; idlIx: AllInstructions<IDL>; programId: PublicKey; provider: Provider }): Promise<{ accounts: AccountsGeneric; resolved: number }>
    • Parameters

      • params: { accounts: AccountsGeneric; args: any[]; idlIx: AllInstructions<IDL>; programId: PublicKey; provider: Provider }
        • accounts: AccountsGeneric
        • args: any[]
        • idlIx: AllInstructions<IDL>
        • programId: PublicKey
        • provider: Provider

      Returns Promise<{ accounts: AccountsGeneric; resolved: number }>

DecodeType<T, Defined>: T extends keyof TypeMap ? TypeMap[T] : T extends { defined: keyof Defined } ? Defined[T["defined"]] : T extends { option: { defined: keyof Defined } } ? Defined[T["option"]["defined"]] | null : T extends { option: keyof TypeMap } ? TypeMap[T["option"]] | null : T extends { coption: { defined: keyof Defined } } ? Defined[T["coption"]["defined"]] | null : T extends { coption: keyof TypeMap } ? TypeMap[T["coption"]] | null : T extends { vec: keyof TypeMap } ? TypeMap[T["vec"]][] : T extends { vec: { defined: keyof Defined } } ? Defined[T["vec"]["defined"]][] : T extends { array: [defined: keyof TypeMap, size: number] } ? TypeMap[T["array"][0]][] : unknown

Type Parameters

  • T extends IdlType

  • Defined

Event<E, Defined>: { data: EventData<E["fields"][number], Defined>; name: E["name"] }

Type Parameters

  • E extends IdlEvent = IdlEvent

  • Defined = Record<string, never>

Type declaration

  • data: EventData<E["fields"][number], Defined>
  • name: E["name"]
EventData<T, Defined>: { [ N in T["name"]]: DecodeType<(T & { name: N })["type"], Defined> }

Type Parameters

  • T extends IdlEventField

  • Defined

Idl: { accounts?: IdlAccountDef[]; constants?: IdlConstant[]; docs?: string[]; errors?: IdlErrorCode[]; events?: IdlEvent[]; instructions: IdlInstruction[]; metadata?: IdlMetadata; name: string; state?: IdlState; types?: IdlTypeDef[]; version: string }

Type declaration

  • Optional accounts?: IdlAccountDef[]
  • Optional constants?: IdlConstant[]
  • Optional docs?: string[]
  • Optional errors?: IdlErrorCode[]
  • Optional events?: IdlEvent[]
  • instructions: IdlInstruction[]
  • Optional metadata?: IdlMetadata
  • name: string
  • Optional state?: IdlState
  • Optional types?: IdlTypeDef[]
  • version: string
IdlAccounts<T>: TypeDefDictionary<NonNullable<T["accounts"]>, IdlTypes<T>>

Type Parameters

IdlEvents<I, Defined>: { [ E in NonNullable<I["events"]>[number] as E["name"]]: IdlEventType<I, E, Defined> }

Type Parameters

IdlTypes<T>: RecursiveTypes<NonNullable<T["types"]>>

Type Parameters

Instruction: { data: Object; name: string }

Type declaration

  • data: Object
  • name: string
InstructionFn<IDL, I>: InstructionContextFn<IDL, I, TransactionInstruction> & IxProps<Accounts<I["accounts"][number]>>

Function to create a TransactionInstruction generated from an IDL. Additionally it provides an accounts utility method, returning a list of ordered accounts for the instruction.

Type Parameters

  • IDL extends Idl = Idl

  • I extends AllInstructions<IDL> = AllInstructions<IDL>

InstructionNamespace<IDL, I>: MakeInstructionsNamespace<IDL, I, TransactionInstruction, { [ M in keyof AllInstructionsMap<IDL>]: { accounts: any } }>

The namespace provides functions to build TransactionInstruction objects for each method of a program.

Usage

instruction.<method>(...args, ctx);

Parameters

  1. args - The positional arguments for the program. The type and number of these arguments depend on the program being used.
  2. ctx - Context non-argument parameters to pass to the method. Always the last parameter in the method call.

Example

To create an instruction for the increment method above,

const tx = await program.instruction.increment({
accounts: {
counter,
},
});

Type Parameters

  • IDL extends Idl = Idl

  • I extends IdlInstruction = IDL["instructions"][number]

MethodsNamespace<IDL, I>: MakeMethodsNamespace<IDL, I>

Type Parameters

  • IDL extends Idl = Idl

  • I extends AllInstructions<IDL> = AllInstructions<IDL>

RpcFn<IDL, I>: InstructionContextFn<IDL, I, Promise<TransactionSignature>>

RpcFn is a single RPC method generated from an IDL, sending a transaction paid for and signed by the configured provider.

Type Parameters

  • IDL extends Idl = Idl

  • I extends AllInstructions<IDL> = AllInstructions<IDL>

RpcNamespace<IDL, I>: MakeInstructionsNamespace<IDL, I, Promise<TransactionSignature>>

The namespace provides async methods to send signed transactions for each non-state method on Anchor program.

Keys are method names, values are RPC functions returning a TransactionInstruction.

Usage

rpc.<method>(...args, ctx);

Parameters

  1. args - The positional arguments for the program. The type and number of these arguments depend on the program being used.
  2. ctx - Context non-argument parameters to pass to the method. Always the last parameter in the method call.

## Example

To send a transaction invoking the `increment` method above,

```javascript
const txSignature = await program.rpc.increment({
accounts: {
counter,
authority,
},
});

Type Parameters

  • IDL extends Idl = Idl

  • I extends AllInstructions<IDL> = AllInstructions<IDL>

SimulateFn<IDL, I>: InstructionContextFn<IDL, I, Promise<SimulateResponse<NullableEvents<IDL>, IdlTypes<IDL>>>>

SimulateFn is a single method generated from an IDL. It simulates a method against a cluster configured by the provider, returning a list of all the events and raw logs that were emitted during the execution of the method.

Type Parameters

  • IDL extends Idl = Idl

  • I extends AllInstructions<IDL> = AllInstructions<IDL>

SimulateNamespace<IDL, I>: MakeInstructionsNamespace<IDL, I, Promise<SimulateResponse<NullableEvents<IDL>, IdlTypes<IDL>>>>

The namespace provides functions to simulate transactions for each method of a program, returning a list of deserialized events and raw program logs.

One can use this to read data calculated from a program on chain, by emitting an event in the program and reading the emitted event client side via the simulate namespace.

Usage

program.simulate.<method>(...args, ctx);

Parameters

  1. args - The positional arguments for the program. The type and number of these arguments depend on the program being used.
  2. ctx - Context non-argument parameters to pass to the method. Always the last parameter in the method call.

Example

To simulate the increment method above,

const events = await program.simulate.increment({
accounts: {
counter,
},
});

Type Parameters

  • IDL extends Idl = Idl

  • I extends AllInstructions<IDL> = AllInstructions<IDL>

Subscription: { ee: EventEmitter; listener: number }

Type declaration

  • ee: EventEmitter
  • listener: number
SystemProgram: { accounts: [{ name: "nonce"; type: { fields: [{ name: "version"; type: "u32" }, { name: "state"; type: "u32" }, { name: "authorizedPubkey"; type: "publicKey" }, { name: "nonce"; type: "publicKey" }, { name: "feeCalculator"; type: { defined: "FeeCalculator" } }]; kind: "struct" } }]; instructions: [{ accounts: [{ isMut: true; isSigner: true; name: "from" }, { isMut: true; isSigner: true; name: "to" }]; args: [{ name: "lamports"; type: "u64" }, { name: "space"; type: "u64" }, { name: "owner"; type: "publicKey" }]; name: "createAccount" }, { accounts: [{ isMut: true; isSigner: true; name: "pubkey" }]; args: [{ name: "owner"; type: "publicKey" }]; name: "assign" }, { accounts: [{ isMut: true; isSigner: true; name: "from" }, { isMut: true; isSigner: false; name: "to" }]; args: [{ name: "lamports"; type: "u64" }]; name: "transfer" }, { accounts: [{ isMut: true; isSigner: true; name: "from" }, { isMut: true; isSigner: false; name: "to" }, { isMut: false; isSigner: true; name: "base" }]; args: [{ name: "base"; type: "publicKey" }, { name: "seed"; type: "string" }, { name: "lamports"; type: "u64" }, { name: "space"; type: "u64" }, { name: "owner"; type: "publicKey" }]; name: "createAccountWithSeed" }, { accounts: [{ isMut: true; isSigner: false; name: "nonce" }, { isMut: false; isSigner: false; name: "recentBlockhashes" }, { isMut: false; isSigner: true; name: "authorized" }]; args: [{ name: "authorized"; type: "publicKey" }]; name: "advanceNonceAccount" }, { accounts: [{ isMut: true; isSigner: false; name: "nonce" }, { isMut: true; isSigner: false; name: "to" }, { isMut: false; isSigner: false; name: "recentBlockhashes" }, { isMut: false; isSigner: false; name: "rent" }, { isMut: false; isSigner: true; name: "authorized" }]; args: [{ name: "lamports"; type: "u64" }]; name: "withdrawNonceAccount" }, { accounts: [{ isMut: true; isSigner: true; name: "nonce" }, { isMut: false; isSigner: false; name: "recentBlockhashes" }, { isMut: false; isSigner: false; name: "rent" }]; args: [{ name: "authorized"; type: "publicKey" }]; name: "initializeNonceAccount" }, { accounts: [{ isMut: true; isSigner: false; name: "nonce" }, { isMut: false; isSigner: true; name: "authorized" }]; args: [{ name: "authorized"; type: "publicKey" }]; name: "authorizeNonceAccount" }, { accounts: [{ isMut: true; isSigner: true; name: "pubkey" }]; args: [{ name: "space"; type: "u64" }]; name: "allocate" }, { accounts: [{ isMut: true; isSigner: false; name: "account" }, { isMut: false; isSigner: true; name: "base" }]; args: [{ name: "base"; type: "publicKey" }, { name: "seed"; type: "string" }, { name: "space"; type: "u64" }, { name: "owner"; type: "publicKey" }]; name: "allocateWithSeed" }, { accounts: [{ isMut: true; isSigner: false; name: "account" }, { isMut: false; isSigner: true; name: "base" }]; args: [{ name: "base"; type: "publicKey" }, { name: "seed"; type: "string" }, { name: "owner"; type: "publicKey" }]; name: "assignWithSeed" }, { accounts: [{ isMut: true; isSigner: false; name: "from" }, { isMut: false; isSigner: true; name: "base" }, { isMut: true; isSigner: false; name: "to" }]; args: [{ name: "lamports"; type: "u64" }, { name: "seed"; type: "string" }, { name: "owner"; type: "publicKey" }]; name: "transferWithSeed" }]; name: "system_program"; types: [{ name: "FeeCalculator"; type: { fields: [{ name: "lamportsPerSignature"; type: "u64" }]; kind: "struct" } }]; version: "0.1.0" }

System IDL.

Type declaration

  • accounts: [{ name: "nonce"; type: { fields: [{ name: "version"; type: "u32" }, { name: "state"; type: "u32" }, { name: "authorizedPubkey"; type: "publicKey" }, { name: "nonce"; type: "publicKey" }, { name: "feeCalculator"; type: { defined: "FeeCalculator" } }]; kind: "struct" } }]
  • instructions: [{ accounts: [{ isMut: true; isSigner: true; name: "from" }, { isMut: true; isSigner: true; name: "to" }]; args: [{ name: "lamports"; type: "u64" }, { name: "space"; type: "u64" }, { name: "owner"; type: "publicKey" }]; name: "createAccount" }, { accounts: [{ isMut: true; isSigner: true; name: "pubkey" }]; args: [{ name: "owner"; type: "publicKey" }]; name: "assign" }, { accounts: [{ isMut: true; isSigner: true; name: "from" }, { isMut: true; isSigner: false; name: "to" }]; args: [{ name: "lamports"; type: "u64" }]; name: "transfer" }, { accounts: [{ isMut: true; isSigner: true; name: "from" }, { isMut: true; isSigner: false; name: "to" }, { isMut: false; isSigner: true; name: "base" }]; args: [{ name: "base"; type: "publicKey" }, { name: "seed"; type: "string" }, { name: "lamports"; type: "u64" }, { name: "space"; type: "u64" }, { name: "owner"; type: "publicKey" }]; name: "createAccountWithSeed" }, { accounts: [{ isMut: true; isSigner: false; name: "nonce" }, { isMut: false; isSigner: false; name: "recentBlockhashes" }, { isMut: false; isSigner: true; name: "authorized" }]; args: [{ name: "authorized"; type: "publicKey" }]; name: "advanceNonceAccount" }, { accounts: [{ isMut: true; isSigner: false; name: "nonce" }, { isMut: true; isSigner: false; name: "to" }, { isMut: false; isSigner: false; name: "recentBlockhashes" }, { isMut: false; isSigner: false; name: "rent" }, { isMut: false; isSigner: true; name: "authorized" }]; args: [{ name: "lamports"; type: "u64" }]; name: "withdrawNonceAccount" }, { accounts: [{ isMut: true; isSigner: true; name: "nonce" }, { isMut: false; isSigner: false; name: "recentBlockhashes" }, { isMut: false; isSigner: false; name: "rent" }]; args: [{ name: "authorized"; type: "publicKey" }]; name: "initializeNonceAccount" }, { accounts: [{ isMut: true; isSigner: false; name: "nonce" }, { isMut: false; isSigner: true; name: "authorized" }]; args: [{ name: "authorized"; type: "publicKey" }]; name: "authorizeNonceAccount" }, { accounts: [{ isMut: true; isSigner: true; name: "pubkey" }]; args: [{ name: "space"; type: "u64" }]; name: "allocate" }, { accounts: [{ isMut: true; isSigner: false; name: "account" }, { isMut: false; isSigner: true; name: "base" }]; args: [{ name: "base"; type: "publicKey" }, { name: "seed"; type: "string" }, { name: "space"; type: "u64" }, { name: "owner"; type: "publicKey" }]; name: "allocateWithSeed" }, { accounts: [{ isMut: true; isSigner: false; name: "account" }, { isMut: false; isSigner: true; name: "base" }]; args: [{ name: "base"; type: "publicKey" }, { name: "seed"; type: "string" }, { name: "owner"; type: "publicKey" }]; name: "assignWithSeed" }, { accounts: [{ isMut: true; isSigner: false; name: "from" }, { isMut: false; isSigner: true; name: "base" }, { isMut: true; isSigner: false; name: "to" }]; args: [{ name: "lamports"; type: "u64" }, { name: "seed"; type: "string" }, { name: "owner"; type: "publicKey" }]; name: "transferWithSeed" }]
  • name: "system_program"
  • types: [{ name: "FeeCalculator"; type: { fields: [{ name: "lamportsPerSignature"; type: "u64" }]; kind: "struct" } }]
  • version: "0.1.0"
TransactionFn<IDL, I>: InstructionContextFn<IDL, I, Transaction>

Tx is a function to create a Transaction for a given program instruction.

Type Parameters

  • IDL extends Idl = Idl

  • I extends AllInstructions<IDL> = AllInstructions<IDL>

TransactionNamespace<IDL, I>: MakeInstructionsNamespace<IDL, I, Transaction>

The namespace provides functions to build Transaction objects for each method of a program.

Usage

program.transaction.<method>(...args, ctx);

Parameters

  1. args - The positional arguments for the program. The type and number of these arguments depend on the program being used.
  2. ctx - Context non-argument parameters to pass to the method. Always the last parameter in the method call.

Example

To create an instruction for the increment method above,

const tx = await program.transaction.increment({
accounts: {
counter,
},
});

Type Parameters

  • IDL extends Idl = Idl

  • I extends AllInstructions<IDL> = AllInstructions<IDL>

ViewFn<IDL, I>: InstructionContextFn<IDL, I, Promise<any>>

ViewFn is a single method generated from an IDL. It simulates a method against a cluster configured by the provider, and then parses the events and extracts return data from the raw logs emitted during the simulation.

Type Parameters

  • IDL extends Idl = Idl

  • I extends AllInstructions<IDL> = AllInstructions<IDL>

ViewNamespace<IDL, I>: MakeInstructionsNamespace<IDL, I, Promise<any>>

Type Parameters

  • IDL extends Idl = Idl

  • I extends AllInstructions<IDL> = AllInstructions<IDL>

Variables

ACCOUNT_DISCRIMINATOR_SIZE: 8 = 8

Number of bytes of the account discriminator.

LangErrorCode: { AccountDidNotDeserialize: number; AccountDidNotSerialize: number; AccountDiscriminatorAlreadySet: number; AccountDiscriminatorMismatch: number; AccountDiscriminatorNotFound: number; AccountDuplicateReallocs: number; AccountNotAssociatedTokenAccount: number; AccountNotEnoughKeys: number; AccountNotInitialized: number; AccountNotMutable: number; AccountNotProgramData: number; AccountNotSigner: number; AccountNotSystemOwned: number; AccountOwnedByWrongProgram: number; AccountReallocExceedsLimit: number; AccountSysvarMismatch: number; ConstraintAccountIsNone: number; ConstraintAddress: number; ConstraintAssociated: number; ConstraintAssociatedInit: number; ConstraintClose: number; ConstraintExecutable: number; ConstraintHasOne: number; ConstraintMintDecimals: number; ConstraintMintFreezeAuthority: number; ConstraintMintMintAuthority: number; ConstraintMut: number; ConstraintOwner: number; ConstraintRaw: number; ConstraintRentExempt: number; ConstraintSeeds: number; ConstraintSigner: number; ConstraintSpace: number; ConstraintState: number; ConstraintTokenMint: number; ConstraintTokenOwner: number; ConstraintZero: number; DeclaredProgramIdMismatch: number; Deprecated: number; IdlInstructionInvalidProgram: number; IdlInstructionStub: number; InstructionDidNotDeserialize: number; InstructionDidNotSerialize: number; InstructionFallbackNotFound: number; InstructionMissing: number; InvalidProgramExecutable: number; InvalidProgramId: number; RequireEqViolated: number; RequireGtViolated: number; RequireGteViolated: number; RequireKeysEqViolated: number; RequireKeysNeqViolated: number; RequireNeqViolated: number; RequireViolated: number; StateInvalidAddress: number } = ...

Type declaration

  • AccountDidNotDeserialize: number
  • AccountDidNotSerialize: number
  • AccountDiscriminatorAlreadySet: number
  • AccountDiscriminatorMismatch: number
  • AccountDiscriminatorNotFound: number
  • AccountDuplicateReallocs: number
  • AccountNotAssociatedTokenAccount: number
  • AccountNotEnoughKeys: number
  • AccountNotInitialized: number
  • AccountNotMutable: number
  • AccountNotProgramData: number
  • AccountNotSigner: number
  • AccountNotSystemOwned: number
  • AccountOwnedByWrongProgram: number
  • AccountReallocExceedsLimit: number
  • AccountSysvarMismatch: number
  • ConstraintAccountIsNone: number
  • ConstraintAddress: number
  • ConstraintAssociated: number
  • ConstraintAssociatedInit: number
  • ConstraintClose: number
  • ConstraintExecutable: number
  • ConstraintHasOne: number
  • ConstraintMintDecimals: number
  • ConstraintMintFreezeAuthority: number
  • ConstraintMintMintAuthority: number
  • ConstraintMut: number
  • ConstraintOwner: number
  • ConstraintRaw: number
  • ConstraintRentExempt: number
  • ConstraintSeeds: number
  • ConstraintSigner: number
  • ConstraintSpace: number
  • ConstraintState: number
  • ConstraintTokenMint: number
  • ConstraintTokenOwner: number
  • ConstraintZero: number
  • DeclaredProgramIdMismatch: number
  • Deprecated: number
  • IdlInstructionInvalidProgram: number
  • IdlInstructionStub: number
  • InstructionDidNotDeserialize: number
  • InstructionDidNotSerialize: number
  • InstructionFallbackNotFound: number
  • InstructionMissing: number
  • InvalidProgramExecutable: number
  • InvalidProgramId: number
  • RequireEqViolated: number
  • RequireGtViolated: number
  • RequireGteViolated: number
  • RequireKeysEqViolated: number
  • RequireKeysNeqViolated: number
  • RequireNeqViolated: number
  • RequireViolated: number
  • StateInvalidAddress: number
LangErrorMessage: Map<number, string> = ...
workspace: any

Functions

  • eventDiscriminator(name: string): Buffer
  • parseIdlErrors(idl: Idl): Map<number, string>
  • splitArgsAndCtx(idlIx: IdlInstruction, args: any[]): [any[], Context]
  • stateDiscriminator(name: string): Promise<Buffer>
  • toInstruction(idlIx: IdlInstruction, ...args: any[]): {}
  • translateError(err: any, idlErrors: Map<number, string>): any
  • validateAccounts(ixAccounts: IdlAccountItem[], accounts?: Accounts<IdlAccountItem>): void

Generated using TypeDoc