buildTransferTokensTransaction
Call Signature
function buildTransferTokensTransaction<TVersion, TFeePayer>(args): Promise<{
feePayer: Readonly<{
address: Address<TAddress>;
}>;
instructions: readonly Instruction<string, readonly (AccountLookupMeta<string, string> | AccountMeta<string>)[]>[];
version: TVersion;
}>;Create a transaction that can transfer tokens to the desired wallet/owner, including creating their ATA if it does not exist
The transaction has the following defaults:
- Default
version=legacy - Default
computeUnitLimit=31_000
Example
const destination = address(...);
const transferTokensTx = await buildTransferTokensTransaction({
feePayer: signer,
latestBlockhash,
mint,
authority: signer,
amount: 900, // note: be sure to consider the mint's `decimals` value
// if decimals=2 => this will transfer 9.00 tokens
// if decimals=4 => this will transfer 0.090 tokens
destination,
// use the correct token program for the `mint`
tokenProgram, // default=TOKEN_PROGRAM_ADDRESS
// default cu limit set to be optimized, but can be overridden here
// computeUnitLimit?: number,
// obtain from your favorite priority fee api
// computeUnitPrice?: number, // no default set
});Type Parameters
| Type Parameter | Default type |
|---|---|
TVersion extends TransactionVersion | "legacy" |
TFeePayer extends TransactionSigner | TransactionSigner |
Parameters
| Parameter | Type |
|---|---|
args | { computeUnitLimit?: number | bigint; computeUnitPrice?: number | bigint; latestBlockhash?: undefined; version?: TVersion; } & { amount: number | bigint; authority: Address | TransactionSigner; destination: Address | TransactionSigner; destinationAta?: Address; feePayer: Address | TransactionSigner; mint: Address | KeyPairSigner; sourceAta?: Address; tokenProgram?: Address; } |
Returns
Promise<{
feePayer: Readonly<{
address: Address<TAddress>;
}>;
instructions: readonly Instruction<string, readonly (AccountLookupMeta<string, string> | AccountMeta<string>)[]>[];
version: TVersion;
}>
Remarks
- transferring without creating the ata is generally < 10_000cu
- validating the ata onchain during creation results in a ~15000cu fluctuation
Call Signature
function buildTransferTokensTransaction<TVersion, TFeePayer, TLifetimeConstraint>(args): Promise<{
feePayer: Readonly<{
address: Address<TAddress>;
}>;
instructions: readonly Instruction<string, readonly (AccountLookupMeta<string, string> | AccountMeta<string>)[]>[];
lifetimeConstraint: BlockhashLifetimeConstraint;
version: TVersion;
}>;Create a transaction that can transfer tokens to the desired wallet/owner, including creating their ATA if it does not exist
The transaction has the following defaults:
- Default
version=legacy - Default
computeUnitLimit=31_000
Example
const destination = address(...);
const transferTokensTx = await buildTransferTokensTransaction({
feePayer: signer,
latestBlockhash,
mint,
authority: signer,
amount: 900, // note: be sure to consider the mint's `decimals` value
// if decimals=2 => this will transfer 9.00 tokens
// if decimals=4 => this will transfer 0.090 tokens
destination,
// use the correct token program for the `mint`
tokenProgram, // default=TOKEN_PROGRAM_ADDRESS
// default cu limit set to be optimized, but can be overridden here
// computeUnitLimit?: number,
// obtain from your favorite priority fee api
// computeUnitPrice?: number, // no default set
});Type Parameters
| Type Parameter | Default type |
|---|---|
TVersion extends TransactionVersion | "legacy" |
TFeePayer extends TransactionSigner | TransactionSigner |
TLifetimeConstraint extends Readonly<{ blockhash: Blockhash; lastValidBlockHeight: bigint; }> | Readonly<{ blockhash: Blockhash; lastValidBlockHeight: bigint; }> |
Parameters
| Parameter | Type |
|---|---|
args | { computeUnitLimit?: number | bigint; computeUnitPrice?: number | bigint; latestBlockhash?: TLifetimeConstraint; version?: TVersion; } & { amount: number | bigint; authority: Address | TransactionSigner; destination: Address | TransactionSigner; destinationAta?: Address; feePayer: Address | TransactionSigner; mint: Address | KeyPairSigner; sourceAta?: Address; tokenProgram?: Address; } |
Returns
Promise<{
feePayer: Readonly<{
address: Address<TAddress>;
}>;
instructions: readonly Instruction<string, readonly (AccountLookupMeta<string, string> | AccountMeta<string>)[]>[];
lifetimeConstraint: BlockhashLifetimeConstraint;
version: TVersion;
}>
Remarks
- transferring without creating the ata is generally < 10_000cu
- validating the ata onchain during creation results in a ~15000cu fluctuation