Home Reference Source
import {Token} from '@solana/web3'
public class | source

Token

An ERC20-like Token

Static Method Summary

Static Public Methods
public static

async createNewToken(connection: Connection, owner: Account, supply: TokenAmount, name: string, symbol: string, decimals: number, programId: PublicKey): Promise<TokenAndPublicKey>

Create a new Token

Constructor Summary

Public Constructor
public

constructor(connection: Connection, token: PublicKey, programId: PublicKey)

Create a Token object attached to the specific token

Member Summary

Public Members
public

Program Identifier for the Token program

public

The public key identifying this token

Method Summary

Public Methods
public

async accountInfo(account: PublicKey): Promise<TokenAccountInfo>

Retrieve account information

public

async approve(owner: Account, account: PublicKey, delegate: PublicKey, amount: number | TokenAmount): Promise<void>

Grant a third-party permission to transfer up the specified number of tokens from an account

public

Construct an Approve instruction

public

async newAccount(owner: Account, source: nullliteral | PublicKey): Promise<PublicKey>

Create a new and empty token account.

public

revoke(owner: Account, account: PublicKey, delegate: PublicKey): Promise<void>

Remove approval for the transfer of any remaining tokens

public

Construct an Revoke instruction

public

async setOwner(owner: Account, account: PublicKey, newOwner: PublicKey): Promise<void>

Assign a new owner to the account

public

Construct a SetOwner instruction

public

async tokenInfo(): Promise<TokenInfo>

Retrieve token information

public

async transfer(owner: Account, source: PublicKey, destination: PublicKey, amount: number | TokenAmount): PromiseTransactionSignature>

Transfer tokens to another account

public

Construct a Transfer instruction

Static Public Methods

public static async createNewToken(connection: Connection, owner: Account, supply: TokenAmount, name: string, symbol: string, decimals: number, programId: PublicKey): Promise<TokenAndPublicKey> source

Create a new Token

Params:

NameTypeAttributeDescription
connection Connection

The connection to use

owner Account

User account that will own the returned Token Account

supply TokenAmount

Total supply of the new token

name string

Descriptive name of this token

symbol string

Symbol for this token

decimals number

Location of the decimal place

programId PublicKey
  • optional
  • default: undefined

Optional token programId, uses the system programId by default

Return:

Promise<TokenAndPublicKey>

Token object for the newly minted token, Public key of the Token Account holding the total supply of new tokens

Public Constructors

public constructor(connection: Connection, token: PublicKey, programId: PublicKey) source

Create a Token object attached to the specific token

Params:

NameTypeAttributeDescription
connection Connection

The connection to use

token PublicKey

Public key of the token

programId PublicKey
  • optional
  • default: undefined

Optional token programId, uses the system programId by default

Public Members

public programId: PublicKey source

Program Identifier for the Token program

public token: PublicKey source

The public key identifying this token

Public Methods

public async accountInfo(account: PublicKey): Promise<TokenAccountInfo> source

Retrieve account information

Params:

NameTypeAttributeDescription
account PublicKey

Public key of the token account

Return:

Promise<TokenAccountInfo>

public async approve(owner: Account, account: PublicKey, delegate: PublicKey, amount: number | TokenAmount): Promise<void> source

Grant a third-party permission to transfer up the specified number of tokens from an account

Params:

NameTypeAttributeDescription
owner Account

Owner of the source token account

account PublicKey

Public key of the token account

delegate PublicKey

Token account authorized to perform a transfer tokens from the source account

amount number | TokenAmount

Maximum number of tokens the delegate may transfer

Return:

Promise<void>

public approveInstruction(owner: PublicKey, account: PublicKey, delegate: PublicKey, amount: number | TokenAmount): TransactionInstruction source

Construct an Approve instruction

Params:

NameTypeAttributeDescription
owner PublicKey

Owner of the source token account

account PublicKey

Public key of the token account

delegate PublicKey

Token account authorized to perform a transfer tokens from the source account

amount number | TokenAmount

Maximum number of tokens the delegate may transfer

public async newAccount(owner: Account, source: nullliteral | PublicKey): Promise<PublicKey> source

Create a new and empty token account.

This account may then be used as a transfer() or approve() destination

Params:

NameTypeAttributeDescription
owner Account

User account that will own the new token account

source nullliteral | PublicKey
  • optional
  • default: undefined

If not null, create a delegate account that when authorized may transfer tokens from this source account

Return:

Promise<PublicKey>

Public key of the new empty token account

public revoke(owner: Account, account: PublicKey, delegate: PublicKey): Promise<void> source

Remove approval for the transfer of any remaining tokens

Params:

NameTypeAttributeDescription
owner Account

Owner of the source token account

account PublicKey

Public key of the token account

delegate PublicKey

Token account to revoke authorization from

Return:

Promise<void>

public revokeInstruction(owner: PublicKey, account: PublicKey, delegate: PublicKey): TransactionInstruction source

Construct an Revoke instruction

Params:

NameTypeAttributeDescription
owner PublicKey

Owner of the source token account

account PublicKey

Public key of the token account

delegate PublicKey

Token account authorized to perform a transfer tokens from the source account

public async setOwner(owner: Account, account: PublicKey, newOwner: PublicKey): Promise<void> source

Assign a new owner to the account

Params:

NameTypeAttributeDescription
owner Account

Owner of the token account

account PublicKey

Public key of the token account

newOwner PublicKey

New owner of the token account

Return:

Promise<void>

public setOwnerInstruction(owner: PublicKey, account: PublicKey, newOwner: PublicKey): TransactionInstruction source

Construct a SetOwner instruction

Params:

NameTypeAttributeDescription
owner PublicKey

Owner of the token account

account PublicKey

Public key of the token account

newOwner PublicKey

New owner of the token account

public async tokenInfo(): Promise<TokenInfo> source

Retrieve token information

Return:

Promise<TokenInfo>

public async transfer(owner: Account, source: PublicKey, destination: PublicKey, amount: number | TokenAmount): PromiseTransactionSignature> source

Transfer tokens to another account

Params:

NameTypeAttributeDescription
owner Account

Owner of the source token account

source PublicKey

Source token account

destination PublicKey

Destination token account

amount number | TokenAmount

Number of tokens to transfer

public async transferInstruction(owner: PublicKey, source: PublicKey, destination: PublicKey, amount: number | TokenAmount): Promise<TransactionInstruction> source

Construct a Transfer instruction

Params:

NameTypeAttributeDescription
owner PublicKey

Owner of the source token account

source PublicKey

Source token account

destination PublicKey

Destination token account

amount number | TokenAmount

Number of tokens to transfer