Standard JSON-RPC API

Below you will find the standard JSON-RPC calls that are compatible with Alchemy.

For more information on Ethereum JSON-RPC check out the Ethereum Wiki.

HINT: If you click on the "Example" title you can try out all the example requests in real-time using our Composer tool!

โ€‹๐Ÿ“ฆ Retrieving Blocks

Calls related to retrieving blocks and block information.

eth_blockNumber

Returns the number of the most recent block.

Parameters

none

Returns

QUANTITY - integer of the current block number the client is on.

โ€‹Exampleโ€‹

Request

Curl
Postman
Curl
curl https://eth-mainnet.alchemyapi.io/v2/your-api-key \
-X POST \
-H "Content-Type: application/json" \
-d '{"jsonrpc":"2.0","method":"eth_blockNumber","params":[],"id":0}'
Postman
URL: https://eth-mainnet.alchemyapi.io/v2/your-api-key
RequestType: POST
Body:
{
"jsonrpc":"2.0",
"method":"eth_blockNumber",
"params":[],
"id":0
}

Result

{
"jsonrpc": "2.0",
"id": 0,
"result": "0xa1c054"
}

eth_getBlockByHash

Returns information about a block by hash.

Parameters

  • DATA, 32 Bytes - Hash of a block.

  • Boolean - If true it returns the full transaction objects, if false it returns only the hashes of the transactions.

params: [
'0xc0f4906fea23cf6f3cce98cb44e8e1449e455b28d684dfa9ff65426495584de6',
true
]

Returns

Object - A block object with the following fields, or null when no block was found:

  • number: QUANTITY - the block number. null when its pending block.

  • hash: DATA, 32 Bytes - hash of the block. null when its pending block.

  • parentHash: DATA, 32 Bytes - hash of the parent block.

  • nonce: DATA, 8 Bytes - hash of the generated proof-of-work. null when its pending block.

  • sha3Uncles: DATA, 32 Bytes - SHA3 of the uncles data in the block.

  • logsBloom: DATA, 256 Bytes - the bloom filter for the logs of the block. null when its pending block.

  • transactionsRoot: DATA, 32 Bytes - the root of the transaction trie of the block.

  • stateRoot: DATA, 32 Bytes - the root of the final state trie of the block.

  • receiptsRoot: DATA, 32 Bytes - the root of the receipts trie of the block.

  • miner: DATA, 20 Bytes - the address of the beneficiary to whom the mining rewards were given.

  • difficulty: QUANTITY - integer of the difficulty for this block.

  • totalDifficulty: QUANTITY - integer of the total difficulty of the chain until this block.

  • extraData: DATA - the "extra data" field of this block.

  • size: QUANTITY - integer the size of this block in bytes.

  • gasLimit: QUANTITY - the maximum gas allowed in this block.

  • gasUsed: QUANTITY - the total used gas by all transactions in this block.

  • timestamp: QUANTITY - the unix timestamp for when the block was collated.

  • transactions: Array - Array of transaction objects, or 32 Bytes transaction hashes depending on the last given parameter.

  • uncles: Array - Array of uncle hashes.

โ€‹Exampleโ€‹

Request

Curl
Postman
Curl
curl https://eth-mainnet.alchemyapi.io/v2/your-api-key \
-X POST \
-H "Content-Type: application/json" \
-d '{"jsonrpc":"2.0","method":"eth_getBlockByHash","params":["0xc0f4906fea23cf6f3cce98cb44e8e1449e455b28d684dfa9ff65426495584de6", true],"id":0}'
Postman
URL: https://eth-mainnet.alchemyapi.io/v2/your-api-key
RequestType: POST
Body:
{
"jsonrpc":"2.0",
"method":"eth_getBlockByHash",
"params":["0xc0f4906fea23cf6f3cce98cb44e8e1449e455b28d684dfa9ff65426495584de6", true],
"id":0
}

Result

{
"jsonrpc": "2.0",
"id": 0,
"result": {
"difficulty": "0x2d50ba175407",
"extraData": "0xe4b883e5bda9e7a59ee4bb99e9b1bc",
"gasLimit": "0x47e7c4",
"gasUsed": "0x5208",
"hash": "0xc0f4906fea23cf6f3cce98cb44e8e1449e455b28d684dfa9ff65426495584de6",
"logsBloom": "0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
"miner": "0x61c808d82a3ac53231750dadc13c777b59310bd9",
"mixHash": "0xc38853328f753c455edaa4dfc6f62a435e05061beac136c13dbdcd0ff38e5f40",
"nonce": "0x3b05c6d5524209f1",
"number": "0x1e8480",
"parentHash": "0x57ebf07eb9ed1137d41447020a25e51d30a0c272b5896571499c82c33ecb7288",
"receiptsRoot": "0x84aea4a7aad5c5899bd5cfc7f309cc379009d30179316a2a7baa4a2ea4a438ac",
"sha3Uncles": "0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347",
"size": "0x28a",
"stateRoot": "0x96dbad955b166f5119793815c36f11ffa909859bbfeb64b735cca37cbf10bef1",
"timestamp": "0x57a1118a",
"totalDifficulty": "0x262c34a6fd1268f6c",
"transactions": [
"0xc55e2b90168af6972193c1f86fa4d7d7b31a29c156665d15b9cd48618b5177ef"
],
"transactionsRoot": "0xb31f174d27b99cdae8e746bd138a01ce60d8dd7b224f7c60845914def05ecc58",
"uncles": []
}
}

eth_getBlockByNumber

Returns information about a block by block number.

Parameters

  • QUANTITY|TAG - integer of a block number, or the string "earliest", "latest" or "pending", as in the default block parameter.

  • Boolean - If true it returns the full transaction objects, if false only the hashes of the transactions.

params: [
'0x1b4',
true
]

Returns

See eth_getBlockByHashโ€‹

โ€‹Exampleโ€‹

Request

Curl
Postman
Curl
curl https://eth-mainnet.alchemyapi.io/v2/your-api-key \
-X POST \
-H "Content-Type: application/json" \
-d '{"jsonrpc":"2.0","method":"eth_getBlockByNumber","params":["0x1b4", true],"id":0}'
Postman
URL: https://eth-mainnet.alchemyapi.io/v2/your-api-key
RequestType: POST
Body:
{
"jsonrpc":"2.0",
"method":"eth_getBlockByNumber",
"params":["0x1b4", true],
"id":0
}

Result

{
"jsonrpc": "2.0",
"id": 0,
"result": {
"number": "0x1b4",
"difficulty": "0x4ea3f27bc",
"extraData": "0x476574682f4c5649562f76312e302e302f6c696e75782f676f312e342e32",
"gasLimit": "0x1388",
"gasUsed": "0x0",
"hash": "0xdc0818cf78f21a8e70579cb46a43643f78291264dda342ae31049421c82d21ae",
"logsBloom": "0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
"miner": "0xbb7b8287f3f0a933474a79eae42cbca977791171",
"mixHash": "0x4fffe9ae21f1c9e15207b1f472d5bbdd68c9595d461666602f2be20daf5e7843",
"nonce": "0x689056015818adbe",
"parentHash": "0xe99e022112df268087ea7eafaf4790497fd21dbeeb6bd7a1721df161a6657a54",
"receiptsRoot": "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421",
"sha3Uncles": "0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347",
"size": "0x220",
"stateRoot": "0xddc8b0234c2e0cad087c8b389aa7ef01f7d79b2570bccb77ce48648aa61c904d",
"timestamp": "0x55ba467c",
"totalDifficulty": "0x78ed983323d",
"transactions": [],
"transactionsRoot": "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421",
"uncles": []
}
}

โ€‹๐Ÿงพ Reading Transactions

Calls for reading transactions.

eth_getTransactionByHash

Returns the information about a transaction requested by transaction hash. In the response object, blockHash, blockNumber, and transactionIndex are null when the transaction is pending.

Parameters

DATA, 32 Bytes - hash of a transaction

params: [
"0x88df016429689c079f3b2f6ad39fa052532c56795b733da78a91ebe6a713944b"
]

Returns

Object - A transaction object, or null when no transaction was found:

  • blockHash: DATA, 32 Bytes - hash of the block where this transaction was in. null when its pending.

  • blockNumber: QUANTITY - block number where this transaction was in. null when it's pending.

  • from: DATA, 20 Bytes - address of the sender.

  • gas: QUANTITY - gas provided by the sender.

  • gasPrice: QUANTITY - gas price provided by the sender in Wei.

  • hash: DATA, 32 Bytes - hash of the transaction.

  • input: DATA - the data send along with the transaction.

  • nonce: QUANTITY - the number of transactions made by the sender prior to this one.

  • to: DATA, 20 Bytes - address of the receiver. null when it's a contract creation transaction.

  • transactionIndex: QUANTITY - integer of the transactions index position in the block. null when its pending.

  • value: QUANTITY - value transferred in Wei.

  • v: QUANTITY - ECDSA recovery id

  • r: DATA, 32 Bytes - ECDSA signature r

  • s: DATA, 32 Bytes - ECDSA signature s

โ€‹Exampleโ€‹

Request

Curl
Postman
Curl
curl https://eth-mainnet.alchemyapi.io/v2/your-api-key \
-X POST \
-H "Content-Type: application/json" \
-d'{"jsonrpc":"2.0","method":"eth_getTransactionByHash","params":["0x88df016429689c079f3b2f6ad39fa052532c56795b733da78a91ebe6a713944b"],"id":0}'
Postman
URL: https://eth-mainnet.alchemyapi.io/v2/your-api-key
RequestType: POST
Body:
{
"jsonrpc":"2.0",
"method":"eth_getTransactionByHash",
"params":["0x88df016429689c079f3b2f6ad39fa052532c56795b733da78a91ebe6a713944b"],
"id":0
}

Result

{
"jsonrpc": "2.0",
"id": 0,
"result": {
"hash": "0x88df016429689c079f3b2f6ad39fa052532c56795b733da78a91ebe6a713944b",
"blockHash": "0x1d59ff54b1eb26b013ce3cb5fc9dab3705b415a67127a003c3e61eb445bb8df2",
"blockNumber": "0x5daf3b",
"from": "0xa7d9ddbe1f17865597fbd27ec712455208b6b76d",
"gas": "0xc350",
"gasPrice": "0x4a817c800",
"input": "0x68656c6c6f21",
"nonce": "0x15",
"r": "0x1b5e176d927f8e9ab405058b2d2457392da3e20f328b16ddabcebc33eaac5fea",
"s": "0x4ba69724e8f69de52f0125ad8b3c5c2cef33019bac3249e2c0a2192766d1721c",
"to": "0xf02c1c8e6114b1dbe8937a39260b5b0a374432bb",
"transactionIndex": "0x41",
"v": "0x25",
"value": "0xf3dbb76162000"
}
}

eth_getTransactionCount

Returns the number of transactions sent from an address.

Parameters

  • DATA, 20 Bytes - address.

  • QUANTITY|TAG - integer block number, or the string "latest", "earliest" or "pending", see the default block parameter.

params: [
'0xc94770007dda54cF92009BFF0dE90c06F603a09f',
'latest' // state at the latest block
]

Returns

QUANTITY - integer of the number of transactions send from this address.

โ€‹Exampleโ€‹

Request

Curl
Postman
Curl
curl https://eth-mainnet.alchemyapi.io/v2/your-api-key \
-X POST \
-H "Content-Type: application/json" \
-d '{"jsonrpc":"2.0","method":"eth_getTransactionCount","params":["0xc94770007dda54cF92009BFF0dE90c06F603a09f","latest"],"id":0}'
Postman
URL: https://eth-mainnet.alchemyapi.io/v2/your-api-key
RequestType: POST
Body:
{
"jsonrpc":"2.0",
"method":"eth_getTransactionCount",
"params":["0xc94770007dda54cF92009BFF0dE90c06F603a09f","latest"],
"id":0
}

Result

{
"jsonrpc": "2.0",
"id": 0,
"result": "0x219"
}

eth_getTransactionReceipt

Returns the receipt of a transaction by transaction hash.

This can also be used to track the status of a transaction, since result will be null until the transaction is mined. However, unlike eth_getTransactionByHash , which returns null for unknown transactions, and a non-null response with 3 null fields for a pending transaction, eth_getTransactionReceipt returns null for both pending and unknown transactions.

This call is also commonly used to get the contract address for a contract creation tx.

Note: the receipt is not available for pending transactions.

Parameters

DATA, 32 Bytes - hash of a transaction

params: [
'0xab059a62e22e230fe0f56d8555340a29b2e9532360368f810595453f6fdd213b'
]

Returns

Object - A transaction receipt object, or null when no receipt was found:

  • transactionHash: DATA, 32 Bytes - hash of the transaction.

  • transactionIndex: QUANTITY - integer of the transactions index position in the block.

  • blockHash: DATA, 32 Bytes - hash of the block where this transaction was in.

  • blockNumber: QUANTITY - block number where this transaction was in.

  • from: DATA, 20 Bytes - address of the sender.

  • to: DATA, 20 Bytes - address of the receiver. null when its a contract creation transaction.

  • cumulativeGasUsed: QUANTITY - The total amount of gas used when this transaction was executed in the block.

  • gasUsed: QUANTITY - The amount of gas used by this specific transaction alone.

  • contractAddress: DATA, 20 Bytes - The contract address created, if the transaction was a contract creation, otherwise null.

  • logs: Array - Array of log objects, which this transaction generated.

  • logsBloom: DATA, 256 Bytes - Bloom filter for light clients to quickly retrieve related logs.

It also returns either:

  • root : DATA 32 bytes of post-transaction stateroot (pre Byzantium)

  • status: QUANTITY either 1 (success) or 0 (failure)

โ€‹Exampleโ€‹

Request

Curl
Postman
Curl
curl https://eth-mainnet.alchemyapi.io/v2/your-api-key \
-X POST \
-H "Content-Type: application/json" \
-d '{"jsonrpc":"2.0","method":"eth_getTransactionReceipt","params":["0xab059a62e22e230fe0f56d8555340a29b2e9532360368f810595453f6fdd213b"],"id":0}
Postman
URL: https://eth-mainnet.alchemyapi.io/v2/your-api-key
RequestType: POST
Body:
{
"jsonrpc":"2.0",
"method":"eth_getTransactionReceipt",
"params":["0xab059a62e22e230fe0f56d8555340a29b2e9532360368f810595453f6fdd213b"],
"id":0
}

Result

{
"jsonrpc": "2.0",
"id": 0,
"result": {
"transactionHash": "0xab059a62e22e230fe0f56d8555340a29b2e9532360368f810595453f6fdd213b",
"blockHash": "0x8243343df08b9751f5ca0c5f8c9c0460d8a9b6351066fae0acbd4d3e776de8bb",
"blockNumber": "0x429d3b",
"contractAddress": null,
"cumulativeGasUsed": "0x64b559",
"from": "0x00b46c2526e227482e2ebb8f4c69e4674d262e75",
"gasUsed": "0xcaac",
"logs": [
{
"blockHash": "0x8243343df08b9751f5ca0c5f8c9c0460d8a9b6351066fae0acbd4d3e776de8bb",
"address": "0xb59f67a8bff5d8cd03f6ac17265c550ed8f33907",
"logIndex": "0x56",
"data": "0x000000000000000000000000000000000000000000000000000000012a05f200",
"removed": false,
"topics": [
"0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef",
"0x00000000000000000000000000b46c2526e227482e2ebb8f4c69e4674d262e75",
"0x00000000000000000000000054a2d42a40f51259dedd1978f6c118a0f0eff078"
],
"blockNumber": "0x429d3b",
"transactionIndex": "0xac",
"transactionHash": "0xab059a62e22e230fe0f56d8555340a29b2e9532360368f810595453f6fdd213b"
}
],
"logsBloom": "0x00000000040000000000000000000000000000000000000000000000000000080000000010000000000000000000000000000000000040000000000000000000000000000000000000000008000000000000000000000000000000000000000000000000000000000000000000002000000000000000000000000010000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000010100000000000000000000000000004000000000000200000000000000000000000000000000000000000000",
"root": "0x3ccba97c7fcc7e1636ce2d44be1a806a8999df26eab80a928205714a878d5114",
"status": null,
"to": "0xb59f67a8bff5d8cd03f6ac17265c550ed8f33907",
"transactionIndex": "0xac"
}
}

eth_getBlockTransactionCountByHash

Returns the number of transactions in a block matching the given block hash.

Parameters

  • DATA, 32 Bytes - hash of a block.

    params: [
    '0x8243343df08b9751f5ca0c5f8c9c0460d8a9b6351066fae0acbd4d3e776de8bb'
    ]

Returns

  • QUANTITY - integer of the number of transactions in this block.

โ€‹Exampleโ€‹

Request

Curl
Postman
Curl
curl https://eth-mainnet.alchemyapi.io/v2/your-api-key \
-X POST \
-H "Content-Type: application/json" \
-d '{"jsonrpc":"2.0","method":"eth_getBlockTransactionCountByHash","params":["0x8243343df08b9751f5ca0c5f8c9c0460d8a9b6351066fae0acbd4d3e776de8bb"],"id":0}'
Postman
URL: https://eth-mainnet.alchemyapi.io/v2/your-api-key
RequestType: POST
Body:
{
"jsonrpc":"2.0",
"method":"eth_getBlockTransactionCountByHash",
"params":["0x8243343df08b9751f5ca0c5f8c9c0460d8a9b6351066fae0acbd4d3e776de8bb"],
"id":0
}

Result

{
"jsonrpc": "2.0",
"id": 0,
"result": "0xb0"
}

eth_getBlockTransactionCountByNumber

Returns the number of transactions in a block matching the given block number.

Parameters

  • QUANTITY|TAG - integer of a block number, or the string "earliest", "latest" or "pending", as in the default block parameter.

params: [
'latest',
]

Returns

  • QUANTITY - integer of the number of transactions in this block.

โ€‹Exampleโ€‹

Request

Curl
Postman
Curl
curl https://eth-mainnet.alchemyapi.io/v2/your-api-key \
-X POST \
-H "Content-Type: application/json" \
-d '{"jsonrpc":"2.0","method":"eth_getBlockTransactionCountByNumber","params":["latest"],"id":0}'
Postman
URL: https://eth-mainnet.alchemyapi.io/v2/your-api-key
RequestType: POST
Body:
{
"jsonrpc":"2.0",
"method":"eth_getBlockTransactionCountByNumber",
"params":["latest"],
"id":0
}

Result

{
"jsonrpc": "2.0",
"id": 0,
"result": "0xee"
}

eth_getTransactionByBlockHashAndIndex

Returns information about a transaction by block hash and transaction index position.

Parameters

DATA, 32 Bytes - hash of a block.

QUANTITY - integer of the transaction index position.

params: [
'0xc0f4906fea23cf6f3cce98cb44e8e1449e455b28d684dfa9ff65426495584de6',
'0x0' // 0
]

Returns

See eth_getTransactionByHashโ€‹

โ€‹Exampleโ€‹

Request

Curl
Postman
Curl
curl https://eth-mainnet.alchemyapi.io/v2/your-api-key \
-X POST \
-H "Content-Type: application/json" \
-d '{"jsonrpc":"2.0","method":"eth_getTransactionByBlockHashAndIndex","params":["0xc0f4906fea23cf6f3cce98cb44e8e1449e455b28d684dfa9ff65426495584de6", "0x0"],"id":0}'
Postman
URL: https://eth-mainnet.alchemyapi.io/v2/your-api-key
RequestType: POST
Body:
{
"jsonrpc":"2.0",
"method":"eth_getTransactionByBlockHashAndIndex",
"params":["0xc0f4906fea23cf6f3cce98cb44e8e1449e455b28d684dfa9ff65426495584de6", "0x0"],
"id":0
}

Result

{
"jsonrpc": "2.0",
"id": 0,
"result": {
"blockHash": "0xc0f4906fea23cf6f3cce98cb44e8e1449e455b28d684dfa9ff65426495584de6",
"blockNumber": "0x1e8480",
"from": "0x32be343b94f860124dc4fee278fdcbd38c102d88",
"gas": "0x51615",
"gasPrice": "0x6fc23ac00",
"hash": "0xc55e2b90168af6972193c1f86fa4d7d7b31a29c156665d15b9cd48618b5177ef",
"input": "0x",
"nonce": "0x1efc5",
"to": "0x104994f45d9d697ca104e5704a7b77d7fec3537c",
"transactionIndex": "0x0",
"value": "0x821878651a4d70000",
"v": "0x1b",
"r": "0x51222d91a379452395d0abaff981af4cfcc242f25cfaf947dea8245a477731f9",
"s": "0x3a997c910b4701cca5d933fb26064ee5af7fe3236ff0ef2b58aa50b25aff8ca5"
}
}

eth_getTransactionByBlockNumberAndIndex

Returns information about a transaction by block number and transaction index position.

Parameters

  • QUANTITY|TAG - a block number, or the string "earliest", "latest" or "pending", as in the default block parameter.

  • QUANTITY - the transaction index position.

params: [
'latest', // 668
'0x0' // 0
]

Returns

See eth_getTransactionByHashโ€‹

โ€‹Exampleโ€‹

Request

Curl
Postman
Curl
curl https://eth-mainnet.alchemyapi.io/v2/your-api-key \
-X POST \
-H "Content-Type: application/json" \
-d '{"jsonrpc":"2.0","method":"eth_getTransactionByBlockNumberAndIndex","params":["latest", "0x0"],"id":0}'
Postman
URL: https://eth-mainnet.alchemyapi.io/v2/your-api-key
RequestType: POST
Body:
{
"jsonrpc":"2.0",
"method":"eth_getTransactionByBlockNumberAndIndex",
"params":["latest", "0x0"],
"id":0
}

Result

{
"jsonrpc": "2.0",
"id": 0,
"result": {
"blockHash": "0xf345d6ac2cb6290489915178fef0b2fc7f5a7312dd06773c77532de6740b2b4d",
"blockNumber": "0xa1c0ff",
"from": "0x79c384ac9c32e90f00a214c77caac1392ec8cdea",
"gas": "0xafbe",
"gasPrice": "0x1270b01800",
"hash": "0x61b27f711f58ee3090c0976c7e90d2b7eafeb7b889f0db593234f04f8ce07f22",
"input": "0xa9059cbb0000000000000000000000004b1a99467a284cc690e3237bc69105956816f7620000000000000000000000000000000000000000000000000000001919617600",
"nonce": "0xa",
"to": "0xf9e5af7b42d31d51677c75bbbd37c1986ec79aee",
"transactionIndex": "0x0",
"value": "0x0",
"v": "0x1b",
"r": "0x2123cdbd1130f726ebed55fd2295239778dd4161495d2733f374d7863fc42ab1",
"s": "0x1f08fd53ff2c3969b88d5e622561d62a799ae68e36f5142689dbfde44bbe1bed"
}
}

โ€‹โœ Writing Transactions

Call to write to the blockchain.

eth_sendRawTransaction

Creates a new message call transaction or a contract creation for signed transactions.

Alchemy does not store keys, so transactions sent via Alchemy must be signed ahead of time using another provider like ethers (via eth_signTransaction) and sent with eth_sendRawTransaction.

Parameters

DATA, The signed transaction data.

params: ["0xd46e8dd67c5d32be8d46e8dd67c5d32be8058bb8eb970870f072445675058bb8eb970870f072445675"]

Returns

DATA, 32 Bytes - the transaction hash, or the zero hash if the transaction is not yet available.

Use eth_getTransactionReceipt to get the contract address after the transaction was mined when you created a contract.

โ€‹Exampleโ€‹

Note: Since eth_sendRawTransaction is a request used for writing to the blockchain and changes its state, it is impossible to execute the same request twice. This means if you were to copy the example given below you will not get the expected response.

Request

Curl
Postman
Curl
curl https://eth-mainnet.alchemyapi.io/v2/your-api-key \
-X POST \
-H "Content-Type: application/json" \
-d '{"jsonrpc":"2.0","method":"eth_sendRawTransaction","params":["0xd46e8dd67c5d32be8d46e8dd67c5d32be8058bb8eb970870f072445675058bb8eb970870f072445675"],"id":1}'
Postman
URL: https://eth-mainnet.alchemyapi.io/v2/your-api-key
RequestType: POST
Body:
{
"jsonrpc":"2.0",
"method":"eth_sendRawTransaction",
"params":["0xd46e8dd67c5d32be8d46e8dd67c5d32be8058bb8eb970870f072445675058bb8eb970870f072445675"],
"id":1
}

Result

{
"id":1,
"jsonrpc": "2.0",
"result": "0xe670ec64341771606e55d6b4ca35a1a6b75ee3d5145a99d05921026d1527331"
}

โ€‹๐Ÿ“‚ Account Information

Calls to get information about an account.

eth_getBalance

Returns the balance of the account of a given address.

Parameters

  1. DATA, 20 Bytes - address to check for balance.

  2. QUANTITY|TAG - integer block number, or the string "latest", "earliest" or "pending", see the default block parameter.

params: [
'0xc94770007dda54cF92009BFF0dE90c06F603a09f',
'latest'
]

Returns

QUANTITY - integer of the current balance for the given address in wei.

โ€‹Exampleโ€‹

Request

Curl
Postman
Curl
curl https://eth-mainnet.alchemyapi.io/v2/your-api-key \
-X POST \
-H "Content-Type: application/json" \
-d '{"jsonrpc":"2.0","method":"eth_getBalance","params":["0xc94770007dda54cF92009BFF0dE90c06F603a09f", "latest"],"id":0}'
Postman
URL: https://eth-mainnet.alchemyapi.io/v2/your-api-key
RequestType: POST
Body:
{
"jsonrpc":"2.0",
"method":"eth_getBalance",
"params":["0xc94770007dda54cF92009BFF0dE90c06F603a09f", "latest"],
"id":0
}

Result

{
"jsonrpc": "2.0",
"id": 0,
"result": "0x7c2562030800"
}

eth_getCode

Returns code at a given address.

Parameters

  • DATA, 20 Bytes - address.

  • QUANTITY|TAG - integer block number, or the string "latest", "earliest" or "pending", see the default block parameter.

params: [
'0xb59f67a8bff5d8cd03f6ac17265c550ed8f33907',
'latest'
]

Returns

  • DATA - the code from the given address.

โ€‹Exampleโ€‹

Request

Curl
Postman
Curl
curl https://eth-mainnet.alchemyapi.io/v2/your-api-key \
-X POST \
-H "Content-Type: application/json" \
-d '{"jsonrpc":"2.0","method":"eth_getCode","params":["0xb59f67a8bff5d8cd03f6ac17265c550ed8f33907", "latest"],"id":0}'
Postman
URL: https://eth-mainnet.alchemyapi.io/v2/your-api-key
RequestType: POST
Body:
{
"jsonrpc":"2.0",
"method":"eth_getCode",
"params":["0xb59f67a8bff5d8cd03f6ac17265c550ed8f33907", "latest"],
"id":0
}

Result

{
"jsonrpc": "2.0",
"id": 0,
"result": "0x606060405236156100965763ffffffff7c010000000000000000000000000000000000000000000000000000000060003504166306fdde0381146100a557806313af40351461012f57806318160ddd1461014e578063313ce5671461017357806370a082311461019c57806375ad319a146101bb5780638da5cb5b146101ee57806395d89b411461021d578063a9059cbb14610230575b34156100a157600080fd5bfe5b005b34156100b057600080fd5b6100b8610252565b60405160208082528190810183818151815260200191508051906020019080838360005b838110156100f45780820151838201526020016100dc565b50505050905090810190601f1680156101215780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b341561013a57600080fd5b6100a3600160a060020a0360043516610289565b341561015957600080fd5b61016161030f565b60405190815260200160405180910390f35b341561017e57600080fd5b610186610315565b60405160ff909116815260200160405180910390f35b34156101a757600080fd5b610161600160a060020a036004351661031a565b34156101c657600080fd5b6101da600160a060020a0360043516610335565b604051901515815260200160405180910390f35b34156101f957600080fd5b61020161038e565b604051600160a060020a03909116815260200160405180910390f35b341561022857600080fd5b6100b861039d565b341561023b57600080fd5b6101da600160a060020a03600435166024356103d4565b60408051908101604052601881527f444f5420416c6c6f636174696f6e20496e64696361746f720000000000000000602082015281565b60005433600160a060020a039081169116146102a457600080fd5b600054600160a060020a0380831691167f70aea8d848e8a90fb7661b227dc522eb6395c3dac71b63cb59edd5c9899b236460405160405180910390a36000805473ffffffffffffffffffffffffffffffffffffffff1916600160a060020a0392909216919091179055565b60015481565b600381565b600160a060020a031660009081526002602052604090205490565b33600160a060020a03811660009081526002602052604081206001015490919060ff16151561036357600080fd5b5050600160a060020a031660009081526002602052604090206001908101805460ff19168217905590565b600054600160a060020a031681565b60408051908101604052600381527f444f540000000000000000000000000000000000000000000000000000000000602082015281565b33600160a060020a03811660009081526002602052604081205490919083908190101561040057600080fd5b33600160a060020a03811660009081526002602052604090206001015460ff16151561042b57600080fd5b85600160a060020a031633600160a060020a03167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef8760405190815260200160405180910390a3600160a060020a033381166000908152600260205260408082208054899003905591881681522080548601905560019350505050929150505600a165627a7a72305820228dfae3e67abcdc7f73fb3f83a7d23f45acd853774acad9d2e1ac83b940fbe90029"
}

eth_getStorageAt

Returns the value from a storage position at a given address, or in other words, returns the state of the contract's storage, which may not be exposed via the contract's methods.

Parameters

  • DATA, 20 Bytes - address of the storage.

  • QUANTITY - integer of the position in the storage.

  • QUANTITY|TAG - integer block number, or the string "latest", "earliest" or "pending", see the default block parameter.

Returns

  • DATA - the value at this storage position.

Example

Calculating the correct position depends on the storage to retrieve. Consider the following contract deployed at 0x295a70b2de5e3953354a6a8344e616ed314d7251 by address 0x391694e7e0b0cce554cb130d723a9d27458f9298.

contract Storage {
uint pos0;
mapping(address => uint) pos1;
โ€‹
function Storage() {
pos0 = 1234;
pos1[msg.sender] = 5678;
}
}

Retrieving the value of pos0 is straight forward:

โ€‹Requestโ€‹

Curl
Postman
Curl
curl https://eth-mainnet.alchemyapi.io/v2/your-api-key \
-X POST \
-H "Content-Type: application/json" \
-d '{"jsonrpc":"2.0", "method": "eth_getStorageAt", "params": ["0x295a70b2de5e3953354a6a8344e616ed314d7251", "0x0", "latest"], "id": 1}'
Postman
URL: https://eth-mainnet.alchemyapi.io/v2/your-api-key
RequestType: POST
Body:
{
"jsonrpc":"2.0",
"method":"eth_getStorageAt",
"params":["0x295a70b2de5e3953354a6a8344e616ed314d7251", "0x0", "latest"],
"id":1
}

Result

{
"jsonrpc":"2.0",
"id":1,
"result":"0x00000000000000000000000000000000000000000000000000000000000004d2"
}

Retrieving an element of the map is harder. The position of an element in the map is calculated with:

keccack(LeftPad32(key, 0), LeftPad32(map position, 0))

This means to retrieve the storage on pos1[โ€œ0x391694e7e0b0cce554cb130d723a9d27458f9298โ€] we need to calculate the position with:

keccak(decodeHex("000000000000000000000000391694e7e0b0cce554cb130d723a9d27458f9298" + "0000000000000000000000000000000000000000000000000000000000000001"))

The geth console which comes with the web3 library can be used to make the calculation:

> var key = "000000000000000000000000391694e7e0b0cce554cb130d723a9d27458f9298" + "0000000000000000000000000000000000000000000000000000000000000001"
undefined
> web3.sha3(key, {"encoding": "hex"})
"0x6661e9d6d8b923d5bbaab1b96e1dd51ff6ea2a93520fdc9eb75d059238b8c5e9"

Now to fetch the storage:

โ€‹Requestโ€‹

Curl
Postman
Curl
curl https://eth-mainnet.alchemyapi.io/v2/your-api-key \
-X POST \
-H "Content-Type: application/json" \
-d '{"jsonrpc":"2.0", "method": "eth_getStorageAt", "params": ["0x295a70b2de5e3953354a6a8344e616ed314d7251", "0x6661e9d6d8b923d5bbaab1b96e1dd51ff6ea2a93520fdc9eb75d059238b8c5e9", "latest"], "id": 1}'
Postman
URL: https://eth-mainnet.alchemyapi.io/v2/your-api-key
RequestType: POST
Body:
{
"jsonrpc":"2.0",
"method":"eth_getStorageAt",
"params":["0x295a70b2de5e3953354a6a8344e616ed314d7251", "0x6661e9d6d8b923d5bbaab1b96e1dd51ff6ea2a93520fdc9eb75d059238b8c5e9", "latest"],
"id":1
}

Result

{
"jsonrpc":"2.0",
"id":1,
"result":"0x000000000000000000000000000000000000000000000000000000000000162e"
}

eth_accounts

Returns a list of addresses owned by client.

Since Alchemy does not store keys, this will always return empty.

Parameters

none

Returns

Array of DATA, 20 Bytes - addresses owned by the client.

โ€‹Exampleโ€‹

Request

Curl
Postman
Curl
curl https://eth-mainnet.alchemyapi.io/v2/your-api-key \
-X POST \
-H "Content-Type: application/json" \
-d '{"jsonrpc":"2.0","method":"eth_accounts","params":[],"id":1}'
Postman
URL: https://eth-mainnet.alchemyapi.io/v2/your-api-key
RequestType: POST
Body:
{
"jsonrpc":"2.0",
"method":"eth_accounts",
"params":[],
"id":1
}

Result

{
"id":1,
"jsonrpc": "2.0",
"result": []
}

eth_getProof

Returns the account and storage values of the specified account including the Merkle-proof. This call can be used to verify that the data you are pulling from is not tampered with.

Parameters

  1. DATA, 20 Bytes - address of the account.

  2. ARRAY, 32 Bytes - array of storage-keys which should be proofed and included. Seeeth_getStorageAtโ€‹

  3. QUANTITY|TAG - integer block number, or the string "latest" or "earliest", see the default block parameterโ€‹

Returns

Object - A account object:

  • balance: QUANTITY - the balance of the account. Seeeth_getBalanceโ€‹

  • codeHash: DATA, 32 Bytes - hash of the code of the account. For a simple Account without code it will return "0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470"

  • nonce: QUANTITY, - nonce of the account. See eth_getTransactionCountโ€‹

  • storageHash: DATA, 32 Bytes - SHA3 of the StorageRoot. All storage will deliver a MerkleProof starting with this rootHash.

  • accountProof: ARRAY - Array of rlp-serialized MerkleTree-Nodes, starting with the stateRoot-Node, following the path of the SHA3 (address) as key.

  • storageProof: ARRAY - Array of storage-entries as requested. Each entry is a object with these properties:

    • key: QUANTITY - the requested storage key

    • value: QUANTITY - the storage value

    • proof: ARRAY - Array of rlp-serialized MerkleTree-Nodes, starting with the storageHash-Node, following the path of the SHA3 (key) as path.

Example

Request

Curl
Postman
Curl
curl https://eth-mainnet.alchemyapi.io/v2/your-api-key \
-X POST \
-H "Content-Type: application/json" \
-d '{"jsonrpc":"2.0","method":"eth_getProof","params":["0x7F0d15C7FAae65896648C8273B6d7E43f58Fa842",["0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421"],"latest"],"id":1}'
Postman
URL: https://eth-mainnet.alchemyapi.io/v2/your-api-key
RequestType: POST
Body:
{
"jsonrpc":"2.0",
"method":"eth_getProof",
"params":["0x7F0d15C7FAae65896648C8273B6d7E43f58Fa842",["0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421"],"latest"],
"id":1
}

Result

{
"id": 1,
"jsonrpc": "2.0",
"result": {
"accountProof": [
"0xf90211a...0701bc80",
"0xf90211a...0d832380",
"0xf90211a...5fb20c80",
"0xf90211a...0675b80",
"0xf90151a0...ca08080"
],
"balance": "0x0",
"codeHash": "0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470",
"nonce": "0x0",
"storageHash": "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421",
"storageProof": [
{
"key": "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421",
"proof": [
"0xf90211a...0701bc80",
"0xf90211a...0d832380"
],
"value": "0x1"
}
]
}
}

โ€‹๐Ÿง  EVM/Smart Contract Execution

eth_call

Executes a new message call immediately without creating a transaction on the block chain.

This is one of the most commonly used API calls. It is used to read from the blockchain which includes executing smart contracts, but does not publish anything to the blockchain. This call does not consume any Ether.

Starting from Geth 1.9.13, eth_callwill check the balance of the sender (to make sure that the sender has enough gas to complete the request) before executing the call. This means that even though the call doesn't consume any gas, the from address must have enough gas to execute the call as if it were a transaction.

Parameters

  • Object - The transaction call object

    • from: DATA, 20 Bytes - (optional) The address the transaction is sent from.

    • to: DATA, 20 Bytes - The address the transaction is directed to.

    • gas: QUANTITY - (optional) Integer of the gas provided for the transaction execution. eth_call consumes zero gas, but this parameter may be needed by some executions.

    • gasPrice: QUANTITY - (optional) Integer of the gasPrice used for each paid gas. Note: most of our users (95%+) never set the gasPrice on eth_call.

    • value: QUANTITY - (optional) Integer of the value sent with this transaction

    • data: DATA - (optional) Hash of the method signature and encoded parameters. For details see Ethereum Contract ABI

  • QUANTITY|TAG - integer block number, or the string "latest", "earliest" or "pending", see the default block parameter.

params: [
{
"from": "0xb60e8dd61c5d32be8058bb8eb970870f07233155",
"to": "0xd46e8dd67c5d32be8058bb8eb970870f07244567",
"gas": "0x76c0",
"gasPrice": "0x9184e72a000",
"value": "0x9184e72a",
"data": "0xd46e8dd67c5d32be8d46e8dd67c5d32be8058bb8eb970870f072445675058bb8eb970870f072445675"
},
"latest"]
]

Returns

DATA - the return value of executed contract.

โ€‹Exampleโ€‹

Note: the below example result cannot be replicated.

Request

Curl
Postman
Curl
curl https://eth-mainnet.alchemyapi.io/v2/your-api-key \
-X POST \
-H "Content-Type: application/json" \
-d '{"jsonrpc":"2.0","method":"eth_call","params":[{"from": "0xb60e8dd61c5d32be8058bb8eb970870f07233155","to": "0xd46e8dd67c5d32be8058bb8eb970870f07244567","gas": "0x76c0","gasPrice": "0x9184e72a000","value": "0x9184e72a","data": "0xd46e8dd67c5d32be8d46e8dd67c5d32be8058bb8eb970870f072445675058bb8eb970870f072445675"}, "latest"],"id":1}'
Postman
URL: https://eth-mainnet.alchemyapi.io/v2/your-api-key
RequestType: POST
Body:
{
"jsonrpc":"2.0",
"method":"eth_call",
"params":[{"from": "0xb60e8dd61c5d32be8058bb8eb970870f07233155","to": "0xd46e8dd67c5d32be8058bb8eb970870f07244567","gas": "0x76c0","gasPrice": "0x9184e72a000","value": "0x9184e72a","data": "0xd46e8dd67c5d32be8d46e8dd67c5d32be8058bb8eb970870f072445675058bb8eb970870f072445675"}, "latest"],
"id":1
}

Result

{
"jsonrpc": "2.0",
"id": 1,
"result": "0x"
}

โ€‹๐Ÿ“‘ Event Logs

eth_getLogs

Returns an array of all logs matching a given filter object. For more information about eth_getLogs check out our Deep Dive into eth_getLogs page.

NOTE: You can make eth_getLogs requests with up to a 2K block range and no limit on the response size. You can also request any block range with a cap of 10K logs in the response.

If you need to pull logs frequently, we recommend using WebSockets to push new logs to you when they are available.

Parameters

Object - The filter options:

  • fromBlock: QUANTITY|TAG - (optional, default: "latest") Value:

    • Integer block number

    • "latest" for the last mined block

    • "pending", "earliest" for not yet mined transactions.

  • toBlock: QUANTITY|TAG - (optional, default: "latest") Value:

    • Integer block number

    • "latest" for the last mined block

    • "pending", "earliest" for not yet mined transactions.

  • address: DATA|Array, 20 Bytes - (optional) Contract address or a list of addresses from which logs should originate.

  • topics: Array of DATA, - (optional) Array of 32 Bytes DATA topics.

    • Topics are order-dependent. Each topic can also be an array of DATA with "or" options.

    • Check out more details on how to format topics in eth_newFilter.

  • blockhash: DATA, 32 Bytes - (optional) With the addition of EIP-234 (Geth >= v1.8.13 or Parity >= v2.1.0), blockHash is a new filter option which restricts the logs returned to the single block with the 32-byte hash blockHash. Using blockHash is equivalent to fromBlock = toBlock = the block number with hash blockHash. If blockHash is present in the filter criteria, then neither fromBlock nor toBlock are allowed.

params: [
{
"address": "0xb59f67a8bff5d8cd03f6ac17265c550ed8f33907",
"topics": [
"0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef"
],
"blockHash": "0x8243343df08b9751f5ca0c5f8c9c0460d8a9b6351066fae0acbd4d3e776de8bb"
}
]

Returns

See eth_getFilterChangesโ€‹

โ€‹Exampleโ€‹

Request

Curl
Postman
Curl
curl https://eth-mainnet.alchemyapi.io/v2/your-api-key \
-X POST \
-H "Content-Type: application/json" \
-d '{"jsonrpc":"2.0","method":"eth_getLogs","params":[{"address": "0xb59f67a8bff5d8cd03f6ac17265c550ed8f33907","topics": ["0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef"],"blockHash": "0x8243343df08b9751f5ca0c5f8c9c0460d8a9b6351066fae0acbd4d3e776de8bb"}],"id":0}'
Postman
URL: https://eth-mainnet.alchemyapi.io/v2/your-api-key
RequestType: POST
Body:
{
"jsonrpc":"2.0",
"method":"eth_getLogs",
"params":[{"topics":[{"address": "0xb59f67a8bff5d8cd03f6ac17265c550ed8f33907","topics": ["0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef"],"blockHash": "0x8243343df08b9751f5ca0c5f8c9c0460d8a9b6351066fae0acbd4d3e776de8bb"}],
"id":0
}

Result

{
"jsonrpc": "2.0",
"id": 0,
"result": [
{
"address": "0xb59f67a8bff5d8cd03f6ac17265c550ed8f33907",
"topics": [
"0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef",
"0x00000000000000000000000000b46c2526e227482e2ebb8f4c69e4674d262e75",
"0x00000000000000000000000054a2d42a40f51259dedd1978f6c118a0f0eff078"
],
"data": "0x000000000000000000000000000000000000000000000000000000012a05f200",
"blockNumber": "0x429d3b",
"transactionHash": "0xab059a62e22e230fe0f56d8555340a29b2e9532360368f810595453f6fdd213b",
"transactionIndex": "0xac",
"blockHash": "0x8243343df08b9751f5ca0c5f8c9c0460d8a9b6351066fae0acbd4d3e776de8bb",
"logIndex": "0x56",
"removed": false
}
]
}

โ€‹โ›“ Chain Information

Calls to receive information about the current blockchain.

eth_protocolVersion

Returns the current ethereum protocol version.

Parameters

none

Returns

String - The current ethereum protocol version.

โ€‹Exampleโ€‹

Request

Curl
Postman
Curl
curl https://eth-mainnet.alchemyapi.io/v2/your-api-key \
-X POST \
-H "Content-Type: application/json" \
-d '{"jsonrpc":"2.0","method":"eth_protocolVersion","params":[],"id":0}'
Postman
URL: https://eth-mainnet.alchemyapi.io/v2/your-api-key
RequestType: POST
Body:
{
"jsonrpc":"2.0",
"method":"eth_protocolVersion",
"params":[]
"id":0
}

Result

{
"jsonrpc": "2.0",
"id": 0,
"result": "0x40"
}

eth_gasPrice

Returns the current price per gas in wei.

If you are curious about the difference in gas price between this method and the eth gas station, check out this GitHub issue.

Parameters

none

Returns

QUANTITY - integer of the current gas price in wei.

โ€‹Exampleโ€‹

Request

Curl
Postman
Curl
curl https://eth-mainnet.alchemyapi.io/v2/your-api-key \
-X POST \
-H "Content-Type: application/json" \
-d '{"jsonrpc":"2.0","method":"eth_gasPrice","params":[],"id":0}'
Postman
URL: https://eth-mainnet.alchemyapi.io/v2/your-api-key
RequestType: POST
Body:
{
"jsonrpc":"2.0",
"method":"eth_gasPrice",
"params":[],
"id":0
}

Result

{
"jsonrpc": "2.0",
"id": 0,
"result": "0x98bca5a00"
}

eth_estimateGas

Generates and returns an estimate of how much gas is necessary to allow the transaction to complete. The transaction will not be added to the blockchain.

Note: The estimate may be significantly more than the amount of gas actually used by the transaction, for a variety of reasons including EVM mechanics and node performance. Estimates are served directly from nodes, we're not doing anything special to the value so the rest of the network is likely seeing the same.

Parameters

  • Object - The transaction call object

    • from: DATA, 20 Bytes - (optional) The address the transaction is sent from.

    • to: DATA, 20 Bytes - The address the transaction is directed to.

    • gas: QUANTITY - (optional) Integer of the gas provided for the transaction execution. eth_call consumes zero gas, but this parameter may be needed by some executions.

    • gasPrice: QUANTITY - (optional) Integer of the gasPrice used for each paid gas. Note: most of our users (95%+) never set the gasPrice on eth_call.

    • value: QUANTITY - (optional) Integer of the value sent with this transaction

    • data: DATA - (optional) Hash of the method signature and encoded parameters. For details see Ethereum Contract ABI

  • QUANTITY|TAG - integer block number, or the string "latest", "earliest" or "pending", see the default block parameter.

Note: If no gas limit is specified geth uses the block gas limit from the pending block as an upper bound. As a result the returned estimate might not be enough to executed the call/transaction when the amount of gas is higher than the pending block gas limit.

Returns

QUANTITY - the amount of gas used.

โ€‹Exampleโ€‹

Request

Curl
Postman
Curl
curl https://eth-mainnet.alchemyapi.io/v2/your-api-key \
-X POST \
-H "Content-Type: application/json" \
-d '{"jsonrpc":"2.0","method":"eth_estimateGas","params":[{see above}],"id":1}'
Postman
URL: https://eth-mainnet.alchemyapi.io/v2/your-api-key
RequestType: POST
Body:
{
"jsonrpc":"2.0",
"method":"eth_estimateGas",
"params":[{see above}],
"id":1
}

Result

{
"id":1,
"jsonrpc": "2.0",
"result": "0x5208" // 21000
}

eth_chainId

Returns the currently configured chain ID, a value used in replay-protected transaction signing as introduced by EIP-155.

The chain ID returned should always correspond to the information in the current known head block. This ensures that caller of this RPC method can always use the retrieved information to sign transactions built on top of the head.

If the current known head block does not specify a chain ID, the client should treat any calls to eth_chainId as though the method were not supported, and return a suitable error.

You should prefer eth_chainId over net_version, so that you can reliably identify the chain you are communicating with.

Parameters

None.

Returns

QUANTITY - integer of the current chain ID.

Example

Request

Curl
Postman
Curl
curl https://eth-mainnet.alchemyapi.io/v2/your-api-key \
-X POST \
-H "Content-Type: application/json" \
-d '{"jsonrpc":"2.0","method":"eth_chainId","params":[],"id":83}'
Postman
URL: https://eth-mainnet.alchemyapi.io/v2/your-api-key
RequestType: POST
Body:
{
"jsonrpc":"2.0",
"method":"eth_chainId",
"params":[],
"id":83
}

Result

{
"id": 83,
"jsonrpc": "2.0",
"result": "0x3d" // 61
}

net_version

Returns the current network id.

Parameters

none

Returns

String - The current network id.

  • "1": Ethereum Mainnet

  • "2": Morden Testnet (deprecated)

  • "3": Ropsten Testnet

  • "4": Rinkeby Testnet

  • "42": Kovan Testnet

โ€‹Exampleโ€‹

Request

Curl
Postman
Curl
curl https://eth-mainnet.alchemyapi.io/v2/your-api-key \
-X POST \
-H "Content-Type: application/json" \
-d '{"jsonrpc":"2.0","method":"net_version","params":[],"id":67}'
Postman
URL: https://eth-mainnet.alchemyapi.io/v2/your-api-key
RequestType: POST
Body:
{
"jsonrpc":"2.0",
"method":"net_version",
"params":[],
"id":67
}

Result

{
"id":67,
"jsonrpc": "2.0",
"result": "3"
}

net_listening

Returns true if client is actively listening for network connections.

Parameters

none

Returns

Boolean - true when listening, otherwise false.

โ€‹Exampleโ€‹

Request

Curl
Postman
Curl
curl https://eth-mainnet.alchemyapi.io/v2/your-api-key \
-X POST \
-H "Content-Type: application/json" \
-d '{"jsonrpc":"2.0","method":"net_listening","params":[],"id":67}'
Postman
URL: https://eth-mainnet.alchemyapi.io/v2/your-api-key
RequestType: POST
Body:
{
"jsonrpc":"2.0",
"method":"net_listening",
"params":[],
"id":67
}

Result

{
"id":67,
"jsonrpc":"2.0",
"result":true
}

โ€‹๐Ÿง” Retrieving Uncles

Calls to get information about uncles.

Note: An uncle doesn't contain individual transactions.

eth_getUncleByBlockNumberAndIndex

Returns information about an uncle of a block by number and uncle index position.

Parameters

  • QUANTITY|TAG - a block number, or the string "earliest", "latest" or "pending", as in the default block parameter.

  • QUANTITY - the uncle's index position.

params: [
'0x29c', // 668
'0x0' // 0
]

Returns

See eth_getBlockByHash

โ€‹Exampleโ€‹

Request

Curl
Postman
Curl
curl https://eth-mainnet.alchemyapi.io/v2/your-api-key \
-X POST \
-H "Content-Type: application/json" \
-d '{"jsonrpc":"2.0","method":"eth_getUncleByBlockNumberAndIndex","params":["0x29c", "0x0"],"id":0}'
Postman
URL: https://eth-mainnet.alchemyapi.io/v2/your-api-key
RequestType: POST
Body:
{
"jsonrpc":"2.0",
"method":"eth_getUncleByBlockNumberAndIndex",
"params":["0x29c", "0x0"],
"id":0
}

Result

{
"jsonrpc": "2.0",
"id": 0,
"result": {
"difficulty": "0x57f117f5c",
"extraData": "0x476574682f76312e302e302f77696e646f77732f676f312e342e32",
"gasLimit": "0x1388",
"gasUsed": "0x0",
"hash": "0x932bdf904546a2287a2c9b2ede37925f698a7657484b172d4e5184f80bdd464d",
"logsBloom": "0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
"miner": "0x5bf5e9cf9b456d6591073513de7fd69a9bef04bc",
"mixHash": "0x4500aa4ee2b3044a155252e35273770edeb2ab6f8cb19ca8e732771484462169",
"nonce": "0x24732773618192ac",
"number": "0x299",
"parentHash": "0xa779859b1ee558258b7008bbabff272280136c5dd3eb3ea3bfa8f6ae03bf91e5",
"receiptsRoot": "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421",
"sha3Uncles": "0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347",
"size": "0x21d",
"stateRoot": "0x2604fbf5183f5360da249b51f1b9f1e0f315d2ff3ffa1a4143ff221ad9ca1fec",
"timestamp": "0x55ba4827",
"transactionsRoot": "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421",
"uncles": []
}
}

eth_getUncleByBlockHashAndIndex

Returns information about an uncle of a block by hash and uncle index position.

Parameters

  • QUANTITY|TAG - a block number, or the string "earliest", "latest" or "pending", as in the

    โ€‹default block parameter.

  • QUANTITY - the uncle's index position.

params: [
'0xb3b20624f8f0f86eb50dd04688409e5cea4bd02d700bf6e79e9384d47d6a5a35',
'0x0' // 0
]

Returns

See eth_getBlockByHash

โ€‹Exampleโ€‹

Request

Curl
Postman
Curl
curl https://eth-mainnet.alchemyapi.io/v2/your-api-key \
-X POST \
-H "Content-Type: application/json" \
-d '{"jsonrpc":"2.0","method":"eth_getUncleByBlockHashAndIndex","params":["0xb3b20624f8f0f86eb50dd04688409e5cea4bd02d700bf6e79e9384d47d6a5a35", "0x0"],"id":0}'
Postman
URL: https://eth-mainnet.alchemyapi.io/v2/your-api-key
RequestType: POST
Body:
{
"jsonrpc":"2.0",
"method":"eth_getUncleByBlockHashAndIndex",
"params":["0xb3b20624f8f0f86eb50dd04688409e5cea4bd02d700bf6e79e9384d47d6a5a35", "0x0"],
"id":0
}

Result

{
"jsonrpc": "2.0",
"id": 0,
"result": {
"difficulty": "0xbf93da424b943",
"extraData": "0x65746865726d696e652d657539",
"gasLimit": "0x7a121d",
"gasUsed": "0x79ea62",
"hash": "0x824cce7c7c2ec6874b9fa9a9a898eb5f27cbaf3991dfa81084c3af60d1db618c",
"logsBloom": "0x0948432021200401804810002000000000381001001202440000010020000080a016262050e44850268052000400100505022305a64000054004200b0c04110000080c1055c42001054b804940a0401401008a00112d80082113400c10006580140005011a40220020000010001c0a00082300434002000050840010102082801c2000148540201004491814020480080111a0300600000003800640024200109c00202010044000880000106810a1a010000028a0100000422000140011000050a2a44b3080001060800000540c108102102600d000004730404a880100600021080100403000180000062642408b440060590400080101e046f08000000430",
"miner": "0xea674fdde714fd979de3edf0f56aa9716b898ec8",
"mixHash": "0x0b15fe0a9aa789c167b0f5ade7b72969d9f2193014cb4e98382254f60ffb2f4a",
"nonce": "0xa212d6400b89b3f6",
"number": "0x5bad54",
"parentHash": "0x05e19fb68d9ec798073808e8b3170875cb327d4b6cde7d6f60fe194677bb26fd",
"receiptsRoot": "0x90807b32c4aa4610c57289de57fa68ba50ed53f14dd2c25f1862aa049029dcd6",
"sha3Uncles": "0xf763576c1ea6a8c61a206e16b1a2451bec5cba1c7545d7ff733a1e8c78715569",
"size": "0x216",
"stateRoot": "0xebc7a1603bfffe0a14bdb89f898e2f2824abb40f04579beb7b920c56d6e273c9",
"timestamp": "0x5b54143f",
"transactionsRoot": "0x7562cba41e067b364b933e7b566fb2444f6954fef3964a5a487d4cd79d97a56c",
"uncles": []
}
}

eth_getUncleCountByBlockHash

Returns the number of uncles in a block matching the given block hash.

Parameters

  • DATA, 32 Bytes - hash of a block.

params: [
'0xb3b20624f8f0f86eb50dd04688409e5cea4bd02d700bf6e79e9384d47d6a5a35'
]

Returns

QUANTITY - integer of the number of uncles in this block.

โ€‹Exampleโ€‹

Request

Curl
Postman
Curl
curl https://eth-mainnet.alchemyapi.io/v2/your-api-key \
-X POST \
-H "Content-Type: application/json" \
-d '{"jsonrpc":"2.0","method":"eth_getUncleCountByBlockHash","params":["0xb3b20624f8f0f86eb50dd04688409e5cea4bd02d700bf6e79e9384d47d6a5a35"],"id":0}'
Postman
URL: https://eth-mainnet.alchemyapi.io/v2/your-api-key
RequestType: POST
Body:
{
"jsonrpc":"2.0",
"method":"eth_getUncleCountByBlockHash",
"params":["0xb3b20624f8f0f86eb50dd04688409e5cea4bd02d700bf6e79e9384d47d6a5a35"],
"id":0
}

Result

{
"jsonrpc": "2.0",
"id": 0,
"result": "0x1"
}

eth_getUncleCountByBlockNumber

Returns the number of uncles in a block matching the give block number.

Parameters

QUANTITY|TAG - integer of a block number, or the string "latest", "earliest" or "pending", see the default block parameter.

params: [
'0xe8', // 232
]

Returns

QUANTITY - integer of the number of uncles in this block.

โ€‹Exampleโ€‹

Request

Curl
Postman
Curl
curl https://eth-mainnet.alchemyapi.io/v2/your-api-key \
-X POST \
-H "Content-Type: application/json" \
-d '{"jsonrpc":"2.0","method":"eth_getUncleCountByBlockNumber","params":["0xe8"],"id":1}'
Postman
URL: https://eth-mainnet.alchemyapi.io/v2/your-api-key
RequestType: POST
Body:
{
"jsonrpc":"2.0",
"method":"eth_getUncleCountByBlockNumber",
"params":["0xe8"],
"id":1
}

Result

{
"jsonrpc": "2.0",
"id": 0,
"result": "0x0"
}

โ€‹๐Ÿ”ฆ Filters

Calls related to creating, getting, and reading from filters.

Eth filters expose the same information as the eth_subscribe methods, except that updates are received by polling rather than receiving pushes. A user may create a filter than repeatedly call eth_getFilterChangeson it, each time receiving events that have occurred since the last time eth_getFilterChangeswas called (or since the filter was created if this is the first time eth_getFilterChangesis being called.

Note: Filters expire after 5 minutes of inactivity, so several of the example requests below will return"filter not found" if you try and call them.

eth_getFilterChanges

Polling method for a filter, which returns an array of logs which occurred since last poll.

Parameters

  1. QUANTITY - the filter id.

params: [
"0xfe704947a3cd3ca12541458a4321c869"
]

Returns

Array - Array of log objects, or an empty array if nothing has changed since last poll.

  • For filters created with eth_newBlockFilter the return are block hashes (DATA, 32 Bytes), e.g. ["0x3454645634534..."].

  • For filters created with eth_newPendingTransactionFilter the return are transaction hashes (DATA, 32 Bytes), e.g. ["0x6345343454645..."].

  • For filters created with eth_newFilter logs are objects with following params:

    • removed: TAG - true when the log was removed, due to a chain reorganization. false if its a valid log.

    • logIndex: QUANTITY - integer of the log index position in the block. null when its pending log.

    • transactionIndex: QUANTITY - integer of the transactions index position log was created from. null when its pending log.

    • transactionHash: DATA, 32 Bytes - hash of the transactions this log was created from. null when its pending log.

    • blockHash: DATA, 32 Bytes - hash of the block where this log was in. null when its pending. null when its pending log.

    • blockNumber: QUANTITY - the block number where this log was in. null when its pending. null when its pending log.