Skip to main content

EvmERC20RouterSDK

The EvmERC20RouterSDK class is an extension of the SDK designed to interact with ERC20 routers in the Ethereum environment. This class facilitates the management and operation of ERC20 tokens, including functionalities for approving tokens, querying balances, and handling cross-chain transactions.

This module will be registered by default when using the TeleportFactory, so you can access its methods through the dapp function.

We recommend using typescript, so that you can specify the expected module type, in order to access all module-specific methods and properties.

import { ERC20RouterSDK } from "@stichting-allianceblock-foundation/abridge-sdk";

const erc20Module = await sdk.dapp<ERC20RouterSDK>(ERC20RouterSDK.DAPP_NAME);

Now that you have an instance of your module, you can use all of its methods and properties. Remember that each module can have different methods and properties, as defined by the developer.

Methods

allowance

async allowance(tokenAddress: string, userAddress: string): Promise<AllowanceWithDecimals>

Returns the allowance of a user for a specific token.

approve

approve(tokenAddress: string, amount: BigNumberish): PayableCall

Approves a specific amount of tokens for the router to spend on behalf of the user.

approveMaxInt

approveMaxInt(tokenAddress): PayableCall

Approves the maximum amount of tokens, based on the balance of the user, for the router to spend on behalf of the user.

balanceOf

async balanceOf(tokenAddress: string,userAddress: string): Promise<{ balance: BigNumber; tokenDecimals: number }>

Returns the balance of a user for a specific token.

balanceOfMulticall

async balanceOfMulticall(tokenAddresses: string[], userAddress: string)

Returns the balance of a user for multiple tokens.

getErc20Claims

async getErc20Claims(targetChainId: number, userAddress: string)

Returns the list of ERC20 claims for a specific user on a specific chain with the metadata of the tokens.

For this purpose, first use the getErc20Claims method of EvmERC20RouterSDK and then add the metadata of each token using the getWrappedTokenDetails function.

getFeeAmountByToken

async getFeeAmountByToken(tokenAddress: string): Promise<BigNumber>

Returns the fee amount required for transactions involving a specific ERC20 token.

getFeeTokens

async getFeeTokens(): Promise<string[]>

Retrieves a list of tokens that can be used to pay transaction fees on the platform.

getNativeTokenByWrappedAddress

async getNativeTokenByWrappedAddress(wrappedTokenAddress: string): Promise<NativeTokenInfo>

Fetches native token information based on the address of its wrapped version on another blockchain.

getProviderFee

async getProviderFee({ targetChainId, tokenAddress, amount, receiverAddress, deliveryFeeEstimate, deliveryFeeExpiry, deliveryFeeSignature, extraArgs, providerAddress }: SendErc20Options): Promise<BigNumber>

Calculates the provider fee for sending ERC20 tokens across chains based on various transaction details and optional parameters.

getServiceFee

async getServiceFee({ targetChainId, tokenAddress, amount, receiverAddress, deliveryFeeEstimate, deliveryFeeExpiry, deliveryFeeSignature, extraArgs, providerAddress }: SendErc20Options): Promise<BigNumber>

Determines the service fee for executing a transaction involving ERC20 tokens on a specific chain.

getTokenDecimals

async getTokenDecimals(tokenAddress: string): Promise<number>

Returns the number of decimals used by a specific ERC20 token.

getTokenDetails

async getTokenDetails(tokenAddress: string): Promise<ERC20TokenMetadata>

Retrieves detailed metadata about an ERC20 token including its name, symbol, and decimal places.

getTokenDetailsMulticall

async getTokenDetailsMulticall(tokenAddresses: string[], userAddress?: string): Promise<ERC20TokenMetadataWithBalance[]>

Fetches detailed metadata and balances for multiple ERC20 tokens for a specified user, utilizing multicall to optimize the number of transactions.

getTokenName

async getTokenName(tokenAddress): Promise<string>

Retrieves the name of an ERC20 token based on its contract address.

getTokenSymbol

async getTokenSymbol(tokenAddress): Promise<string>

Fetches the symbol of an ERC20 token, providing a shorthand representation commonly used in exchanges and wallets.

getWrappedForNativeToken

async getWrappedForNativeToken(nativeChainId: number, nativeToken: string): Promise<string>

Finds the wrapped token address for a native token on a different blockchain, facilitating cross-chain interactions.

getWrappedTokenDetails

async getWrappedTokenDetails(nativeTokenAddress, nativeChainId): Promise<ERC20TokenMetadata | undefined>

Retrieves details of a wrapped token, including its metadata, or returns undefined if the token is not yet wrapped on the target chain.

isTokenApproved

async isTokenApproved(tokenAddress: string, userAddress: string, threshold?: BigNumberish): Promise<boolean>

Checks whether the ERC20 token is approved by the user to be spent above a specified threshold.

getTargetERC20RouterContract

async getTargetERC20RouterContract(targetChainId: number, defaultRpc?: boolean)

Fetches the ERC20 router contract on a target blockchain, optionally using a default RPC setting if provided.

getERC20RouterDeliveryGas

async getERC20RouterDeliveryGas(sourceChainId: number, targetChainId: number, token: string): Promise<number>

Estimates the gas required for delivering an ERC20 token via the router between specified source and target chains.

estimateDeliveryGas

async estimateDeliveryGas(sourceChainId: number, targetChainId: number, token: string)

Calculates the total delivery gas costs by summing up provider, teleport, and router gas estimates for a given token transaction between chains.

calculateExtraArg

async calculateExtraArg({ targetChainId, tokenAddress })

Calculates additional arguments needed for transactions, particularly useful for adjusting gas limits based on estimated delivery costs.

sendErc20

sendErc20({ targetChainId, tokenAddress, amount, receiverAddress, feeTokenAddress, deliveryFeeEstimate, deliveryFeeExpiry, deliveryFeeSignature, v, r, s, deadline, extraArgs, providerAddress}: SendErc20Options): PayableCall

Executes a transaction to send ERC20 tokens across chains, handling various transaction types including those that require permits and additional fee handling, configurable by extensive options.