Celo's ContractKit is a library to help developers and validators to interact with the celo-blockchain.
ContractKit supports the following functionality:
- Connect to a node
- Access web3 object to interact with node's Json RPC API
- Send Transaction with celo's extra fields: (feeCurrency)
- Simple interface to interact with CELO and cUSD
- Simple interface to interact with Celo Core contracts
npm install @celo/contractkit@baklava// oryarn add @celo/contractkit@baklava
You will need node version
8.13.0 or higher.
To start working with contractkit you need a
To access web3:
Setting Default Tx Options
kit allows you to set default transaction options:
Interacting with CELO & cUSD
celo-blockchain has two initial coins: CELO and cUSD (stableToken). Both implement the ERC20 standard, and to interact with them is as simple as:
To send funds:
To interact with cUSD, is the same but with a different contract:
If you would like to pay fees in cUSD, set the gas price manually:
contractKit.setFeeCurrencyCeloContract.StableToken // Default to paying fees in cUSD.transferrecipient, weiTransferAmount.send
Interacting with Other Contracts
Apart from GoldToken and StableToken, there are many core contracts.
For the moment, we have contract wrappers for:
- Exchange (Uniswap kind exchange between Gold and Stable tokens)
In the following weeks will add wrapper for all other contracts
Accessing web3 contract wrappers
Some user might want to access web3 native contract wrappers.
To do so, you can:
We expose native wrappers for all Celo core contracts.
The complete list of Celo Core contracts is:
A Note About Contract Addresses
Celo Core Contracts addresses, can be obtained by looking at the
That's actually how
kit obtain them.
We expose the registry api, which can be accessed by:
Sending Custom Transactions
Celo transaction object is not the same as Ethereum's. There are three new fields present:
- feeCurrency (address of the ERC20 contract to use to pay for gas and the gateway fee)
- gatewayFeeRecipient (coinbase address of the full serving the light client's trasactions)
- gatewayFee (value paid to the gateway fee recipient, denominated in the fee currency)
This means that using
myContract.methods.transfer().send() should be avoided.
kit provides an utility method to send transaction in both scenarios. If you use contract wrappers, there is no need to use this.
For a raw transaction:
When interacting with a web3 contract object:
If you need to debug
kit, we use the well known debug node library.
So set the environment variable