Comment on page
Quickstart
Quickstart a project with carbon retirements with these few lines of code.
Instantiate the ToucanClient and set a
signer
& provider
to interact with our infrastructure.We recommend using to use ethers.js ^5.6.4 for the signer and provider. When you are considering using wagmi, only versions under 1.0 will work as this library has not yet been upgraded to viem.
import ToucanClient from "toucan-sdk";
import { ethers } from "ethers";
// ethers signer and provider
const provider = new ethers.providers.JsonRpcProvider(
"https://rpc.ankr.com/polygon"
);
// make sure to set your private key in your .env file
const signer = new ethers.Wallet(process.env.PRIVATE_KEY, provider);
// set signer & provider
const toucan = new ToucanClient("alfajores", provider, signer);
import ToucanClient from "toucan-sdk";
import { useProvider, useSigner } from "wagmi";
// get signer & provider
const { data: signer } = useSigner();
const provider = useProvider();
// set signer & provider
const toucan = new ToucanClient("alfajores", provider, signer);
You could also set the signer/provider later if you prefer that. They are optional. But you will need to set them if you want to interact with contracts. The provider is read-only, while the signer allows both writing to and reading from the blockchain.
import ToucanClient from "toucan-sdk";
const toucan = new ToucanClient("alfajores");
toucan.setProvider(provider);
toucan.setSigner(signer);
If you don't have a signer nor a provider set, you can only interact with the subgraph.
To retire Carbon Credits on mainnet, you will have to get Carbon Pool Tokens from a DEX like Uniswap. You'll then need to redeem the pool tokens for TCO2s. You can then retire these TCO2s and get a retirement certificate NFT for that.
If you already own NCTs, you can follow this example. Get your test tokens at the Toucan Faucet. You can find more ways to retire in this list of all SDK functions.
Redeem your Pool Tokens and get an array of redeemed TCO2s
const tco2addresses = await toucan.redeemAuto("NCT", parseEther("1"));
Retire the Carbon Credits
await toucan.retire(parseEther("1"), tco2addresses[0].address);
The functions in the OffsetHelper will abstract the following steps:
Using these functions, you can easily offset. Bear in mind that using these functions will not let you choose a specific project to retire. Specifying your the project you want to retire, requires you to use the
redeemMany
function.const cUSD = "0x765DE816845861e75A25fCA122bb6898B8B1282a";
const tx = await toucan.autoOffsetExactInToken(cUSD, "NCT", parseEther("0.01"));
Last modified 1mo ago