Toucan
Search
⌃K

Contract Interactions

Contract interactions

Toucan SDK provides you with several useful tools to quickly redeem and retire tokens. In case you can't find the function that you need with the Toucan SDK, you can also directly interact with the contracts.

retire

The retire function retires/burns an amount of TCO2s (each represents 1 ton of CO2) to achieve offset. It returns the retirement transaction.
function retire(
amount: BigNumber,
tco2Address: string
): Promise<ContractReceipt>;
Params
Name
Type
Description
amount
BigNumber
amount of TCO2 to retire
tco2Address
string
address of the TCO2 token to retire

retireFrom

The retireFrom function retires/burns an amount of TCO2s from a different address/wallet. The function requires approval from the address you're trying to retire from. It returns the retirement transaction.
function retireFrom(
amount: BigNumber,
address: string,
tco2Address: string
): Promise<ContractReceipt>;
Params
Name
Type
Description
amount
BigNumber
amount of TCO2 to retire
address
string
address of the account to retire from
tco2Address
string
address of the TCO2 token to retire

retireAndMintCertificate

The retireAndMintCertificate function retires/burns an amount of TCO2s & mints the NFT certificate for it within the same transaction. It returns the retirement transaction.
function retireAndMintCertificate(
retirementEntityName: string,
beneficiaryAddress: string,
beneficiaryName: string,
retirementMessage: string,
amount: BigNumber,
tco2Address: string
): Promise<ContractReceipt>;
Params
Name
Type
Description
retirementEntityName
string
name of the entity that does the retirement (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 to retire
tco2Address
string
address of the TCO2 token to retire

getDepositCap

The getDepositCap function gets the cap for TCO2s based on totalVintageQuantity.
function getDepositCap(tco2Address: string): Promise<BigNumber>;
Params
Name
Type
Description
tco2Address
string
address of the TCO2 token

getAttributes

The getAttributes function retrieves the attributes of the TCO2 token. It returns an array of attributes including vintage and project details.
function getAttributes(tco2Address: string): Promise<Attributes>;
Params
Name
Type
Description
tco2Address
string
address of the TCO2 token

getTCO2Remaining

The getTCO2Remaining function gets the remaining space in TCO2 contract before hitting the cap. It returns a BigNumber representing the remaining space.
function getTCO2Remaining(tco2Address: string): Promise<BigNumber>;
Params
Name
Type
Description
tco2Address
string
address of the TCO2 token

depositTCO2

The depositTCO2 function deposits TCO2 tokens from a user's address into a Toucan pool and mints a pool token for the user. It returns returns the deposit transaction.
function depositTCO2(
pool: PoolSymbol,
amount: BigNumber,
tco2Address: string
): Promise<ContractReceipt>;
Params
Name
Type
Description
pool
PoolSymbol
symbol of the pool (token) to use, e.g. "NCT"
amount
BigNumber
amount of TCO2s to deposit
tco2Address
string
address of the TCO2 token

checkEligible

The checkEligible function checks if a TCO2 is eligible for pool. It returns a boolean.
function checkEligible(pool: PoolSymbol, tco2Address: string): Promise<boolean>;
Params
Name
Type
Description
pool
PoolSymbol
symbol of the pool (token) to use, e.g. "NCT"
tco2Address
string
address of the TCO2 token

redeemAuto2

The redeemAuto2 function automatically redeems TCO2 tokens from the pool up to the deposit cap. It returns the redemption transaction. It returns an array containing tco2 addresses (string) and amounts (BigNumber).
function redeemAuto2(
pool: PoolSymbol,
amount: BigNumber
): Promise<ContractReceipt>;
Params
Name
Type
Description
pool
PoolSymbol
symbol of the pool (token) to use, e.g. "NCT"
amount
BigNumber
amount of pool tokens to redeem

redeemAuto

The redeemAuto function automatically redeems TCO2 tokens from the pool up to the deposit cap. It returns the redemption transaction.
function redeemAuto(
pool: PoolSymbol,
amount: BigNumber
): Promise<ContractReceipt>;
Params
Name
Type
Description
pool
PoolSymbol
symbol of the pool (token) to use, e.g. "NCT"
amount
BigNumber
amount of pool tokens to redeem

redeemMany

The redeemMany function selectively redeems pool tokens for TCO2s in a single transaction. It returns the redeem transaction.
function redeemMany(
pool: PoolSymbol,
tco2Addresses: string[],
amounts: BigNumber[]
): Promise<ContractReceipt>;
Params
Name
Type
Description
pool
PoolSymbol
symbol of the pool (token) to use, e.g. "NCT"
tco2Addresses
string[]
array of TCO2 contract addresses
amounts
BigNumber[]
array of amounts of TCO2 tokens to redeem for each tco2s

calculateRedeemFees

The calculateRedeemFees function calculates the fees to selectively redeem pool tokens for TCO2s. It returns amount (BigNumber) of fees it will cost to redeem.
function calculateRedeemFees(
pool: PoolSymbol,
tco2Addresses: string[],
amounts: BigNumber[]
): Promise<FeeCalculationResult>;
Params
Name
Type
Description
pool
PoolSymbol
symbol of the pool (token) to use, e.g. "NCT"
tco2Addresses
string[]
array of TCO2 contract addresses
amounts
BigNumber[]
array of amounts of TCO2 tokens to redeem

getPoolRemaining

The getPoolRemaining function gets the remaining space in pool contract before hitting the cap. It returns BigNumber representing the remaining space.
function getPoolRemaining(pool: PoolSymbol): Promise<BigNumber>;
Params
Name
Type
Description
pool
PoolSymbol
symbol of the pool (token) to use, e.g. "NCT"

getScoredTCO2s

The getScoredTCO2s function ets an array of scored TCO2s; scoredTCO2s[0] is lowest ranked. It returns an array of TCO2 addresses by rank.
function getScoredTCO2s(pool: PoolSymbol): Promise<string[]>;
Params
Name
Type
Description
pool
PoolSymbol
symbol of the pool (token) to use, e.g. "NCT"

checkIfTCO2

The checkIfTCO2 function checks if an address represents a TCO2. It returns a boolean.
function checkIfTCO2(address: string): Promise<boolean>;
Params
Name
Type
Description
address
string
address of the token to check

Interact directly with Toucan's contracts

If you need to interact with a method of our contracts that hasn't been implemented in the SDK yet, you can also get the contract and call the specific function.
It's important to note that, if you want to use write methods you need to have a signer set!

getPoolAddress

The getPoolAddress function returns the address of a Toucan pool.
function getPoolAddress(pool: PoolSymbol): string;
Params
Name
Type
Description
pool
PoolSymbol
symbol of the pool (token) to use, e.g. "NCT"

getPoolContract

The getPoolContract function retrieves an ethers.Contract based on the symbol, to interact with the pool token.
function getPoolContract(pool: PoolSymbol): IToucanPoolToken;
Params
Name
Type
Description
pool
PoolSymbol
symbol of the pool (token) to use, e.g. "NCT"

getTCO2Contract

The getTCO2Contract function retrieves an ethers.Contract based on the address, to interact with the the Toucan TCO2.
function getTCO2Contract(tco2Address: string): IToucanCarbonOffsets;
Params
Name
Type
Description
tco2Address
string
address of TCO2 ethers.Contract to instantiate

getRegistryContract

The getRegistryContract function retrieves an ethers.Contract to interact with the contract registry.
function getRegistryContract(): IToucanContractRegistry;

Example

You can always access any method or property of the BCT, NCT and TCO2 contracts by first getting and storing them in a variable, like so:
toucan.setSigner(signer);
const nct = await toucan.getPoolContract("NCT");
const tco2 = await toucan.getTCO2Contract(tco2Address);
const registry = await toucan.getRegistryContract();
const remainingTCO2 = await nct.tokenBalances(tco2Address);