Skip to main content
@chipi-stack/core is in development (v0.1.0). APIs may change before stable release.

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 with symbol, decimals, and address
  • account (Account): A starknet.js Account instance

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 address
  • spender (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 approve
  • amount (Amount): Amount to approve

Returns

Call: A StarkNet Call object for use with TxBuilder or Account.execute()

Throws

  • If amount.decimals doesn’t match the token’s decimals
  • If amount.symbol doesn’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 address
  • amount (Amount): Amount to transfer

Returns

Call: A StarkNet Call object

Throws

  • If amount.decimals doesn’t match the token’s decimals
  • If amount.symbol doesn’t match the token’s symbol (when set)

Example

Full Flow: Check Balance, Approve, Transfer

  • Amount: The value type returned by balanceOf() and allowance()
  • TxBuilder: Execute Call objects in atomic batches
  • TokenRegistry: Look up TokenInfo for the Erc20 constructor