メインコンテンツまでスキップ

ERC20-Basic

Overview

It is a library that enables the issuance, operation, and data acquisition of tokens that support ERC20, which is the most widely distributed fungable token standard on Ethereum.

Install

npm install @gusdk/erc20-basic

Usage

import { ERC20Basic, ERC20Basic__factory} from "erc20-basic-sdk"
import {BigNumber, ethers, Wallet} from "ethers"

const provider = new ethers.providers.JsonRpcProvider({
url: 'https://sandbox1.japanopenchain.org:8545/'
})

// use the concrete contract factory if you need to operate on the bytecode (ie. deploy)
async function deployTestToken(ownerPK: string): Promise<ERC20Basic> {
const owner = new Wallet(ownerPK, provider);
return new ERC20Basic__factory(owner).deploy(
"TEST123",
"TEST123",
100,
18
);
}

// to call existing contracts, a factory for both the concrete contract and for the interface
// can be used since the ABI is the same
async function getTokenBalance(walletAddress: string, tokenAddress: string): Promise<BigNumber> {
const token = ERC20Basic__factory.connect(tokenAddress, provider);
return token.balanceOf(walletAddress);
}

Functionality

name

name(): Promise<string>;

Returns the name of the token

symbol

symbol(): Promise<string>;

Returns the symbol of the token

totalSupply

totalSupply(): Promise<BigNumber>;

Returns the total token supply

balanceOf

balanceOf(account: PromiseOrValue<string>): Promise<BigNumber>;

Returns the account balance of another account with address account

decimals

decimals(): Promise<number>;

Returns the token decimals

allowance

allowance(owner: PromiseOrValue<string>, spender: PromiseOrValue<string>): Promise<BigNumber>;

Returns the amount which spender is still allowed to withdraw from owner

approve

approve(spender: PromiseOrValue<string>, amount: PromiseOrValue<BigNumberish>): Promise<ContractTransaction>;

Allows spender to withdraw from your account multiple times, up to the value amount. If this function is called again it overwrites the current allowance with value.

decreaseAllowance

decreaseAllowance(spender: PromiseOrValue<string>, subtractedValue: PromiseOrValue<BigNumberish>): Promise<ContractTransaction>;

decrease number token spender able to transfer

increaseAllowance

decreaseAllowance(spender: PromiseOrValue<string>, subtractedValue: PromiseOrValue<BigNumberish>): Promise<ContractTransaction>;

increase number token spender able to transfer

transfer

transfer(to: PromiseOrValue<string>, amount: PromiseOrValue<BigNumberish>): Promise<ContractTransaction>;

Transfers value amount of tokens to address to

transferFrom

transfer(to: PromiseOrValue<string>, amount: PromiseOrValue<BigNumberish>): Promise<ContractTransaction>;

Transfers value amount of tokens from address from to address to

Events

Approval

Approval(owner?: PromiseOrValue<string> | null, spender?: PromiseOrValue<string> | null, value?: null): ApprovalEventFilter

When approval function call the approval event will fire

Transfer

Transfer(from?: PromiseOrValue<string> | null, to?: PromiseOrValue<string> | null, value?: null): TransferEventFilter;

When transfer function call the approval event will fire