The Conflux implementation structure is different from Ethereum, so there are great differences in concept and implementation. This article mainly introduces the differences between Conflux RPC and Ethereum RPC

The concept is introduced

Epoch

In the Ethereum blockchain, only transactions on the main chain are valid, so it can be considered that the Ethereum blockchain ledger is a single chain, and each block from front to back has a number called block number. Conflux developed a new ledger structure: tree graph, which achieves high throughput and low latency.

In the block structure of the Tree Graph, it is a Tree if only the parent edge is looked at, and it is a Graph if both parent edges are looked at. It is this structure that allows Conflux networks to emit blocks simultaneously, that is, multiple blocks can be generated after a block. Therefore, there is no concept of block number in Conflux. However, in order to realize the complete order, Conflux starts from the genesis block by GHAST rule and selects the most barysubtree block from all its sub-blocks as pivot block. All pivot block chains to one block also form a chain defined as Pivot chain. If you just look at the pivot chain, which has the same structure as the ordinary blockchain, one Epoch is defined on the chain based on each pivot block. Therefore, you can understand the Epoch in Conflux as a concept corresponding to the block number. It’s just that there may be multiple blocks in each epoch in Conflux.

Storage Limit

In the real world, banks pay fees to send money transactions, miners pay fees to send transactions in Bitcoin, and the same is true in Ethereum. Specifically, transactions on the Ethereum network are ultimately executed by EVM run by miners. Gas is used to measure the amount of work (i.e. hours of work) performed by a transaction. The transaction sender can specify the price he/she is willing to pay for each amount of work when sending a transaction, namely the gasPrice. So the final transaction fee is gas * gasPrice. The gas specified when sending a transaction is a limit value, that is, the maximum amount of time the sender is willing to pay GAS for a transaction. If the transaction requires more work than GAS, no more money will be paid and the transaction will not be executed.

In Dapp system, transaction execution requires miners not only to pay computing resources for calculation, but also to store the state of the contract, so storage resources need to be paid. When sending a transaction in the Conflux system, it is also necessary to pledge part of the cost for the state storage. Therefore, when sending a transaction in Conflux, there is one more parameter storageLimit than Ethereum, which is used to set the upper limit of the cost that is willing to pledge for a transaction storage. The cost of the mortgage is refunded after the contract frees up the storage used.

This section describes RPC parameters

Epoch Number is optional

When sending RPC requests, some RPCS need to carry the Epoch Number parameter, which indicates the state in which Epoch is being requested. The following are the options for the Epoch Number parameter:

format meaning
Hexadecimal string Epoch Number Integer value (for example, “0x1000” indicates epoch Number 4096)
The string “earliest” The height of the Epoch where the Creation block was located
The string “latest_checkpoint” Height of the first Epoch of the current checkpoint
The string “latest_state” The Epoch height of the most recently executed block
The string “latest_mined” Epoch height of the newly excavated block

Note that the latest epochs are not executable for performance optimization reasons, so there are no available states in these epochs. For most RPCs related to status queries, “latest_state” is recommended.

Hexadecimal coding rules for data

When sending RPC requests, two key data types are transferred through JSON, unformatted byte arrays and numeric values. Both are transmitted in hexadecimal code, but in slightly different formats:

1. Logarithmic coding

When encoding numeric values (integers, numbers) : Encode the hexadecimal prefix “0x”, using the most compact representation (exception: zero is represented as “0x0”). The following is an example:

Correct examples:

  • 0x41 (Decimal number 65)
  • 0x400 (Decimal number 1024)

Examples of errors:

  • Error: 0x (must have at least one digit – zero is “0x0”)
  • Error: 0x0400 (starting with zero is not allowed)
  • Error: ff (must be prefixed with 0x)

2. Encode unformatted data

When encoding unformatted data (byte arrays, account addresses, hashes, bytecode arrays), the hexadecimal prefix “0x” is also used. The difference is that each byte must contain two hexadecimal digits. The following is an example:

Correct examples:

  • 0x41 (Length 1 for string “A”)
  • 0x004200 (Length 3, representing string “\0B\0”)
  • 0x (length 0 for string “”)

The wrong sample

  • Error: 0xf0F0F (Must be Even Digits)
  • Error: 004200 (must start with 0x)

Set GasLimit & StorageLimit & EpochHeight

When sending a transaction, it is recommended to use RPC cfx_estimateGasAndCollateral first to return estimated gas usage and storage collateral. However, the actual execution consumption is different from the expected result. To prevent transaction execution failures, it is recommended that you set the values of gaslimit and storage_limit to the estimated value * 4/3 during actual transaction sending.

EpochHeight indicates that the transaction will be executed within the Epoch of EpochHeight-100000, EpochHeight+100000. If the Epoch exceeds the Epoch, the transaction will be discarded. It is recommended to set the current Epoch value.

Conflux VS Ethereum JSONRPC

Here is a comparison of the use of JSON RPC for Conflux versus Ethereum. See JSON RPC developer documentation for details on Conflux RPC

Public RPC

Conflux Public RPC Corresponding Ethereum RPC RPC parameters Need epoch Number parameter?
cfx_gasPrice eth_gasPrice N
cfx_epochNumber eth_blockNumber epoch_number Y
cfx_getBalance eth_getBalance address,epoch_number Y
cfx_getAdmin address,epoch_number Y
cfx_getSponsorInfo address,epoch_number Y
cfx_getStakingBalance address,epoch_number Y
cfx_getCollateralForStorage address,epoch_number Y
cfx_getCode eth_getCode address,epoch_number Y
cfx_getStorageAt eth_getStorageAt address,pos,epoch_number Y
cfx_getStorageRoot address,epoch_number Y
cfx_getBlockByHash eth_getBlockByHash block_hash,include_txs N
cfx_getBlockByHashWithPivotAssumption block_hash, pivot_hash, epoch_number, Y
cfx_getBlockByEpochNumber eth_getBlockByNumber epoch_number, include_txs Y
cfx_getBestBlockHash N
cfx_getNextNonce address, epoch_number Y
cfx_sendRawTransaction eth_sendRawTransaction raw_tx N
cfx_call eth_call tx, epoch_number Y
cfx_getLogs eth_getLogs filter N
cfx_getTransactionByHash eth_getTransactionByHash tx_hash N
cfx_estimateGasAndCollateral eth_estimateGas request, epoch_number Y
cfx_checkBalanceAgainstTransaction account_addr, contract_addr, gas_limit,gas_price, storage_limit, epoch Y
cfx_getBlocksByEpoch epoch_number Y
cfx_getSkippedBlocksByEpoch epoch_number Y
cfx_getTransactionReceipt eth_getTransactionReceipt tx_hash N
cfx_getAccount address, epoch_number Y
cfx_getInterestRate epoch_number Y
cfx_getAccumulateInterestRate epoch_number Y
cfx_getConfirmationRiskByHash block_hash N
cfx_getStatus N
cfx_getBlockRewardInfo epoch_number Y
cfx_clientVersion web3_clientVersion N

Local RPC

Conflux In addition to public RPCS, some RPCS are restricted to local access for security and performance reasons

Conflux local rpc Corresponding Ethereum RPC
txpool_status
tx_inspect
txpool_inspect
txpool_content eth_newPendingTransactionFilter
getTransactionsFromPool
clear_tx_pool
net_throttling
net_node
net_disconnect_node
net_sessions
current_sync_phase
consensus_graph_state
sync_graph_state
cfx_sendTransaction eth_sendTransaction
accounts eth_accounts
new_account
unlock_account
lock_account
sign eth_sign

There is no corresponding Ethereum RPC currently

Here are the RPCS that Conflux has no correspondence with in Ethereum

  • web3_sha3
  • net_version
  • net_peerCount
  • net_listening
  • eth_protocolVersion
  • eth_coinbase
  • eth_mining
  • eth_hashrate
  • eth_getTransactionCount
  • eth_getBlockTransactionCountByHash
  • eth_getBlockTransactionCountByNumber
  • eth_getUncleCountByBlockHash
  • eth_getUncleCountByBlockNumber
  • eth_signTransaction
  • eth_getTransactionByBlockHashAndIndex
  • eth_getTransactionByBlockNumberAndIndex
  • eth_getUncleByBlockHashAndIndex
  • eth_getUncleByBlockNumberAndIndex
  • eth_getCompilers
  • eth_compileLLL
  • eth_compileSolidity
  • eth_compileSerpent
  • eth_newFilter
  • eth_newBlockFilter
  • eth_uninstallFilter
  • eth_getFilterChanges
  • eth_getWork
  • eth_submitWork
  • eth_submitHashrate
  • db_putString
  • db_getString
  • db_putHex
  • db_getHex
  • shh_post
  • shh_version
  • shh_newIdentity
  • shh_hasIdentity
  • shh_newGroup
  • shh_addToGroup
  • shh_newFilter
  • shh_uninstallFilter
  • shh_getFilterChanges
  • shh_getMessages
  • eth_syncing