Celo - Getting Started (REST API)

This article covers the steps required to create a Celo wallet and generate addresses and private keys. It includes an example of checking the address balance and transferring funds to another Celo address.

πŸ“˜

The following steps and examples are based on Celo Alfajores (testnet).

Steps

Step_1: Generate a Mnemonic

Generating a mnemonic means creating a 24-word phrase that will be the foundation for your wallet. This phrase is like a master key from which all your wallet addresses and their private keys can be generated.

  • Tatum does not store Mnemonics and or Private Keys.
  • The responsibility of keeping your Mnemonics and Private Keys secure rests solely with you, the User.
  • Additional information about Mnemonics and Private Keys is available in the following article.

Example request:

  • The response returns a Mnemonic and a Celo XPUB
curl --location 'https://api.tatum.io/v3/celo/wallet' \
--header 'x-api-key: {YOUR_API_KEY}'
//Response:
{
    "xpub": "xpub6E633e5b4gYG2NnKxf99VcjRBpLv2Szcuoypn1wBkAbgMmubtNW9EsqzoAQZHdNX23HG4Lf7bNZUAVcBsZcuka2GRY1HQtgHNa2Pyfw2iGW",
    "mnemonic": "duck spoon spend into satisfy uncle fiber action tank deposit dad olive sorry reflect security issue carpet garden height add use #### #### ####"
}

πŸ“˜

Be mindful of Tatum's Derivation Path.

Step_2: Generate a Celo Private Key from Mnemonic and index

Creating a private key is creating a unique and secret key that belongs to you. This key is crucial for accessing and controlling your funds.

Example request:

  • The response returns a Celo Private Key based on index 1.
curl --location 'https://api.tatum.io/v3/celo/wallet/priv' \
--header 'Content-Type: application/json' \
--header 'x-api-key: {YOUR_API_KEY}' \
--data '{
    "mnemonic": "duck spoon spend into satisfy uncle fiber action tank deposit dad olive sorry reflect security issue carpet garden height add use #### #### ####",
    "index": 1
}'
//Response:
{
    "key": "####"
}

Step_3: Generate a Celo address from XPUB and index

Generating an address is about creating a public address where others can send you funds. It's like an account number in the blockchain world.

Example request:

  • The response returns a Celo Externally Owned Address (EOA) based on index 1
curl --location 'https://api.tatum.io/v3/celo/address/xpub6E633e5b4gYG2NnKxf99VcjRBpLv2Szcuoypn1wBkAbgMmubtNW9EsqzoAQZHdNX23HG4Lf7bNZUAVcBsZcuka2GRY1HQtgHNa2Pyfw2iGW/1' \
--header 'x-api-key: {YOUR_API_KEY}'
//Response:
{
    "address": "0xa57628beccedc2089acd8ed5399398cb74d856f0"
}

Step_4: Add funds to the Celo address

  • We take the address generated in step_3.
  • For testnet, you can get free coins from a faucet.
{
    "address": "0xa57628beccedc2089acd8ed5399398cb74d856f0"
}

Step_5: Check the balance of a Celo address

Request example:

  • The response returns the balance from a Celo address
curl --location 'https://api.tatum.io/v3/celo/account/balance/0xa57628beccedc2089acd8ed5399398cb74d856f0' \
--header 'x-api-key: {YOUR_API_KEY}'
//Response:
{
    "celo": "2.48",
    "cUsd": "0",
    "cEur": "0"
}

Step_6: Estimate the fees of a Celo transaction

Tatum Fee estimates endpoints return values in Wei. Find more about EVM Fee Estimate in the following article.

Request example:

  • The response returns an estimation of the potentially required Gas Used via "GasLimit" and the "GasPrice". Additional information is available in the following article.
curl --location 'https://api.tatum.io/v3/celo/gas' \
--header 'Content-Type: application/json' \
--header 'x-api-key: {YOUR_API_KEY}' \
--data '{
    "from": "0xa57628beccedc2089acd8ed5399398cb74d856f0",
    "to": "0x23b77b9b1d9fcb9df8ed31f7b3b538270c234594",
    "amount": "1.2"
}'
//Response:
{
    "gasLimit": 27300,
    "gasPrice": "10000000000" //This value is returned in WEI!
}

Step_7: Check the current "nonce" value from the sender's address

The "nonce" is a unique and incremental counter used to ensure that each transaction is processed only once, preventing replay attacks. EVM transactions require this. Find more about the "nonce" in the following article.

Request example:

  • The response returns the current "nonce" value from a Celo address
curl --location 'https://api.tatum.io/v3/celo/transaction/count/0xa57628beccedc2089acd8ed5399398cb74d856f0' \
--header 'x-api-key: {YOUR_API_KEY}'
//Response:
0

Step_8: Sign and broadcast a Celo transaction

Request example:

  • The response returns a transaction hash
curl --location 'https://api.tatum.io/v3/celo/transaction' \
--header 'Content-Type: application/json' \
--header 'x-api-key: {YOUR_API_KEY}' \
--data '{
    "to": "0x23b77b9b1d9fcb9df8ed31f7b3b538270c234594",
    "currency": "CELO",
    "feeCurrency": "CELO",
    "amount": "1.2",
    "fee": {
        "gasPrice": "10", // In GWEI!
        "gasLimit": "27300"
    },
    "nonce": 0,
    "fromPrivateKey": "SENDER_ADDRESS_PRIVATE_KEY"
}'
//Response:
{
    "txId": "0x94a96af24c9b7454a2355adbce1b912b0eaec6ac0a99cda0a5f09a2b2ec51c34"
}

Step_9: Get the details of a Celo transaction

Request example:

  • The response returns the details of a Celo transaction hash
curl --location 'https://api.tatum.io/v3/celo/transaction/0x94a96af24c9b7454a2355adbce1b912b0eaec6ac0a99cda0a5f09a2b2ec51c34' \
--header 'x-api-key: {YOUR_API_KEY}'
//Response:
{
    "transactionHash": "0x94a96af24c9b7454a2355adbce1b912b0eaec6ac0a99cda0a5f09a2b2ec51c34",
    "blockHash": "0x910ed451803d76dab83c0921716cdf072250b111d51e1ba1f4867acc84c27041",
    "blockNumber": 24734693,
    "from": "0xa57628beccedc2089acd8ed5399398cb74d856f0",
    "gas": 27300,
    "gasPrice": "10000000000",
    "feeCurrency": null,
    "gatewayFeeRecipient": null,
    "gatewayFee": "0x0",
    "input": "0x",
    "nonce": 0,
    "to": "0x23b77b9b1d9fcb9df8ed31f7b3b538270c234594",
    "transactionIndex": 0,
    "value": "1200000000000000000",
    "type": 0,
    "ethCompatible": false,
    "contractAddress": null,
    "cumulativeGasUsed": 21000,
    "effectiveGasPrice": 10000000000,
    "gasUsed": 21000,
    "logs": [],
    "logsBloom": "0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
    "status": true,
    "hash": "0x94a96af24c9b7454a2355adbce1b912b0eaec6ac0a99cda0a5f09a2b2ec51c34",
    "maxFeePerGas": null,
    "maxPriorityFeePerGas": null,
    "chainId": null
}

Good to Know

  • Fee Estimates may fluctuate one way or the other, within seconds.
    • Tatum Mainnet Fee Estimates are generally in line with other providers.
    • The Testnet Fee Estimate is generally unreliable. Since testnet coins have "no value", users tend to set random amounts greatly skewing the estimates.
  • Be mindful of Tatum's derivation path. Find additional information in the following article.
  • To transfer tokens on the CELO network, check the following article.
  • Familiarize yourself with the Safety & Security Basics in the following article.