Skip to main content

Ethereum API

Introduction​

DVM(Darwinia Virtual Machine) is fully compatible with EVM (Ethereum Virtual Machine) in Darwinia Network.

You can use web3.js or other ethereum tools to interact with Darwinia using Ethereum compactible RPC api.

RPC List​

Note: The currently implemented RPC apis is compatible with Ethereum, but some apis are not yet implemented.

Supported Interfaces​

  • debug_traceBlockByNumber
  • debug_traceByHash
  • debug_traceTransaction
  • eth_accounts
  • eth_blockNumber
  • eth_chainId
  • eth_coinbase
  • eth_call
  • eth_estimateGas
  • eth_feeHistory
  • eth_gasPrice
  • eth_getBlockByHash
  • eth_getBlockByNumber
  • eth_getTransactionCount
  • eth_getBlockTransactionCountByHash
  • eth_getBlockTransactionCountByNumber
  • eth_getCode
  • eth_getTransactionByBlockHashAndIndex
  • eth_getTransactionByHash
  • eth_getTransactionByBlockNumberAndIndex
  • eth_getTransactionReceipt
  • eth_getUncleByBlockHashAndIndex
  • eth_getUncleByBlockNumberAndIndex
  • eth_getUncleCountByBlockHash
  • eth_getUncleCountByBlockNumber
  • eth_getLogs
  • eth_getWork
  • eth_getBalance
  • eth_getFilterChanges
  • eth_getFilterLogs
  • eth_hashrate
  • eth_mining
  • eth_newFilter
  • eth_newBlockFilter
  • eth_newPendingTransactionFilter
  • eth_protocolVersion
  • eth_sendTransaction
  • eth_sendRawTransaction
  • eth_submitWork
  • eth_submitHashrate
  • eth_subscription
  • eth_syncing
  • eth_unsubscribe
  • eth_uninstallFilter
  • net_version
  • net_peerCount
  • net_listening
  • trace_filter
  • web3_clientVersion
  • web3_sha3

Things Dapp developers must know​

Use block.timestamp instead of block.number​

On Ethereum or other EVM-Compatible platform, you may use block.number in contract, but this is not recommended in CSC. We may introduce CSC 2.0 (The Next Generation of CSC) in the future and export the data from CSC 1.0 to CSC 2.0, which may reset the chain height to zero, so we recommend using block.timestamp.

Ethereum uses a consensus protocol named Proof-of-Work (PoW). While CSC uses the Nominated Proof of Stake(NPOS). They are two completely different consensus mechanisms. Consequently, Proof of Work concepts, such as difficulty, uncles, hashrate, generally is not applicable to CSC. For APIs that return value related to Ethereum’s Proof of Work, default value are returned.

Genesis Block​

It is particularly important to note that CSC's genesis block does not start at 0 like Ethereum. It is 4969901. This means that if you try to query the block history before 4969901 with eth_getBlockByNumber() or eth_getBlockByHash(), you will get null. This is because the DVM smart contract solution was added in the middle of the Substrate-base Crab chain, there are no Ethereum transactions in the Substrate history blocks and no corresponding Ethereum history blocks generated.

Ethereum Block Author​

The author(miner) of the ethereum block you get from eth_getBlockByNumber() or eth_getBlockByHash() is the last 20 bytes of the actual substrate block author. It's because the ethereum block is built based on substrate block and who's author is a 32-bytes address. We have to truncate to adapt ethereum block needs. Please do not tranfer to the ethereum block author, since the private key of this address is unknown.

Dev Tools​

Darwinia is EVM-compatiable, so your can use almost all toolchains for EVM. Here are some of our picks:

Wallets:

Libraries:

Contract Libraries:

Dev Environment: