Documentation Index
Fetch the complete documentation index at: https://docs.chipipay.com/llms.txt
Use this file to discover all available pages before exploring further.
Overview
Erc20 provides a typed wrapper around ERC20 contract interactions on StarkNet. Read methods (balanceOf, allowance) return Amount objects. Write methods (approveCall, transferCall) return Call objects for use with TxBuilder or Account.execute().
Usage
Constructor
Parameters
token(TokenInfo): Object withsymbol,decimals, andaddressaccount(Account): A starknet.jsAccountinstance
Methods
balanceOf(address)
Query the ERC20 balance of an address.
Parameters
address(string): StarkNet address to query
Returns
Promise<Amount>: The balance as an Amount object
allowance(owner, spender)
Query the allowance granted by owner to spender.
Parameters
owner(string): Token owner addressspender(string): Approved spender address
Returns
Promise<Amount>: The allowance as an Amount object
approveCall(spender, amount)
Build an ERC20 approve Call object. Does not execute the transaction.
Parameters
spender(string): Address to approveamount(Amount): Amount to approve
Returns
Call: A StarkNet Call object for use with TxBuilder or Account.execute()
Throws
- If
amount.decimalsdoesn’t match the token’s decimals - If
amount.symboldoesn’t match the token’s symbol (when set)
transferCall(recipient, amount)
Build an ERC20 transfer Call object. Does not execute the transaction.
Parameters
recipient(string): Destination addressamount(Amount): Amount to transfer
Returns
Call: A StarkNet Call object
Throws
- If
amount.decimalsdoesn’t match the token’s decimals - If
amount.symboldoesn’t match the token’s symbol (when set)
Example
Full Flow: Check Balance, Approve, Transfer
Related
- Amount: The value type returned by
balanceOf()andallowance() - TxBuilder: Execute Call objects in atomic batches
- TokenRegistry: Look up TokenInfo for the Erc20 constructor
