Contract interactions
Interact with Toucan smart contracts using our JavaScript SDK
Last updated
Was this helpful?
Interact with Toucan smart contracts using our JavaScript SDK
Last updated
Was this helpful?
The Toucan SDK provides you with several useful tools to quickly redeem and retire carbon credits programmatically. In case you can't find the function that you need with the Toucan SDK, you can also directly interact with the .
The OffsetHelper combines these steps in each of the following "auto offset" methods to allow carbon credit retirement (offsetting) within one transaction:
Obtain a pool token such as NCT (by performing a token swap)
Redeem the pool token for a TCO2 token
Retire the TCO2 token
The autoOffsetPoolToken
retires carbon credits using the lowest quality (oldest) TCO2 tokens available from the specified carbon pool. This method does not include a token swap — the user must already hold reference tokens. All provided reference tokens are consumed for offsetting.
This method may take up to 1 minute to return a result. It returns the redeem transaction.
pool
PoolSymbol
symbol of the carbon reference token to offset with, e.g. NCT
amount
BigNumber
amount of TCO2 tokens to redeem and retire
The autoOffsetExactInToken
extends the functionality described in autoOffsetPoolToken
by including a step to swap another token, like USDC, WETH or WMATIC, for the carbon reference tokens.
After the swap is completed, subsequent steps are the same as above. This method may take up to 1 minute to return a result. It returns the redeem transaction.
swapToken
string
— WETH
, WMATIC
or USDC
The ticker for the token to swap into carbon reference tokens
pool
PoolSymbol
e.g. NCT
symbol of the carbon reference token to use
amount
BigNumber
the amount of ERC20 token to swap into carbon reference token. Full amount will be used for offsetting.
The autoOffsetExactOutToken
retires a specified amount of carbon credits using the lowest quality (oldest) TCO2 tokens available from the specified token pool by sending ERC20 tokens (cUSD, USDC, WETH, WMATIC). This method may take up to 1 minute to return a result. It returns the offset transaction.
swapToken
string
— WETH
, WMATIC
or USDC
The ticker for the token to swap into pool tokens (only accepts WETH, WMATIC and USDC)
pool
PoolSymbol
e.g. NCT
Symbol of the carbon reference token to use
amount
BigNumber
Amount of TCO2 tokens to retire
Same as autoOffsetExactInToken
, but the autoOffsetExactInETH
swaps the blockchain's native token for carbon reference tokens, instead of allowing you to specify the swapToken
.
This method may take up to 1 minute to return a result. It returns the offset transaction.
pool
PoolSymbol
e.g. NCT
Ticker symbol of the carbon reference token to acquire and redeem
amount
BigNumber
The amount of native tokens e.g., MATIC to swap into Toucan carbon reference tokens. The full amount of redeemed TCO2 tokens will be used for offsetting.
Same as autoOffsetExactOutToken
, but the autoOffsetExactOutETH
swaps the blockchain's native token for carbon reference tokens, instead of allowing you to specify the swapToken
.
This method may take up to 1 minute to return a result. It returns the offset transaction.
pool
PoolSymbol
e.g. NCT
Ticker symbol of the carbon reference token to acquire and redeem
amount
BigNumber
The amount of TCO2 tokens to retire
Calculates and returns the expected amount of carbon references tokens that can be acquired by swapping the provided amount of ERC20 token.
swapToken
string
— WETH
, WMATIC
or USDC
The ERC20 token used for the swap
pool
PoolSymbol
e.g. NCT
Symbol of the carbon reference token to swap for
amount
BigNumber
The amount of ERC20 token to swap
Calculates and returns the expected amount of carbon references tokens that can be acquired by swapping the provided amount of native token.
pool
PoolSymbol
e.g. NCT
Symbol of the carbon reference token to swap for
amount
BigNumber
Amount of native tokens to swap for, e.g., WMATIC
Calculates how much of the specified ERC20 token is required in order to swap for the desired amount of a specified carbon reference token.
swapToken
string
— WETH
, WMATIC
or USDC
The ERC20 token used for the swap
pool
PoolSymbol
e.g. NCT
Symbol of the pool token to swap for
amount
BigNumber
The desired amount of carbon reference token to receive
Calculates the amount of native tokens (e.g, MATIC) required to swap for the desired amount of a carbon reference token, e.g., NCT.
pool
PoolSymbol
e.g. NCT
Symbol of the pool token to swap for
amount
BigNumber
The desired amount of carbon reference tokens to receive
The retire
function retires an amount of TCO2 tokens and returns the retirement transaction.
amount
BigNumber
Amount of TCO2 tokens to retire
tco2Address
string
Address of the TCO2 token to retire
The retireFrom
function retires an amount of TCO2 tokens from a different address/wallet. The function requires approval from the address you're trying to retire from. If you don't own any TCO2s you need to buy pool tokens, e.g., NCTs on a DEX and redeem these first. It returns the retirement transaction.
amount
BigNumber
Amount of TCO2 tokens to retire
address
string
Address of the account to retire from
tco2Address
string
Contract address of the TCO2 token to retire
The retireAndMintCertificate
function retires an amount of TCO2s & mints the NFT RetirementCertificate
for it within the same transaction. If you don't own any TCO2s you need to buy pool tokens, e.g., NCTs on a DEX and redeem these first. It returns the retirement transaction.
retirementEntityName
string
Name of the entity that does the retirement (i.e. you)
beneficiaryAddress
string
Address of the beneficiary (in case you're retiring for someone else)
beneficiaryName
string
Name of the beneficiary
retirementMessage
string
Retirement message
amount
BigNumber
Amount of TCO2 tokens to retire
tco2Address
string
Contract address of the TCO2 token to retire
The getDepositCap
function gets the cap for TCO2s based on totalVintageQuantity
.
tco2Address
string
Contract address of the TCO2 token
The getAttributes
function retrieves the attributes of the TCO2 token. It returns an array of attributes including vintage and project details.
tco2Address
string
Contract address of the TCO2 token
The getTCO2Remaining
function gets the remaining space in TCO2 contract before hitting the deposit cap. It returns a BigNumber
representing the remaining space.
tco2Address
string
Contract address of the TCO2 token
The depositTCO2
function deposits TCO2 tokens from a user's account into a carbon pool and mints and deposits an equivalent number of the pool's reference tokens back into the user's account. It returns returns the deposit transaction.
pool
PoolSymbol
e.g. NCT
Symbol of the pool (token) to use
amount
BigNumber
Amount of TCO2 tokens to deposit
tco2Address
string
Contract address of the TCO2 token
The checkEligible
function checks if a TCO2 is eligible for pool. It returns a boolean.
pool
PoolSymbol
e.g. NCT
Symbol of the pool to check against
tco2Address
string
Contract address of the TCO2 token to check
The redeemAuto
function automatically redeems TCO2 tokens from the pool up to the deposit cap. It returns the redemption transaction, which returns an array containing TCO2 contract addresses (string
) and amounts (BigNumber
).
pool
PoolSymbol
e.g. NCT
Symbol of the pool redeem from
amount
BigNumber
Amount of carbon reference tokens to redeem
This function is deprecated. Use redeemAuto
instead.
pool
PoolSymbol
e.g. NCT
Symbol of the pool to redeem from
amount
BigNumber
Amount of carbon reference tokens to redeem
The redeemMany
function redeems carbon reference tokens for specified TCO2 tokens in specified amounts in a single transaction. It returns the redeem transaction.
pool
PoolSymbol
e.g. NCT
Symbol of the pool to redeem from
tco2Addresses
string[]
Array of TCO2 contract addresses
amounts
BigNumber[]
Array of amounts of TCO2 tokens to redeem for each
The tco2Addresses
and amounts
arrays must be of equal length, and align based on index, i.e. "Redeem amounts[4]
tokens from TCO2 contract address tco2Addresses[4]
."
pool
PoolSymbol
e.g. NCT
Symbol of the pool (token) to use
tco2Addresses
string[]
Array of TCO2 contract addresses
amounts
BigNumber[]
Array of amounts of TCO2 tokens to redeem
The getPoolRemaining
function gets the remaining space in pool contract before hitting the cap, i.e. supplyCap - totalSupply
. It returns BigNumber
representing the remaining space in the pool.
pool
PoolSymbol
e.g. NCT
Symbol of the pool (token) to check
The getScoredTCO2s
function gets an array of TCO2s ordered by score for a specific pool; scoredTCO2s[0]
is lowest ranked. It returns an array of TCO2 addresses by rank.
pool
PoolSymbol
e.g. NCT
Symbol of the pool (token) to use
The checkIfTCO2
function checks if an address represents a TCO2. It returns a boolean
.
address
string
Contract address of the token to check
The getPoolAddress
function returns the address of a Toucan pool.
pool
PoolSymbol
e.g. NCT
Symbol of the pool
The getPoolContract
function retrieves an ethers.Contract
object based on the pool symbol.
pool
PoolSymbol
e.g. NCT
Symbol of the pool (token) to use
The getTCO2Contract
function retrieves an ethers.Contract
object based on the TCO2 contract address.
tco2Address
string
Address of TCO2 contract to instantiate an ethers.Contract
object for
The getRegistryContract
function retrieves an ethers.Contract
to interact with the contract registry.
You can always access any method or property of pool and TCO2 contracts by first getting and storing them in a variable, like this:
Return values are described in the
The calculateRedeemFees
function calculates the fees to selectively redeem carbon reference tokens for TCO2s. It returns amount (BigNumber
) of fees it will cost to redeem. are levied in the pool's reference token.
If you need to interact with a method of our that hasn't been implemented in the SDK yet, you can also connect directly to the contract and call the specific function. Learn more about smart contract functions in , and the docs.