Complete API reference for the built-in OP20 fungible token helper.
Import: import { OP20 } from '@btc-vision/unit-test-framework'
Extends: ContractRuntime
new OP20(details: OP20Interface)interface OP20Interface extends ContractDetails {
readonly file: string; // Path to compiled .wasm file
readonly decimals: number; // Token decimals (e.g. 8, 18)
}const token = new OP20({
address: Blockchain.generateRandomAddress(),
deployer: deployer,
file: './bytecodes/MyToken.wasm',
decimals: 18,
gasLimit: 150_000_000_000n, // Optional
});| Property | Type | Description |
|---|---|---|
file |
string |
Path to the WASM bytecode file |
decimals |
number |
Token decimal places |
address |
Address |
Contract address |
deployer |
Address |
Deployer address |
gasUsed |
bigint |
Cumulative gas used |
async totalSupply(): Promise<bigint>Returns the total token supply in raw units.
async balanceOf(owner: Address): Promise<bigint>Returns the token balance of owner in raw units.
async balanceOfNoDecimals(owner: Address): Promise<number>Returns the token balance of owner divided by 10^decimals.
async allowance(owner: Address, spender: Address): Promise<bigint>Returns the allowance spender has to spend from owner.
async nonceOf(owner: Address): Promise<bigint>Returns the signature nonce for owner.
async metadata(): Promise<{ metadata: OP20Metadata; response: CallResponse }>Returns token metadata:
interface OP20Metadata {
readonly name: string;
readonly symbol: string;
readonly decimals: number;
readonly totalSupply: bigint;
readonly maximumSupply: bigint;
readonly icon: string;
readonly domainSeparator: Uint8Array;
}async domainSeparator(): Promise<Uint8Array>Returns the EIP-712-style domain separator (32 bytes).
async mint(to: Address, amount: number): Promise<void>Mints amount tokens (in whole units, automatically expanded by 10^decimals).
async mintRaw(to: Address, amount: bigint): Promise<void>Mints amount tokens in raw units (no decimal expansion).
async safeTransfer(from: Address, to: Address, amount: bigint, data?: Uint8Array): Promise<CallResponse>Transfers amount raw tokens from from to to.
async safeTransferFrom(from: Address, to: Address, amount: bigint, data?: Uint8Array): Promise<void>Transfers amount from from on behalf of the sender (requires allowance).
async burn(from: Address, amount: bigint): Promise<CallResponse>Burns amount raw tokens from from.
async airdrop(map: AddressMap<bigint>): Promise<CallResponse>Batch mints to multiple addresses.
async increaseAllowance(owner: Address, spender: Address, amount: bigint): Promise<CallResponse>Increases spender's allowance from owner by amount.
async decreaseAllowance(owner: Address, spender: Address, amount: bigint): Promise<CallResponse>Decreases spender's allowance from owner by amount.
async increaseAllowanceBySignature(
owner: Address, spender: Address, amount: bigint,
deadline: bigint, signature: Uint8Array
): Promise<CallResponse>async decreaseAllowanceBySignature(
owner: Address, spender: Address, amount: bigint,
deadline: bigint, signature: Uint8Array
): Promise<CallResponse>static decodeTransferredEvent(data: Buffer | Uint8Array): TransferredEventinterface TransferredEvent {
readonly operator: Address;
readonly from: Address;
readonly to: Address;
readonly value: bigint;
}static decodeMintedEvent(data: Buffer | Uint8Array): MintedEventinterface MintedEvent {
readonly to: Address;
readonly value: bigint;
}static decodeBurnedEvent(data: Buffer | Uint8Array): BurnedEventinterface BurnedEvent {
readonly from: Address;
readonly value: bigint;
}static decodeApprovedEvent(data: Buffer | Uint8Array): ApprovedEventinterface ApprovedEvent {
readonly owner: Address;
readonly spender: Address;
readonly value: bigint;
}