This repository was archived by the owner on Apr 18, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 18
Types: Token
Bleaker edited this page Feb 22, 2022
·
3 revisions
Token is a class which can represent any ERC20-compatible token on any given network, and is a data class.
The Synapse Protocol SDK provides pre-defined Token instances for all tokens supported by the Synapse Protocol on all supported networks
in the Tokens namespace, which is easily imported like so:
import {Tokens, ChainId} from "@synapseprotocol/sdk";
console.log(Tokens.USDC.address(ChainId.BSC));You should not expect to ever have to instantiate a Token manually, and using a manually instantiated Token with
various functions in the SDK will likely cause undefined behavior.
Unless otherwise specified, all instance variables are read only and set by the constructor.
-
name(string) - The "official" name of the token. Example: "USD Circle" (for USDC) -
symbol(string) - Symbol the token is known by both on and off-chain. Examples: "USDT" (Tether's USD stablecoin), "DOGE" (for Dogecoin) -
addresses({ [chainId: number] => string }) - This field is similarly shaped todecimals, in that it is a mapping with shapechain id => address for chain (string), containing the on-chain addresses of this token for respective Chain ID values.
-
address- Returns the on-chain address of this token respective to the passed Chain ID.
- Params:
-
chainId: number- Chain ID of the chain for which you want this token's on-chain address.
-
- Returns:
-
string- The on-chain address of this token respective to
network, ornullif the token is not supported by the Synapse Protocol on the given network.
- The on-chain address of this token respective to
-
-
decimals- Returns the on-chain decimals value of this token respective to the passed ChainID.
- Params:
-
chainId: number- Chain ID of the chain for which you want this token's on-chain decimals.
-
- Returns:
-
number- The on-chain decimals value of this token respective to
network, ornullif the token is not supported by the Synapse Protocol on the given network.
- The on-chain decimals value of this token respective to
-
-
valueToWei- Given an amount of a token in Ether, returns that value represented in units of Wei using the correct decimal precision for the passed Chain Id.
- Params:
-
ether: BigNumberish- Some amount of a given token in units of Ether
-
chainId: number- Chain ID is required to ensure proper arithmatic. This is especially important when retrieving the Wei representation of an Ether amount for a token which has different decimal values on different chains, such as USDC and USDT.
-
- Returns:
-
BigNumber- Wei units representation of the passed amount based on its on-chain
decimalsvalue for the passedchainId.
- Wei units representation of the passed amount based on its on-chain
-