Toucan Documentation
  • 🌱Introduction
    • Welcome to Toucan
    • Legal Disclaimer
  • 🌏Toucan
    • Bridging
      • Puro Carbon Bridge
        • Tokenization
        • Detokenization
    • Carbon Pools
      • How a Carbon Pool Works
      • Benefits of Pools
      • CHAR Carbon Pool
      • How to Buy CHAR
      • Deposits and Redemptions
    • Carbon Retirements
  • 🌿RESOURCES
    • Web3 concepts
    • Carbon markets
      • Carbon credits
    • Frequently asked questions
      • How do I use the Carbon Bridge?
      • How can one carbon pool token, like CHAR, represent one tonne of carbon?
      • Can I retire carbon pool tokens, like CHAR, to offset my emissions?
      • Where can I find the addresses of CHAR or other contracts?
      • How long does it take to bridge carbon credits?
      • What happens to a pool token if it is bridged to another network?
      • FAQ for transition to Open Source
    • Archives
      • Verra Bridge [Deprecated]
      • Pool Acceptance Criteria: NCT, BCT
      • NCT Pool Report
    • Audits
  • 💻Developers
    • Toucan for developers
    • Smart contracts
      • Carbon pool contracts
      • TCO2 contracts
      • Retirement certificates
      • OffsetHelper
    • Subgraphs
    • Toucan SDK
      • Quickstart
      • Contract interactions
      • Subgraph interactions
    • Tools + examples
      • Integration examples
      • Testnet faucets
      • Dune dashboard
    • Developer support
      • Error codes
Powered by GitBook
On this page
  • Setting up the client
  • Retire Carbon Credits
  • Offset Carbon Credits with the OffsetHelper

Was this helpful?

  1. Developers
  2. Toucan SDK

Quickstart

Quickstart a project with carbon retirements with a few lines of code

PreviousToucan SDKNextContract interactions

Last updated 10 months ago

Was this helpful?

Setting up the client

Instantiate the ToucanClient and set a signer & provider to interact with our smart contracts.

We recommend using to use for the signer and provider.

Read the

Network
JsonRpcProvider

Celo Mainnet

https://forno.celo.org

Celo Alfajores Testnet

https://alfajores-forno.celo-testnet.org

Polygon Mainnet

https://polygon-rpc.com

import ToucanModule from "toucan-sdk";
import { ethers } from "ethers";

const ToucanClient = ToucanModule.default;

// 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("polygon", provider, signer);

Note that when you are considering using , only versions under 1.0 will work as this library has not yet been upgraded to .

Read the

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 and / or 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("polygon");
toucan.setProvider(provider);
toucan.setSigner(signer);

If you don't have a signer or a provider set, you can still interact with the subgraph.

Retire Carbon Credits

Redeem your Pool Tokens and get an array of redeemed TCO2s

const tco2addresses = await toucan.redeemAuto("NCT", parseEther("1"));

Retire the TCO2 tokens

await toucan.retire(parseEther("1"), tco2addresses[0].address);

Offset Carbon Credits with the OffsetHelper

The functions in the OffsetHelper will bundle the following steps into a single transaction:

  • Interact with the pool contract to redeem the tokens for TCO2

  • Interact with the TCO2 token contract to retire the TCO2 the amount purchased and redeemed

Note that if you're using the swap functionality, the exact number of TCO2 tokens retired will depend on the stablecoin : reference token exchange rate, which can vary moment to moment.

const cUSD = "0x765DE816845861e75A25fCA122bb6898B8B1282a";
const tx = await toucan.autoOffsetExactInToken(cUSD, "NCT", parseEther("0.01"));

To retire carbon credits on mainnet, you will need to have TCO2 tokens in your account. These can be acquired by buying carbon reference tokens from a DEX like , then the reference tokens for TCO2s. You can then retire these TCO2 tokens through the Toucan app UI, or programmatically with the ToucanClient.retire() method.

If you already own NCT tokens, you can follow this example. Get your test tokens at the . You can find more ways to retire, and mint RetirementCertificates, in list of all SDK functions.

Exchange ERC20 tokens e.g., cUSD or USDC for pool tokens (e.g., NCT) at a DEX like or , etc. (depending on the network)

Using these functions, you can easily offset TCO2 tokens using other cryptocurrencies and stablecoins. Bear in mind that using these functions will not let you choose a specific project to retire. To specify your the project you want to retire, you'd need to use the function, which is not supported by the OffsetHelper at this point.

💻
ethers.js ^5.6.4
ethers.js Signer docs ->
wagmi
viem
wagmi useSigner docs ->
Toucan Faucet
this
Uniswap
SushiSwap
Uniswap
redeeming
redeemMany