Skip to content

Celo

Integrating with Celo in Viem

Viem provides first-class support for chains implemented on Celo.

Chains

The following Viem chains are implemented on Celo:

import {
  celo, 
  celoAlfajores, 
  celoCannoli, 
} from 'viem/chains'

Configuration

Viem exports Celo's chain formatters & serializers via chainConfig. This is useful if you need to define another chain which is implemented on Celo.

import { defineChain } from 'viem'
import { chainConfig } from 'viem/celo'
 
export const celoExample = defineChain({
  ...chainConfig,
  name: 'Celo Example',
  // ...
})

Utilities

parseTransaction

Parses a serialized RLP-encoded transaction. Supports signed & unsigned CIP-42, CIP-64, EIP-1559, EIP-2930 and Legacy Transactions.

Celo-flavored version of Viem's parseTransaction.

Parameters

  • serializedTransaction (Hex): The serialized transaction.
import { parseTransaction } from 'viem/celo'
 
const transaction = parseTransaction('0x7cf84682a4ec80847735940084773594008094765de816845861e75a25fca122bb6898b8b1282a808094f39fd6e51aad88f6f4ce6ab8827279cfffb92266880de0b6b3a764000080c0')

serializeTransaction

Serializes a transaction object. Supports CIP-42, CIP-64, EIP-1559, EIP-2930, and Legacy transactions.

Celo-flavored version of Viem's serializeTransaction.

Parameters

  • transaction (TransactionSerializable): The transaction object to serialize.
  • signature (Signature): Optional signature to include.
import { serializeTransaction } from 'viem/celo'
 
const serialized = serializeTransaction({
  chainId: 1,
  gas: 21001n,
  gatewayFee: parseGwei('3'),
  gatewayFeeRecipient: '0x1234512345123451234512345123451234512345',
  maxFeePerGas: parseGwei('20'),
  maxPriorityFeePerGas: parseGwei('2'),
  nonce: 69,
  to: '0x1234512345123451234512345123451234512345',
  value: parseEther('0.01'),
})