Skip to main content

Celo

tip

Celo developers make use of external libraries like DappKit. The following is an explanation of how to initiate a transfer transaction by invoking the eth_sendTransaction method through dapp.request. We recommend utilizing a dedicated library rather than accessing the service directly if you want a greater degree of abstraction than the API provides.

To send a transaction in Celo network, it needs to be followed the steps below.

  1. Detecting of Universal Provider (window.dapp)
  2. Detecting the Celo network to which the user is linked
  3. Import the Celo account of the user

The WELLDONE Wallet finds and imports networks associated with that wallet address. Before submitting a transaction, you should evaluate whether to transmit it to the mainnet or the testnet. The following format can be used to transmit the transaction:

const response = await window.dapp.request('celo', {
method: 'dapp:signAndSendTransaction',
params: [TransactionParameters],
});

1. Returns

This method returns the transaction hash value as a Promise object of type string because you can send multiple transactions as well as one transaction.

Promise<string[]>;

2. Params

The dapp:signAndSendTransaction method takes the transaction as HEX string type HEX_STRING_TX_DATA. However, EVM networks such as Celo can take the eth_sendTransaction parameters as it is. In other words, you can put the transaction objects in the parameters as they are.

interface TransactionParameters {
from: string;
to: string;
gas?: string; // overwritten by WELLDONE Wallet
gasPrice?: string; // overwritten by WELLDONE Wallet
value?: string;
data: string;
feeCurrency?: string; // Celo-specific option
gatewayFeeRecipient?: string; // Celo-specific option
gatewayFee?: string; // Celo-specific option
}
  • from : The address the transaction is sent from.

  • to : (optional when creating new contract) The address the transaction is directed to.

  • gas : (optional) Integer of the gas provided for the transaction execution. It will return unused gas.

  • gasPrice : (optional) Integer of the gasPrice used for each paid gas, in Wei.

  • value : (optional) Integer of the value sent with this transaction, in Wei.

  • data : The compiled code of a contract OR the hash of the invoked method signature and encoded parameters.

  • feeCurrency : (optional) address of the ERC20 contract to use to pay for gas and the gateway fee

  • gatewayFeeRecipient : (optional) coinbase address of the full serving the light client's trasactions

  • gatewayFee : (optional) value paid to the gateway fee recipient, denominated in the fee currency

note
  • The gas and gasPrice fields are overwritten by the WELLDONE Wallet internal logic.
  • gatewayFeeRecipient and gatewayFee are options to support full node incentives, which are not currently implemented by the protocol.

3. Example

const sendTransaction = async () => {
// get accounts first
const accounts = await dapp.request('celo', { method: 'dapp:accounts' });
const transactionParameters = {
from: accounts['celo'].address,
to: accounts['celo'].address, // send to yourself
value: '0x00',
data: '0x6057361d000000000000000000000000000000000000000000000000000000000008a198',
};
// sending a transaction
try {
const response = await dapp.request('celo', {
method: 'dapp:signAndSendTransaction',
params: [transactionParameters],
});
const txHash = response[0];
} catch (error) {
/*
{
message: 'User denied transaction signature',
code: 4001,
}
*/
}
};

To complete the transaction, follow the steps outlined below. The testnet token is required to transmit a transaction. You can request faucet through the FAUCET tab in the wallet.

Live Editor
Result
Loading...