Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

@celo/contractkit

celo-org247.3kApache-2.010.0.1TypeScript support: included

Celo's ContractKit to interact with Celo network

celo, blockchain, contractkit

readme

ContractKit

Celo's ContractKit is a library to help developers and validators to interact with the Celo blockchain.

ContractKit supports the following functionality:

  • Interact with json RPC API
  • Send Transaction with celo's extra fields: (feeCurrency)
  • Build apps to interact with governance and staking

User Guide

[!TIP] You might not need the ContractKit. For new projects we recommened viem or web3 optionally with our celo plugin.

Getting Started

To install you will need Node.js v18.14.2. or greater. v20 reccomended.

npm install @celo/contractkit
// or
yarn add @celo/contractkit

Examples

To start working with contractkit you need a kit instance:

import { newKit } from '@celo/contractkit' // or import { newKit } from '@celo/contractkit/lib/mini-kit'

const kit = newKit("https://alfajores-forno.celo-testnet.org")

List Registered ValidatorGroups


const validatorsContractWrapper = await kit.contracts.getValidators()
const validatorGroups = await validatorsContractWrapper.getRegisteredValidatorGroups()

Show locked Celo balance for account

const lockedGoldContractWrapper = await kit.contracts.getLockedGold()

const accountAddress = kit.defaultAccount 
const summary = lockedGoldContractWrapper.getAccountSummary(accountAddress!)

More Information

You can find more information about the ContractKit in the Celo docs at https://docs.celo.org/developer-guide/contractkit.

How we work

We are a GitHub-first team, which means we have a strong preference for communicating via GitHub. Please use GitHub to:

🐞 File a bug report

💬 Ask a question

Suggest a feature

🧑‍💻 Contribute!

🚔 Report a security vulnerability

[!TIP]

Please avoid messaging us via Slack, Telegram, or email. We are more likely to respond to you on GitHub than if you message us anywhere else. We actively monitor GitHub, and will get back to you shortly 🌟

Debugging

If you need to debug kit, we use the well known debug node library.

So set the environment variable DEBUG as:

DEBUG="kit:*,

changelog

@celo/contractkit

10.0.1

Patch Changes

10.0.1-beta.1

Patch Changes

10.0.1-cc13.0

Patch Changes

10.0.0

Major Changes

  • #600 66c8ad4 Thanks @aaronmgdr! - Remove old L1 contract wrappers, GasPriceMinimum, FeeCurrencyWhitelist, DowntimeSlasher, DoubleSigningSlasherBlockchainParameters, BaseSlasher, Random,

Patch Changes

10.0.0-beta.2

Patch Changes

10.0.0-beta.1

Patch Changes

10.0.0-beta.0

Major Changes

  • #600 66c8ad4 Thanks @aaronmgdr! - Remove old L1 contract wrappers, GasPriceMinimum, FeeCurrencyWhitelist, DowntimeSlasher, DoubleSigningSlasherBlockchainParameters, BaseSlasher, Random,

Patch Changes

9.2.1

Patch Changes

9.2.0

Minor Changes

9.1.1

Patch Changes

9.1.0

Minor Changes

  • #535 c184fb1 Thanks @aaronmgdr! - Add CeloToken and LockedCelo aliases for deprecated GoldToken and LockedCelo Contracts enum

  • #533 549450f Thanks @soloseng! - added support for epochManager processGroups function to contractkit && celocli

Patch Changes

9.1.0-beta.1

Minor Changes

  • #533 549450f Thanks @soloseng! - added support for epochManager processGroups function to contractkit && celocli

Patch Changes

9.1.0-beta.0

Minor Changes

  • #535 c184fb1 Thanks @aaronmgdr! - Add CeloToken and LockedCelo aliases for deprecated GoldToken and LockedCelo Contracts enum

Patch Changes

9.0.1

Patch Changes

9.0.1-beta.2

Patch Changes

9.0.1-beta.1

Patch Changes

9.0.1-beta.0

Patch Changes

9.0.0

Major Changes

  • #340 33ad4aa Thanks @aaronmgdr! - Removes all exports under the lib/identity folder. These have been move to a new @celo/metadata-claims package and should be imported from there.

    Note that folder structure is also flattened slightly. so replace @celo/contractkit/lib/identity/claims/ with @celo/metadata-claims/lib/

    example

    - import { createAccountClaim } from '@celo/contractkit/lib/identity/claims/account'
    + import { createAccountClaim } from '@celo/metadata-claims/lib/account'
    - import { ContractKit, IdentityMetadataWrapper, newKitFromWeb3 } from '@celo/contractkit'
    - import { ClaimTypes } from '@celo/contractkit/lib/identity'
    + import { ContractKit, newKitFromWeb3 } from '@celo/contractkit'
    + import { ClaimTypes, IdentityMetadataWrapper } from '@celo/metadata-claims'
    

    Note that Contractkit is Not a dependency. Instead when using IdentityMetadataWrapper you should make an object that satisfis the AccountMetadataSignerGetters type

    import { AccountMetadataSignerGetters } from '@celo/metadata-claims/lib/types'

    using viem it would be like

    const accountsMetaDataSignerGetters: AccountMetadataSignerGetters = {
      isAccount: async (address: string) => accounts.read.isAccount([address as Address]),
      getValidatorSigner: async (address: string) =>
        accounts.read.getValidatorSigner([address as Address]),
      getVoteSigner: async (address: string) =>
        accounts.read.getValidatorSigner([address as Address]),
      getAttestationSigner: async (address: string) =>
        accounts.read.getValidatorSigner([address as Address]),
    }

Minor Changes

  • #447 7bc05c2 Thanks @shazarre! - Exposes EpochManager.getElectedSigners contract method

  • 76045eb Thanks @shazarre! - ValidatorsWrapper: add registerValidatorNoBls to allow registration without BLS keys which are not supported in L2

Patch Changes

  • #463 eba89a3 Thanks @aaronmgdr! - Add GovernanceSlasher to RegisteredContractsEnum

  • #467 43e8474 Thanks @shazarre! - fix: add transferOwnership() to proxy abi list

  • #446 42d091f Thanks @aaronmgdr! - Bump @celo/abis

  • #480 b83d8c4 Thanks @aaronmgdr! - Recommended node version is now node 20

  • #455 36c4369 Thanks @aaronmgdr! - Mark contract wrapper methods that will not work on L2 because solidity contracts have onlyL1 modifier as deprecated.

    | Deprecated Contract / Method | Replacement or none | | -------------------------------------------- | ----------------------------------------- | | Validators#registerValidator | Validators#registerValidatorNoBLS | | BlockchainParams#getEpochNumberOfBlock | EpochManager#getEpochNumberOfBlock | | BlockchainParams#getFirstBlockNumberForEpoch | EpochManager#getFirstBlockAtEpoch | | Election#getCurrentValidatorSigners | EpochManager#getElectedSigners | | Election#getGroupEpochRewards | Election#getGroupEpochRewardsBasedOnScore | | GovernanceSlasher#slash | GovernanceSlasher#slashL2 | | DoubleSigningSlasher | X | | DowntimeSlasher | X |

  • #400 38fe4d0 Thanks @shazarre! - Renames getElected and its usages to getElectedAccounts for EpochManagerWrapper

  • #456 d5c9204 Thanks @nicolasbrugneaux! - Backwards compat for some methods using epoch's block numbers

  • Updated dependencies [c4b9c6d, d988d31, 4ef76eb, 26b9779, fb08485]:

9.0.0-beta.5

Patch Changes

9.0.0-beta.4

Patch Changes

9.0.0-beta.3

Minor Changes

Patch Changes

  • #446 42d091f Thanks @aaronmgdr! - Bump @celo/abis

  • #455 36c4369 Thanks @aaronmgdr! - Mark contract wrapper methods that will not work on L2 because solidity contracts have onlyL1 modifier as deprecated.

    | Deprecated Contract / Method | Replacement or none | | -------------------------------------------- | ----------------------------------------- | | Validators#registerValidator | Validators#registerValidatorNoBLS | | BlockchainParams#getEpochNumberOfBlock | EpochManager#getEpochNumberOfBlock | | BlockchainParams#getFirstBlockNumberForEpoch | EpochManager#getFirstBlockAtEpoch | | Election#getCurrentValidatorSigners | EpochManager#getElectedSigners | | Election#getGroupEpochRewards | Election#getGroupEpochRewardsBasedOnScore | | GovernanceSlasher#slash | GovernanceSlasher#slashL2 | | DoubleSigningSlasher | X | | DowntimeSlasher | X |

  • #456 d5c9204 Thanks @nicolasbrugneaux! - Backwards compat for some methods using epoch's block numbers

  • Updated dependencies []:

9.0.0-beta.2

Patch Changes

9.0.0-beta.1

Minor Changes

  • 76045eb Thanks @shazarre! - ValidatorsWrapper: add registerValidatorNoBls to allow registration without BLS keys which are not supported in L2

Patch Changes

9.0.0-beta.0

Major Changes

  • #340 33ad4aa Thanks @aaronmgdr! - Removes all exports under the lib/identity folder. These have been move to a new @celo/metadata-claims package and should be imported from there.

    Note that folder structure is also flattened slightly. so replace @celo/contractkit/lib/identity/claims/ with @celo/metadata-claims/lib/

    example

    - import { createAccountClaim } from '@celo/contractkit/lib/identity/claims/account'
    + import { createAccountClaim } from '@celo/metadata-claims/lib/account'
    - import { ContractKit, IdentityMetadataWrapper, newKitFromWeb3 } from '@celo/contractkit'
    - import { ClaimTypes } from '@celo/contractkit/lib/identity'
    + import { ContractKit, newKitFromWeb3 } from '@celo/contractkit'
    + import { ClaimTypes, IdentityMetadataWrapper } from '@celo/metadata-claims'
    

    Note that Contractkit is Not a dependency. Instead when using IdentityMetadataWrapper you should make an object that satisfis the AccountMetadataSignerGetters type

    import { AccountMetadataSignerGetters } from '@celo/metadata-claims/lib/types'

    using viem it would be like

    const accountsMetaDataSignerGetters: AccountMetadataSignerGetters = {
      isAccount: async (address: string) => accounts.read.isAccount([address as Address]),
      getValidatorSigner: async (address: string) =>
        accounts.read.getValidatorSigner([address as Address]),
      getVoteSigner: async (address: string) =>
        accounts.read.getValidatorSigner([address as Address]),
      getAttestationSigner: async (address: string) =>
        accounts.read.getValidatorSigner([address as Address]),
    }

Patch Changes

8.3.1

Patch Changes

  • #409 e709b88 Thanks @aaronmgdr! - Renames getElected and its usages to getElectedAccounts for EpochManagerWrapper

8.3.0

Minor Changes

  • #348 76d09b7 Thanks @shazarre! - Adds support for firstKnownEpoch, getFirstBlockAtEpoch, getLastBlockAtEpoch on EpochManager wrapper

Patch Changes

8.2.0

Minor Changes

8.1.1

Patch Changes

8.1.1-beta.0

Patch Changes

8.1.0

Minor Changes

  • #264 59f4b42 Thanks @nicolasbrugneaux! - Add support for serializing, sending, parsing and deserializing cip66 transactions. This tx type is preffered over cip64 when paying for gas with tokens. Like eip1559 maxFeePerGass and maxPriorityFeePerGas are denominated in CELO. To create an cip66 transaction with Contractkit call the kit.populateMaxFeeInToken method with your transaction and then send it.

  • #267 f553539 Thanks @shazarre! - Introduced CeloDistributionScheduleWrapper

  • #266 182bf73 Thanks @aaronmgdr! - Adds support for FeeCurrencyDirectory contract

  • #266 182bf73 Thanks @aaronmgdr! - Introduces getConfig for FeeCurrencyDirectoryWrapper

  • #279 06019bf Thanks @shazarre! - Adds support for <1.5.0.0 and >=1.5.0.0 Governance contract version

Patch Changes

8.1.0-beta.1

Minor Changes

  • #264 59f4b42 Thanks @nicolasbrugneaux! - Add support for serializing, sending, parsing and deserializing cip66 transactions. This tx type is preffered over cip64 when paying for gas with tokens. Like eip1559 maxFeePerGass and maxPriorityFeePerGas are denominated in CELO. To create an cip66 transaction with Contractkit call the kit.populateMaxFeeInToken method with your transaction and then send it.

Patch Changes

8.1.0-beta.0

Minor Changes

Patch Changes

8.0.0

Major Changes

  • #200 6e3372f Thanks @nicolasbrugneaux! - The following changes are related to adding support for more fee currencies in the @celo packages.

    (BREAKING): setFeeCurrency changed to accept an address instead of previously accepting a StableToken (CHANGED): all places referring to gasCurrencies have been changed from string to StrongAddress for safer types. This shouldn't impact you as you already should have been giving 0x${string} in these places (CHANGED): reinforced the types of most contract wrappers to use StrongAddress where appropriate

  • #200 6e3372f Thanks @nicolasbrugneaux! - Removes stable token infos from the kit.getNetworkConfig()

    Removes from StableTokenWrapper all InflationParameters including, valueToUnits(), unitsToValues(), setInflationParameters(),

    Removes the inflation params from StableTokenWrapper.getConfig

Patch Changes

8.0.0-beta.0

Major Changes

  • #188 08b0d6a Thanks @github-actions! - The following changes are related to adding support for more fee currencies in the @celo packages.

    (BREAKING): setFeeCurrency changed to accept an address instead of previously accepting a StableToken (CHANGED): all places referring to gasCurrencies have been changed from string to StrongAddress for safer types. This shouldn't impact you as you already should have been giving 0x${string} in these places (CHANGED): reinforced the types of most contract wrappers to use StrongAddress where appropriate

  • #188 a317972 Thanks @github-actions! - Removes stable token infos from the kit.getNetworkConfig()

    Removes from StableTokenWrapper all InflationParameters including, valueToUnits(), unitsToValues(), setInflationParameters(),

    Removes the inflation params from StableTokenWrapper.getConfig

Patch Changes

7.2.0

Minor Changes

7.1.0

Minor Changes

  • #140 0ad9c01 Thanks @timmoreton! - Activate votes from any account, new optional parameter to specify for account in ElectionWrapper:activate

Patch Changes

7.1.0-beta.1

Patch Changes

7.1.0-beta.0

Minor Changes

  • #140 0ad9c01 Thanks @timmoreton! - Activate votes from any account, new optional parameter to specify for account in ElectionWrapper:activate

7.0.0

Major Changes

Patch Changes

  • #57 8fb6c76 Thanks @aaronmgdr! - Re-removes MetaTransaction wallets, as previously removed in 6.0.0 (9ab9d00eb).

    Remove support for deprecated MetaTransactionWallet and MetaTransactionWalletDeployer. If absolutely needed the contracts can be accessed directly or an alternative such as account abstraction should be used.

  • #56 7dfbcd6 Thanks @aaronmgdr! - Re-removes grandamento

    While 6.0.0 (9ab9d00eb) previously removed grandamento it was added back temporarily because @celo/celocli required the wrappers to be available in order to execute the proposal to remove it from governance. It is now gone for good. RIP.

    Due to previous removal this is not considered a breaking change.

  • Updated dependencies [6b2e34c]:

7.0.0-beta.2

Major Changes

Patch Changes

6.0.1-beta.1

Patch Changes

  • #56 7dfbcd6 Thanks @aaronmgdr! - Reremoves grandamento

    While 9ab9d00eb previously removed grandamento it was added back temporarily because the celo cli required the wrappers to be available in order to execute the proposal to remove it from governance. It is now gone for good. RIP.

    Due to previous removal this is not considered a breaking change.

6.0.1-beta.0

Patch Changes

  • #57 8fb6c76 Thanks @aaronmgdr! - Re-removes MetaTransaction wallets (as previously removed in 6.0)

    previous messsage for removal - 9ab9d00eb: Remove Support for deprecated MetaTransactionWallet and MetaTransactionWalletDeployer. IF absolutely needed the contracts can be accessed directly or an alternative such as account abstraction should be used

6.0.0

Major Changes

  • 1c9c844cf: Remove contracts from lib/generated. now available in @celo/abis package at @celo/abis/web3

6.0.0-beta.2

Patch Changes

  • ba27783ae: Revert removal of Contracts

6.0.0-beta.1

Major Changes

  • 9ab9d00eb: Remove Support for deprecated MetaTransactionWallet and MetaTransactionWalletDeployer. IF absolutely needed the contracts can be accessed directly or an alternative such as account abstraction should be used
  • 9ab9d00eb: Removes Grandamento from cli and contractkit completely as it has become no op by mento team

6.0.0-beta.0

Major Changes

  • 1c9c844cf: Remove contracts from lib/generated. now available in @celo/abis package at @celo/abis/web3

    If you were directly importing contracts from @celo/contractkit/lib/generated/* eg @celo/lib/generated/Accounts do a find replace

    find: @celo/contractkit/lib/generated/ replace: @celo/abis/web3/

5.2.1

Patch Changes

  • 88e3788b8: add notice that LockedGold.getTotalPendingWithdrawalsCount is not yet available on all networks
  • 70f600bb0: Mark MetaTransactionWallet and MetaTransactionWalletDeployer as deprecated, including functions to get them and their wrappers. see https://github.com/celo-org/celo-monorepo/issues/10766
  • 2985f9eb2: Refactor Accounts.getParsedSignatureOfAddress

5.2.0

Minor Changes

  • add FeeHandler Wrapper
  • 32face3d8: Governance delegation functions added
  • 87647b46b: Add multisig:approve command to CLI, expose MultiSig.confirmTransaction in ContractKit.

Patch Changes

5.2.0-beta.0

Minor Changes

  • add FeeHandler Wrapper
  • 32face3d8: Governance delegation functions added
  • 87647b46b: Add multisig:approve command to CLI, expose MultiSig.confirmTransaction in ContractKit.

Patch Changes

5.1.0

Minor Changes

  • d48c68afc: Add MultiSig.getTransaction() now optionally takes a second boolean param to avoid fetching confirmations information
  • d48c68afc: Add method getConfirmations() to Multisig Wrapper
  • 53bbd4958: Add cip64 support for feeCurrency Transactions. Note this is the replacement for the deprecated cip42 and legacy tx types https://github.com/celo-org/celo-proposals/blob/master/CIPs/cip/0064.md

Patch Changes

  • 53bbd4958: Note celo sdk packages will no longer be fix bumped (ie will not share the same version always) and will now use ^range when depending on each other
  • d48c68afc: parallelize async calls in Governance Wrapper
  • Updated dependencies [d48c68afc]
  • Updated dependencies [53bbd4958]
  • Updated dependencies [53bbd4958]

5.1.0-beta.0

Minor Changes

  • d48c68afc: Add MultiSig.getTransaction() now optionally takes a second boolean param to avoid fetching confirmations information
  • d48c68afc: Add method getConfirmations() to Multisig Wrapper
  • 53bbd4958: Add cip64 support for feeCurrency Transactions. Note this is the replacement for the deprecated cip42 and legacy tx types https://github.com/celo-org/celo-proposals/blob/master/CIPs/cip/0064.md

Patch Changes