Skip to content

Latest commit

 

History

History
268 lines (186 loc) · 5.34 KB

File metadata and controls

268 lines (186 loc) · 5.34 KB

OP20 API Reference

Complete API reference for the built-in OP20 fungible token helper.

Import: import { OP20 } from '@btc-vision/unit-test-framework' Extends: ContractRuntime


Constructor

new OP20(details: OP20Interface)

OP20Interface

interface OP20Interface extends ContractDetails {
    readonly file: string;     // Path to compiled .wasm file
    readonly decimals: number; // Token decimals (e.g. 8, 18)
}

Example

const token = new OP20({
    address: Blockchain.generateRandomAddress(),
    deployer: deployer,
    file: './bytecodes/MyToken.wasm',
    decimals: 18,
    gasLimit: 150_000_000_000n, // Optional
});

Properties

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

Read Methods

totalSupply()

async totalSupply(): Promise<bigint>

Returns the total token supply in raw units.

balanceOf(owner)

async balanceOf(owner: Address): Promise<bigint>

Returns the token balance of owner in raw units.

balanceOfNoDecimals(owner)

async balanceOfNoDecimals(owner: Address): Promise<number>

Returns the token balance of owner divided by 10^decimals.

allowance(owner, spender)

async allowance(owner: Address, spender: Address): Promise<bigint>

Returns the allowance spender has to spend from owner.

nonceOf(owner)

async nonceOf(owner: Address): Promise<bigint>

Returns the signature nonce for owner.

metadata()

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;
}

domainSeparator()

async domainSeparator(): Promise<Uint8Array>

Returns the EIP-712-style domain separator (32 bytes).


Write Methods

mint(to, amount)

async mint(to: Address, amount: number): Promise<void>

Mints amount tokens (in whole units, automatically expanded by 10^decimals).

mintRaw(to, amount)

async mintRaw(to: Address, amount: bigint): Promise<void>

Mints amount tokens in raw units (no decimal expansion).

safeTransfer(from, to, amount)

async safeTransfer(from: Address, to: Address, amount: bigint, data?: Uint8Array): Promise<CallResponse>

Transfers amount raw tokens from from to to.

safeTransferFrom(from, to, amount)

async safeTransferFrom(from: Address, to: Address, amount: bigint, data?: Uint8Array): Promise<void>

Transfers amount from from on behalf of the sender (requires allowance).

burn(from, amount)

async burn(from: Address, amount: bigint): Promise<CallResponse>

Burns amount raw tokens from from.

airdrop(map)

async airdrop(map: AddressMap<bigint>): Promise<CallResponse>

Batch mints to multiple addresses.

increaseAllowance(owner, spender, amount)

async increaseAllowance(owner: Address, spender: Address, amount: bigint): Promise<CallResponse>

Increases spender's allowance from owner by amount.

decreaseAllowance(owner, spender, amount)

async decreaseAllowance(owner: Address, spender: Address, amount: bigint): Promise<CallResponse>

Decreases spender's allowance from owner by amount.

increaseAllowanceBySignature(...)

async increaseAllowanceBySignature(
    owner: Address, spender: Address, amount: bigint,
    deadline: bigint, signature: Uint8Array
): Promise<CallResponse>

decreaseAllowanceBySignature(...)

async decreaseAllowanceBySignature(
    owner: Address, spender: Address, amount: bigint,
    deadline: bigint, signature: Uint8Array
): Promise<CallResponse>

Static Event Decoders

decodeTransferredEvent(data)

static decodeTransferredEvent(data: Buffer | Uint8Array): TransferredEvent
interface TransferredEvent {
    readonly operator: Address;
    readonly from: Address;
    readonly to: Address;
    readonly value: bigint;
}

decodeMintedEvent(data)

static decodeMintedEvent(data: Buffer | Uint8Array): MintedEvent
interface MintedEvent {
    readonly to: Address;
    readonly value: bigint;
}

decodeBurnedEvent(data)

static decodeBurnedEvent(data: Buffer | Uint8Array): BurnedEvent
interface BurnedEvent {
    readonly from: Address;
    readonly value: bigint;
}

decodeApprovedEvent(data)

static decodeApprovedEvent(data: Buffer | Uint8Array): ApprovedEvent
interface ApprovedEvent {
    readonly owner: Address;
    readonly spender: Address;
    readonly value: bigint;
}

<- Previous: Documentation Index | Next: OP721 ->