Security News
ESLint is Now Language-Agnostic: Linting JSON, Markdown, and Beyond
ESLint has added JSON and Markdown linting support with new officially-supported plugins, expanding its versatility beyond JavaScript.
@celo/contractkit
Advanced tools
Celo's ContractKit is a library to help developers and validators to interact with the celo-blockchain.
ContractKit supports the following functionality:
To install:
npm install @celo/contractkit@baklava
// or
yarn add @celo/contractkit@baklava
You will need node version 8.13.0
or higher.
To start working with contractkit you need a kit
instance:
import { newKit } from '@celo/contractkit'
const kit = newKit('https://alfajores-forno.celo-testnet.org:8545')
To access web3:
await kit.web3.eth.getBalance(someAddress)
kit
allows you to set default transaction options:
import { newKit, CeloContract } from '@celo/contractkit'
async function getKit(myAddress: string) {
const kit = newKit('https://alfajores-forno.celo-testnet.org:8545')
// default from
kit.defaultAccount = myAddress
// paid gas in celo dollars
await kit.setFeeCurrency(CeloContract.StableToken)
return kit
}
celo-blockchain has two initial coins: cGold and cDollar (stableToken). Both implement the ERC20 standard, and to interact with them is as simple as:
const goldtoken = await kit.contracts.getGoldToken()
const balance = await goldtoken.balanceOf(someAddress)
To send funds:
const oneGold = kit.web3.utils.toWei('1', 'ether')
const tx = await goldtoken.transfer(someAddress, oneGold).send({
from: myAddress,
})
const hash = await tx.getHash()
const receipt = await tx.waitReceipt()
To interact with cDollar, is the same but with a different contract:
const stabletoken = await kit.contracts.getStableToken()
Apart from GoldToken and StableToken, there are many core contracts.
For the moment, we have contract wrappers for:
In the following weeks will add wrapper for all other contracts
Some user might want to access web3 native contract wrappers.
To do so, you can:
const web3Exchange = await kit._web3Contracts.getExchange()
We expose native wrappers for all Celo core contracts.
The complete list of Celo Core contracts is:
Celo Core Contracts addresses, can be obtained by looking at the Registry
contract.
That's actually how kit
obtain them.
We expose the registry api, which can be accessed by:
const goldTokenAddress = await kit.registry.addressFor(CeloContract.GoldToken)
Celo transaction object is not the same as Ethereum's. There are three new fields present:
This means that using web3.eth.sendTransaction
or myContract.methods.transfer().send()
should be avoided.
Instead, 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:
const tx = kit.sendTransaction({
from: myAddress,
to: someAddress,
value: oneGold,
})
const hash = await tx.getHash()
const receipt = await tx.waitReceipt()
When interacting with a web3 contract object:
const goldtoken = await kit._web3Contracts.getGoldToken()
const oneGold = kit.web3.utils.toWei('1', 'ether')
const txo = await goldtoken.methods.transfer(someAddress, oneGold)
const tx = await kit.sendTransactionObject(txo, { from: myAddress })
const hash = await tx.getHash()
const receipt = await tx.waitReceipt()
If you need to debug kit
, we use the well known debug node library.
So set the environment variable DEBUG
as:
DEBUG="kit:*,
FAQs
Celo's ContractKit to interact with Celo network
The npm package @celo/contractkit receives a total of 17,850 weekly downloads. As such, @celo/contractkit popularity was classified as popular.
We found that @celo/contractkit demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 8 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
ESLint has added JSON and Markdown linting support with new officially-supported plugins, expanding its versatility beyond JavaScript.
Security News
Members Hub is conducting large-scale campaigns to artificially boost Discord server metrics, undermining community trust and platform integrity.
Security News
NIST has failed to meet its self-imposed deadline of clearing the NVD's backlog by the end of the fiscal year. Meanwhile, CVE's awaiting analysis have increased by 33% since June.