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 |
approveInstruction(owner: PublicKey, account: PublicKey, delegate: PublicKey, amount: number | TokenAmount): TransactionInstruction Construct an Approve instruction |
|
public |
async newAccount(owner: Account, source: nullliteral | PublicKey): Promise<PublicKey> Create a new and empty token account. |
|
public |
Remove approval for the transfer of any remaining tokens |
|
public |
revokeInstruction(owner: PublicKey, account: PublicKey, delegate: PublicKey): TransactionInstruction Construct an Revoke instruction |
|
public |
Assign a new owner to the account |
|
public |
setOwnerInstruction(owner: PublicKey, account: PublicKey, newOwner: PublicKey): TransactionInstruction Construct a SetOwner instruction |
|
public |
Retrieve token information |
|
public |
async transfer(owner: Account, source: PublicKey, destination: PublicKey, amount: number | TokenAmount): Promise<void> Transfer tokens to another account |
|
public |
async transferInstruction(owner: PublicKey, source: PublicKey, destination: PublicKey, amount: number | TokenAmount): Promise<TransactionInstruction> 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:
Name | Type | Attribute | Description |
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 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:
Name | Type | Attribute | Description |
connection | Connection | The connection to use |
|
token | PublicKey | Public key of the token |
|
programId | PublicKey |
|
Optional token programId, uses the system programId by default |
Public Members
Public Methods
public async accountInfo(account: PublicKey): Promise<TokenAccountInfo> source
Retrieve account information
Params:
Name | Type | Attribute | Description |
account | PublicKey | Public key of the token account |
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:
Name | Type | Attribute | Description |
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 |
public approveInstruction(owner: PublicKey, account: PublicKey, delegate: PublicKey, amount: number | TokenAmount): TransactionInstruction source
Construct an Approve instruction
Params:
Name | Type | Attribute | Description |
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
public revoke(owner: Account, account: PublicKey, delegate: PublicKey): Promise<void> source
Remove approval for the transfer of any remaining tokens
public revokeInstruction(owner: PublicKey, account: PublicKey, delegate: PublicKey): TransactionInstruction source
Construct an Revoke instruction
public async setOwner(owner: Account, account: PublicKey, newOwner: PublicKey): Promise<void> source
Assign a new owner to the account
public setOwnerInstruction(owner: PublicKey, account: PublicKey, newOwner: PublicKey): TransactionInstruction source
Construct a SetOwner instruction
public async transfer(owner: Account, source: PublicKey, destination: PublicKey, amount: number | TokenAmount): Promise<void> source
Transfer tokens to another account
Params:
Name | Type | Attribute | Description |
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:
Name | Type | Attribute | Description |
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 |