Skip to content

Latest commit

 

History

History
66 lines (49 loc) · 5.01 KB

starknet_vs_ethereum_node_apis.md

File metadata and controls

66 lines (49 loc) · 5.01 KB

General

This document provides information to developers who wish to work with StarkNet's node RPC API and are familiar with Ethereum's RPC API. The document focuses on existing APIs, specifically targeting distributed application developers.

As a general rule, the APIs are similar in naming, semantics and conventions. We generally follow the same methods used in Ethereum's node API and make changes where the technology requires it to maintain consistency.

Below you can find a summary of the changes, whether cross-cutting or method-specific. We also provide a mapping of methods.

We currently compare Ethereum 1.0 API, as defined here, and StarkNet's API.

Familiarity with Ethereum and StarkNet is assumed herein.

Cross-Cutting Changes

Some differences are more fundamental and manifest in different API methods.

Block and Transaction objects: Block and transaction objects have a somewhat different structure compared to Ethereum. These changes are mainly due to different network mechanics, e.g., no proof of work in StarkNet.

Block Tags: In some cases, the API refers to a block using relative tags that point to a block in a specific position in the chain or state (latest, earliest, pending). Where applicable, StarkNet allows referring only to the latest block, using the latest tag.

Naming Conventions

Unless otherwise noted, the method names used are the same method names with a different prefix. The eth prefix is replaced with starknet.

Types

The fundamental data type in StarkNet is a field element. As a corollary, all resulting blocks and transactions' hashes are also field elements. When referring to a block/transaction type or an address, StarkNet uses a field element, not a 256-bit number.

The field element type in StarkNet is based on the field in the underlying Cairo VM. In other words, a value x of a field element type is an integer in the range of 0≤x<P. P is currently defined as 2^251+17*2^192+1

Mapping of Methods

We list below the methods in Ethereum's API and their corresponding StarkNet methods.

Ethereum Method StarkNet Method Differences From Ethereum
eth_blockNumber starknet_blockNumber Will return only the block number
eth_chainId starknet_chainId
eth_getBlockByNumber starknet_getBlockByNumber
  • Doesn’t have the include transactions input.
  • The result key is “result”.
eth_getBlockTransactionCountByHash starknet_getBlockTransactionCountByHash
  • Supports also “latest” block tag as input
  • The result is always an integer
  • The response key is “result”.
  • May return an error for invalid block hash.
eth_getBlockTransactionCountByNumber starknet_getBlockTransactionCountByNumber
  • Block number input is given as a decimal integer.
  • The result key is “result”.
  • May return an error for invalid block number.
eth_getTransactionByBlockHashAndIndex starknet_getTransactionByBlockHashAndIndex
  • The Index is given as a decimal integer.
  • eth_getTransactionByBlockNumberAndIndex starknet_getTransactionByBlockNumberAndIndex
  • The index is given as a decimal integer.
  • eth_pendingTransactions starknet_pendingTransactions
    • The result key is “result”.
    • Will not return market fee parameters.
    eth_getBlockByHash starknet_getBlockByHash
    • Doesn’t have the include transactions input.
    • The result key is “result”.
    eth_protocolVersion starknet_protocolVersion
    eth_syncing starknet_syncing
  • The result will not include known and pulled states
  • eth_getStorageAt starknet_getStorageAt
    • Accepts a block hash instead of a block number
    • The result key is “result”.
    • The result type is a field element.
    • Will return errors for invalid contract or storage keys.
    eth_getTransactionByHash starknet_getTransactionByHash
    • Input key is “transaction_hash”.
    • The result key is “result”.
    • Will not return null.
    • Will return an error for an invalid transaction hash.
    eth_getTransactionReceipt starknet_getTransactionReceipt
    • Input key is “transaction_hash”.
    • The result key is “result”.
    • Will not return null.
    • Will return an error for an invalid transaction hash.
    eth_getCode starknet_getCode
    • The input key is “contract_address”.
    • Does not accept a block number.
    • Will return byte code (field elements) and ABI.
    • Will return an error for an invalid contract address.
    eth_call starknet_call
    • Input transaction is different.
    • Input block designated by hash.
    • Will return errors for invalid contract address