Polygon API

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

For more information on Polygon's API check out the official documentation.

NOTE: Not all standard Ethereum methods are supported by Polygon. Likewise, not all Polygon methods are currently supported on Alchemy. For the full list of supported Polygon methods, check out the official documentation.

Mainnet vs. Testnet

There are two networks on Polygon: Mainnet and Mumbai testnet. The endpoints are as follows:

  • Mainnet: https://polygon-mainnet.g.alchemy.com/v2/your-api-key

  • Mumbai: https://polygon-mumbai.g.alchemy.com/v2/your-api-key

β€‹πŸ“¦ Retrieving Block

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.

Request

Curl
Postman
Curl
curl https://polygon-mainnet.g.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://polygon-mainnet.g.alchemyapi.io/v2/your-api-key
RequestType: POST
Body:
{
"jsonrpc":"2.0",
"method":"eth_blockNumber",
"params":[],
"id":0
}

Result

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

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.

Request

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

Result

{
"jsonrpc": "2.0",
"id": 0,
"result": {
"difficulty": "0x13",
"extraData": "0xd783010a0383626f7288676f312e31352e35856c696e7578000000000000000029adbbaf99a3f97b2baefa11e865cf9d74435716ef8618caaa388619f5ae7d8e5d2cadab0cd2f5becd4ebf7d48f5584c9e414c2a4a6ea2bc6ea8f02dbf5675cd01",
"gasLimit": "0x1385aa8",
"gasUsed": "0x1380a56",
"hash": "0xe2885b25d0863ce4df48facee18d5dd4b4be7366abc59133c2de66ab57d7b71e",
"logsBloom": "0x3eb4221d73001e540126a703d8666026b3480983cccc083c04ba806267cc27149835341b440290711abcd3188b4c1da12b84cd48131caa0860a6c1d136bebe8a89918c04184b6e00827328c802a23ca738981432097c0300823b0d34d0d0c6c4682508ecdaf0b4190deb480c4b5a9ca01db86eacca08c5f1d7d0d2f6245c099a010967474dcab60810d55c224564a88b0b29fcdba123000a78643a750604e002f68930330062607a9eaa05ca59a60a4e4449de00f2bb86708121d1093ac8415b18048416334214e80491cc6613434e0272df878498eab4320239d4d77881fbc433d0ca83051d010128102226cd58a248cb008e2240fcd658148169358e502d53",
"miner": "0x0000000000000000000000000000000000000000",
"mixHash": "0x0000000000000000000000000000000000000000000000000000000000000000",
"nonce": "0x0000000000000000",
"number": "0xf93d47",
"parentHash": "0x745ffd6d21e961040b0821f93be0f9533d2f01f87289abe78af4d8052a4c5528",
"receiptsRoot": "0xc9cb68ece0290f11a0c3e96e8c7ef52bc0b7a6f0543360c4967400750c2ea23f",
"sha3Uncles": "0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347",
"size": "0xf747",
"stateRoot": "0xdd45900534469c5fcbf7b9ac3a56639e2ff6821500804347a5b9332bfa880813",
"timestamp": "0x60dcae89",
"totalDifficulty": "0xa4be87e",
"transactions": [
{
"blockHash": "0xe2885b25d0863ce4df48facee18d5dd4b4be7366abc59133c2de66ab57d7b71e",
"blockNumber": "0xf93d47",
"from": "0x8a18a2fee7dc9c2002e21fda8c10f0feb0abf05e",
"gas": "0x61899",
"gasPrice": "0x17a27db936",
"hash": "0x78f825c7d0c09709b82a54b170887d000c58408725cd8d44d10df3382fc5fa1c",
"input": "0xf98a9e410000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000007b0900000000000000f5a20b000000002791bca1f2de4661ed88a30c99a7a9449aa841741e00f38a214f0f8c02b5b1f5b93fe646a4390e842a2d1e014395bb4d53f0f9fe088a7b1a0c2924e4eab7712f1e01d4deec3fd8578887ba3cd6549e188307033600d91e01f36ad6a25ed157b896ce5178ffd82ee6203d760d0000000000",
"nonce": "0xa9ee",
"to": "0xeee49495242da9e0bdbe29a7098388cea8348de4",
"transactionIndex": "0x0",
"value": "0x0",
"type": "0x0",
"v": "0x136",
"r": "0x8aa119caab9667a1cad06f6fdaf1d01ee80b3c50cf5b53a71dcaff557dfb9b24",
"s": "0x305482180355f212cad7a07fda4ce4e1832f1c3013316b660c647f3e5f8c231b"
}
...
],
"transactionsRoot": "0xe3394943ac8e86ee3f0112719f1f4e9eb229b7221792a4279c2bdb390bce1ba3",
"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​

Request

Curl
Postman
Curl
curl https://polygon-mainnet.g.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://polygon-mainnet.g.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": {
"difficulty": "0x7",
"extraData": "0xd58301090083626f7286676f312e3133856c696e757800000000000000000000e14198dde4da0ea1015e9d38ad288f5ba62cf8d1b9a98ccd02fb6f75553ee51c70caa1c376cf4a937c644cae060effe8bf25409cef9ecd25013a608b3a51cbef00",
"gasLimit": "0xe984c2",
"gasUsed": "0x0",
"hash": "0xa284f649d7d9a3c0dea48e3bf3d295767a4893902e61d27e1590d4cece691b6f",
"logsBloom": "0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
"miner": "0x0000000000000000000000000000000000000000",
"mixHash": "0x0000000000000000000000000000000000000000000000000000000000000000",
"nonce": "0x0000000000000000",
"number": "0x1b4",
"parentHash": "0x9481d3bb2bbe842f0e4703cb5be094d95650fe8345b4da5642ed27bec3acd0d5",
"receiptsRoot": "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421",
"sha3Uncles": "0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347",
"size": "0x260",
"stateRoot": "0x01b797385461764bd56336dd5e810f3d57529d47bcbf3260c7d9c770bf6c5af4",
"timestamp": "0x5ed28d86",
"totalDifficulty": "0xbed",
"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: [
"0x4ec492e0ba174ddca1324e9867c4e4c10a6eca6a1f77b56a19de875ae869b195"
]

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

Request

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

Result

{
"jsonrpc": "2.0",
"id": 0,
"result": {
"blockHash": "0xb5acef6bbf84c1c0ec7a5009757e3a09ee25ec129b564d11fb976ce75f426c59",
"blockNumber": "0xd7b488",
"from": "0x7b5fc677cf27a807adf2ebcef72db3b935df6c0a",
"gas": "0xb352c",
"gasPrice": "0x9502f900",
"hash": "0x4ec492e0ba174ddca1324e9867c4e4c10a6eca6a1f77b56a19de875ae869b195",
"input": "0x405cec6700000000000000000000000024cf788254bb130bacb6ff519ef875b1d4b0008e000000000000000000000000ab45c5a4b0c941a2f231c04c3f49182e1a25405200000000000000000000000000000000000000000000000000000000000001200000000000000000000000000000000000000000000000000000000000000046000000000000000000000000000000000000000000000000000000009502f900000000000000000000000000000000000000000000000000000000000004ffa0000000000000000000000000000000000000000000000000000000000000104f0000000000000000000000000000000000000000000000000000000000000400000000000000000000000000000000000000000000000000000000000000048000000000000000000000000000000000000000000000000000000000000002a434ee9791000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000040000000000000000000000000000000000000000000000000000000000000014000000000000000000000000000000000000000000000000000000000000000010000000000000000000000002791bca1f2de4661ed88a30c99a7a9449aa84174000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000800000000000000000000000000000000000000000000000000000000000000044095ea7b3000000000000000000000000750fd34fbb97abe5492338a3918552291a799ca0000000000000000000000000000000000000000000000000000000002114a0c0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001000000000000000000000000750fd34fbb97abe5492338a3918552291a799ca000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000080000000000000000000000000000000000000000000000000000000000000006440993b26000000000000000000000000000000000000000000000000000000002114a0c00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000005fd8004400000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000041dc112fa5131cb8f424321830c246c7aec27a5f86968d6eaace1926600716676633ec1f49b2d2eaea0ba7c10d9d97922f13e92002ab2e0610fc17d6ff3e4c60761b000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
"nonce": "0x3059e",
"to": "0xd216153c06e857cd7f72665e0af1d7d82172f494",
"transactionIndex": "0x4",
"value": "0x0",
"type": "0x0",
"v": "0x1c",
"r": "0x39aeddb2b67676e65e7d6f43fd57c731e17534fcfea0eb40d37be1224a8bb8f0",
"s": "0x284defe0787533fc62c637acd2d9e89b2609350c1c26fd4dbb5386242e85a795"
}
}

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: [
'0x0e11795884b28b08f9978bb85938280967cda041',
'latest' // state at the latest block
]

Returns

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

Request

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

Result

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

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: [
'0x9ee9891518b06f4b5bf76a4bef4ba6d93e8d38a17b7aaad492f5555865da7dbb'
]

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)

Request

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

Result

{
"jsonrpc": "2.0",
"id": 0,
"result": {
"blockHash": "0x6357724a8ccd4dc6f175267395466c005be8ca70f1a67d2232774e8b0fb968ae",
"blockNumber": "0xf8ff26",
"contractAddress": null,
"cumulativeGasUsed": "0x24cf9c",
"from": "0x0e11795884b28b08f9978bb85938280967cda041",
"gasUsed": "0x303ab",
"logs": [
{
"address": "0x4d97dcd97ec945f40cf65f87097ace5ea0476045",
"topics": [
"0x4a39dc06d4c0dbc64b70af90fd698a233a518aa5d07e595d983b8c0526c8f7fb",
"0x000000000000000000000000cf5cea15e49b33b70a0bef2d42a46425c54c80a1",
"0x000000000000000000000000cf5cea15e49b33b70a0bef2d42a46425c54c80a1",
"0x0000000000000000000000000000000000000000000000000000000000000000"
],
"data": "0x000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000a00000000000000000000000000000000000000000000000000000000000000002cb4e96cda2b16481b25e3d2b2cab2bd5c74e15de2495d5f78aa3b3fab67f94b87815b4e593d58ca91f171be3dd89ee2005a61df0a00445b8411dda6564c36ed0000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000067d109f00000000000000000000000000000000000000000000000000000000067d109f",
"blockNumber": "0xf8ff26",
"transactionHash": "0x9ee9891518b06f4b5bf76a4bef4ba6d93e8d38a17b7aaad492f5555865da7dbb",
"transactionIndex": "0xc",
"blockHash": "0x6357724a8ccd4dc6f175267395466c005be8ca70f1a67d2232774e8b0fb968ae",
"logIndex": "0x63",
"removed": false
}
],
"logsBloom": "0x04000000020000000000000000000000000000000000000000000000002040000000000000000000000000000000000010008000000000000000000100000040000000000000000000000008000600800000000000000000002100000002000000000000020000000000000000000800000000000800000180000112000000000001000002000000000080000000000000100000020010000000000000000000200000000400800000000000000001000000000000000000000000000000024000000042000000000001800000000000000404000400000000180000000020000800008000000000040000000000000000000020000000000000000002100002",
"status": "0x1",
"to": "0xd216153c06e857cd7f72665e0af1d7d82172f494",
"transactionHash": "0x9ee9891518b06f4b5bf76a4bef4ba6d93e8d38a17b7aaad492f5555865da7dbb",
"transactionIndex": "0xc",
"type": "0x0"
}
}

eth_getBlockTransactionCountByHash

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

Parameters

  • DATA, 32 Bytes - hash of a block.

    params: [
    '0xbb63603be7a656f34e7a8fa41cb610f33a6c9e74536159a7676fc00eed072d90'
    ]

Returns

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

Request

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

Result

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

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.

Request

Curl
Postman
Curl
curl https://polygon-mainnet.g.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://polygon-mainnet.g.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": "0x146"
}

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: [
'0xbb63603be7a656f34e7a8fa41cb610f33a6c9e74536159a7676fc00eed072d90',
'0x0' // 0
]

Returns

See eth_getTransactionByHash​

Request

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

Result

{
"jsonrpc": "2.0",
"id": 0,
"result": {
"blockHash": "0xbb63603be7a656f34e7a8fa41cb610f33a6c9e74536159a7676fc00eed072d90",
"blockNumber": "0xf93fba",
"from": "0x5604fdedd03bfb5e9331a44ba67cd2aa3c99276d",
"gas": "0x4bd12",
"gasPrice": "0xe8d4a51000",
"hash": "0x45e81b15ce93fc99af5ea6631fc0416515fbb2bd982fb6f9ef7ad66027e85e21",
"input": "0x38ed1739000000000000000000000000000000000000000000000000000000000301c1fa00000000000000000000000000000000000000000022057090352a28bb23ac7e00000000000000000000000000000000000000000000000000000000000000a00000000000000000000000005604fdedd03bfb5e9331a44ba67cd2aa3c99276d00000000000000000000000000000000000000000000000000000000c1b96bbc00000000000000000000000000000000000000000000000000000000000000030000000000000000000000002791bca1f2de4661ed88a30c99a7a9449aa841740000000000000000000000000d500b1d8e8ef31e21c99d1db9a6444d3adf1270000000000000000000000000aaa5b9e6c589642f98a1cda99b9d024b8407285a",
"nonce": "0x3d",
"to": "0xa5e0829caced8ffdd4de3c43696c57f7d7a678ff",
"transactionIndex": "0x0",
"value": "0x0",
"type": "0x0",
"v": "0x136",
"r": "0x52903fb1e680b74b775c4415b16bc77f6f8f511c80826679452900061cbd5d97",
"s": "0x2cc237b42925f108fcfa351fade6717f2473708f89affca8f7fab6d78c013107"
}
}

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​

Request

Curl
Postman
Curl
curl https://polygon-mainnet.g.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://polygon-mainnet.g.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": "0x19ece445ee0ad85d1f07d6852d2722fd47d5c9976ac62d9446842bf767a65bb3",
"blockNumber": "0xf94012",
"from": "0x9b814233894cd227f561b78cc65891aa55c62ad2",
"gas": "0x289ec",
"gasPrice": "0x4cd5886400",
"hash": "0x44374bfbe757797e181de0a43643a9e5dce9dbb1e7360a04667d4703ac3c7a2b",
"input": "0x0c53c51c0000000000000000000000007a2c8466603a4d9ef3a294672d5402b2ebe5826000000000000000000000000000000000000000000000000000000000000000a0b703dab06e91938eb7c85c5261cf8c46c55a6a7f17efc8910d5148f7cf993ac7333d10bd3fadaf8c4f99b729152e10a148aa56e94863e761aef4a3babe4f7cdd000000000000000000000000000000000000000000000000000000000000001c0000000000000000000000000000000000000000000000000000000000000044a22cb46500000000000000000000000058807bad0b376efc12f5ad86aac70e78ed67deae000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000",
"nonce": "0xf167",
"to": "0xa5f1ea7df861952863df2e8d1312f7305dabf215",
"transactionIndex": "0x0",
"value": "0x0",
"type": "0x0",
"v": "0x136",
"r": "0x9121dd82b8b8e6a2f6fc89ad6b1461b563444d2518cf4bc3301c21d81dd3c740",
"s": "0x52f252d1aeff76206d0f21ee9236ab74b6e7452ef0466cd56534646f9d4d7af4"
}
}

β€‹βœ 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: ["0x29adbbaf99a3f97b2baefa11e865cf9d74435716ef8618caaa388619f5ae7d8e5d2cadab0cd2f5becd4ebf7d48f5584c9e414c2a4a6ea2bc6ea8f02dbf5675cd01"]

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.

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://polygon-mainnet.g.alchemyapi.io/v2/your-api-key \
-X POST \
-H "Content-Type: application/json" \
-d '{"jsonrpc":"2.0","method":"eth_sendRawTransaction","params":["0x29adbbaf99a3f97b2baefa11e865cf9d74435716ef8618caaa388619f5ae7d8e5d2cadab0cd2f5becd4ebf7d48f5584c9e414c2a4a6ea2bc6ea8f02dbf5675cd01"],"id":1}'
Postman
URL: https://polygon-mainnet.g.alchemyapi.io/v2/your-api-key
RequestType: POST
Body:
{
"jsonrpc":"2.0",
"method":"eth_sendRawTransaction",
"params":["0x29adbbaf99a3f97b2baefa11e865cf9d74435716ef8618caaa388619f5ae7d8e5d2cadab0cd2f5becd4ebf7d48f5584c9e414c2a4a6ea2bc6ea8f02dbf5675cd01"],
"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: [
'0x0ef2e86a73c7be7f767d7abe53b1d4cbfbccbf3a',
'latest'
]

Returns

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

Request

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

Result

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

eth_getCode

Returns code at a given address. This method can be used to distinguish between contract addresses and wallet addresses.

Parameters

  • DATA, 20 Bytes - address.

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

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

Returns

  • DATA - the code from the given address.

Request

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

Result

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

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.

Pending example!

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.

Request

Curl
Postman
Curl
curl https://polygon-mainnet.g.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://polygon-mainnet.g.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.

Request

Curl
Postman
Curl
curl https://polygon-mainnet.g.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://polygon-mainnet.g.alchemyapi.io/v2/your-api-key
RequestType: POST
Body:
{
"jsonrpc":"2.0",
"method":"eth_getProof",
"params":["0x7F0d15C7FAae65896648C8273B6d7E43f58Fa842",["0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421"],"latest"],
"id":1
}

Result

{
"jsonrpc": "2.0",
"id": 1,
"result": {
"address": "0x7f0d15c7faae65896648c8273b6d7e43f58fa842",
"accountProof": [
"0xf90211a001f8376b07906c3c694512eb5a0006def0a41ddf0ec1774530625f64987f6103a0300cb44fdb8d037c9e7f129b4616b7312b13e6a689dd8108dfc4d4cda796a5f3a0300e28a0e966b994458344c424246de7fe27f22913a05f55485802769f92e14fa0fbb5da243cd3d8f3da9baabcdd8c9af1c4041895b6d9fee9602fe8ffa04bd1dca04be995644174846bddc5a0a1a18038c04ac8501d86dbd883b83aeb9d4d36a927a0a03845280edee05f1bcbeebb71af107f2415d8aa9fa0ace8ed19889c2002a18ba02f33c81b8fffb065c0dd0fa4e0af1cd08638571524c5b017aa7b6ab9a159d36ca0ff38c0ecd978d7d7c477e1d73ce3f56f6fa9a38bab8692553f3e0227cf44c500a0b8555e51efb8e8e183c7518fbfeae60d6fabcfffb7b58439475fa6b3deb209faa06c909fb9839543f0dd2bd0af923bb67a7b21fcffe26226c525be226714eb982ca06921abc56c2f24e909faf626a8a2dd5dff9b20028090725eb714c3c93a3228d8a058028c4a84c95a65b41b5ace65904ecc0cd184f2ab8a53b347ef4591d41c477ea0eac35cd0c3a0844910c6db9eab9cef372e62f63c35b1c0265e803f4412c91694a0eb6d08245a3a3491a6f030b957a4f962cd95be60a67ae8f467f17c341a7c61bea09bfa39350897c43f913d0893a9dabc41468ed20698e6706353fea03078e6be05a0ccc62b8ec6ef0a5c9982ad5d9b6f2b8aa9a07cf2c8dd029b93c3e7fe37d1be8180",
"0xf90211a037b245b091d2248b80be2408f8c9d185070dc900f1e72171481f6ef0f6badae7a0847344c73d91591e9c058ea03936241dc838ac05e1432209ab6596421465bd27a0913d0c384266ded7463d722457a2ff2292e9875b53448008b7245601cd70ab98a0440fcfb3de03209df7cca338ab349c8760b87b72709bd10cbfb4aabacba57f5aa0e42285d3c469abb208f9586010e50983b44d2850d36fbdcc5db10bee3b4664eda05967d65750144d225c16b3d17258d216e8914c6fdcfd746ea6ff512954cc8a7ba0f1e261e7bff8fe91222feaa5d1cbaa0931a90979ef7552de959ed2e8c4797201a0bd1e1a762c6f78b5f13b81d5d12fabc91d8674dd5f1bdecfa66a5f0cdd88f22da09ee8162165b3dff6d1db5f501d65eeac48fc5e49e1073720efe19a701c13369fa0832edf1f1b496db86a4b1629816abc859f71da6d4bcfbc3ed8e46ee6abc83c7ca0bda4e256aeaf979b484873ed80536596c92cc3e3a1f0ec5a0696b0e2ad4cb609a0f7a1fcf40c535e57df607137bf51d05032b2ab56ffde3c910ee754b1d414698ea059b6f3de5a9f5a2fb8a8cf2d421a7a6436ef9f07cbf447aa7a41d515c5db8a52a0caa16f34c0528765ec2b580f2c2f1d6955d5fc4250a4a86f1d6b2b931ad111f9a05f086bc0721f6f17a16bd0200779fbdb0939ed8c2494b1aad4204a09ae3b35b1a0b62c66790820a11613c8b9baa6d0fa9568bebaaf607905614d8bae4bdcfefafc80",
"0xf90211a03303c753b4f488b4c049e479cc4796de78ead917901bee2f28a1bd85fdec09e3a0b68db45646f1bb767ee0d5414982b05472965f4ccb650f9045fef7c93a0f739da00e205af885bb806199ae2502e8a40d1c1e66669a20d9f8be21cb67cb2b130ef4a0d91bbd8f15ce274e4c769090329155a771bcd64226b67e607d588c941e659d6ea070fae56ea95c13a2d810afca5225e12fbf48161ec690e05d867d59aeab2e274da0980737cd1b0e7f693ce223c750b5d211ee1a569366f2cbd7f76ee88a8a62f902a0273c36c050cbeb67537c63ca39a6aa2365bce660234a2bc34edda64cb5cbbdc3a03f6ad0780afcfb7a57429256905d5ca9221ddb22c9c054111aaa0c3452393d1da0a515e8cde54e122baa67c51f9661aa377ff713e29effca0e4361d687f7577abfa000f3578da1733fdca7f56e69f8ab1601c3b4cc909cb926afac60487432bd5c72a012e1f42be181208f128c868c833693dd8e6f3c0d58112a5f2086e6d3ad08c8a3a05643c184c4b63ac5ee2574f8e5d3f3d58e9bc93334cb2ac8170e8d9af2e6e64ba08c27431b31a8318954c8ebea1be8afa19f5520b7000a539af8fb8caf6a757e42a0fb709b734f5dab2d647c862f9ff189ea60422135915d01829d6fea886afa6c2aa047601d9151b2ba33e9e73bdeb697b93534cd34d052530b40f1e4627bee79e8fba0c99ed933ca8ceb5414db1a3192f24ed7c44526716d17b046f0d92b04d862ae4c80",
"0xf90211a00d7751dc79c9156f2357704ccc0c8fd590f6bb0c8ef01b32aa347689ae1b7177a0a4fb1a518b73ed70159eb3be9d6692ab4e7271f1fc2bc8c3a870ef98850efe43a0642c0db960ab327f7dcbaa4f76b0e01aee2db72cb5ee92880d0d4393c6d2e48fa006e5f9e16d96ed4f38f5854a65bcee0ccdc3108d5e462187c66659426cf341ffa0f3132e2aa744438ae54c50561199a11e9391d758dc602a59520a0680ed8d313aa018260f95ebf9fa543d526847fd89ceb81c60a7abc3c5f318a5fdb884f5a1a5a5a00034799a077b472409e51abc46758298cd74dd131b81935427116cda6d44705fa0b2117d267a54626509f5f2cc23719a81d9440387de231cea6fb6f5f0594b7a39a0a2ffa5a52791d85322458b995381cc131844c5fc58f8cc6cd4561fc64d6d8f55a06d94dad3d3b7a9789707e96cc25231499453c779b0634a96f8cab0d5cba42a90a062f8558dfbd67248347121f5c7c35c9418723cff00191d238f8d3d5e5f696b5fa0d3bd2acd4035e94b4cd66462e33a6548d203bf5d3ce91d4c705e2d9a088b2f63a070df6544606e44e128e9aefe79c60746d4229fd011411e4fa0b214cadbbefbada09fb29e72acbfb83bb255644d833e5935d1472231ebb8f404e096f7c712bf363aa0dfafc10973c9986fd7316c159af401e3e62bf0e526bb04aa6e255e2615104766a0fdf63393eec26d77eda30a9e50f7e929d3d646ddd5ff015a4585fe9bac93e0d880",
"0xf90211a03d917f4a11219ba0c039107f9d9022a038ec5adcfce78c082393c4e4033da504a034f0f69773413969b5e5402a551c11943db0870a3dd741ffb080389ed6330d5ba0e21d064290c007d5dbd856a94cf0055e2bb00b39fcc9a9e211c30fd79d0ec2d7a077d7c53e2d34aa1d90e13e59ee0fa79959fd8c90be69f9285c801e6942e21ed5a0a6521f6086e249135f8737f5b86d9993ee47f124dd13795a24b62c146b5b9b91a0ae83d7d4f3e30acedc78fdf005befa04a129b9ea56a02e8cb56ae71f79ff803fa0a29f80b4bad24b764146a9cfe1e707b83f603d8193e8d65096e87d3799a2fb13a0d03350ff011c2dd5b01ff0de94d0314cba0a66eb23310bf76984b235e8d580eba07b5849bd464f2462a6950c378f88b098bb48d57571aeed7d77dbfccd2108c6bea030cf7fc983434e4137d8e983b3be89545037c8ab72947f1b85803f1b7af6e868a0d233b40fd2d6c08f5b31df464e0ae61a6670249051ccaac74b7a196d678e3182a02fd11d6567ebf44f3b83de7116e4d7982537f32915d01702b07e0d44b5976ec5a07bf5fd9d2d8c19ba71a44f40987c60185a03dab62e304d957a1a7ba8862e306ba09d2e0a5a31090bc96cffecf0250bdef07c115c5e498cf0485f01524150ecec1ea0cbae19f56cd37a94e521a693f91b0b5ff7ff958c9c3d0a7779b44b6f554acb40a0139e14b60742fd987226078408790d6cf21f3a05eec8ff00bc258f96f3e251dd80",
"0xf8d1a01d608a24a8a811af295fffd1a840539826c4b342b451e5293c1aaf88d4fef08aa0501a846e6b2680d86643c6211f5ac33ef404a382894f8d49a3e887ccf2c257c2a0d427f04f25079e46a7ae205fe2862bd155eb68e693adaa36b1dfb6d7a9bba210a066460be340441b1ec0e5b0596b6968ab68ea54d2830a4a38def70cdb2ea558c5808080808080a046fbdd730771362a13e30bda783543b18baa113f446176f27c86eeee609e80d5a0a10c55dd71e81b3aa87b167fbfc1c154bc7227ca8cdea3b5b1bb567bc07981be8080808080",
"0xf8679e2067f29e142d49f8824d4e7f1735ec3da219687387629b5fccd86812df84b846f8440180a056e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421a01d93f60f105899172f7255c030301c3af4564edd4a48577dbdc448aec7ddb0ac"
],
"balance": "0x0",
"codeHash": "0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470",
"nonce": "0x0",
"storageHash": "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421",
"storageProof": [
{
"key": "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421",
"value": "0x0",
"proof": []
}
]
}
}

β€‹πŸ§  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), OR the blockHash (in accordance with EIP-1898) Note: the parameter is an object instead of a string and should be specified as: {"blockHash": "0x<some-hash>"}. Learn more here.

Note: eth_call has a timeout restriction at the node level. Batching multiple eth_call together on-chain using pre-deployed smart contracts might result in unexpected timeouts that cause none of your calls to complete. Instead, consider serializing these calls, or using smaller batches if they fail with a node error code.

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

Returns

DATA - the return value of executed contract.

Request

Curl
Postman
Curl
curl https://polygon-mainnet.g.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://polygon-mainnet.g.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.

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​

Pending example!

​⛓ Chain Information

Calls to receive information about the current blockchain.

eth_gasPrice

Returns the current price per gas in wei.

There may be slight disrepancies due to calculation differences between this method and the matic gas station.

Parameters

none

Returns

QUANTITY - integer of the current gas price in wei.

Request

Curl
Postman
Curl
curl https://polygon-mainnet.g.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://polygon-mainnet.g.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": "0x77359400"
}

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

  • eth_estimateGas will check the balance of the sender (to make sure that the sender has enough gas to complete the request). This means that even though the call doesn't consume any gas, the from address must have enough gas to execute the transaction.

  • If no gas 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 actual gas needed is higher than the pending block gas limit.

Returns

QUANTITY - the amount of gas used.

Request

Curl
Postman
Curl
curl https://polygon-mainnet.g.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://polygon-mainnet.g.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.

Request

Curl
Postman
Curl
curl https://polygon-mainnet.g.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://polygon-mainnet.g.alchemyapi.io/v2/your-api-key
RequestType: POST
Body:
{
"jsonrpc":"2.0",
"method":"eth_chainId",
"params":[],
"id":83
}

Result

{
"jsonrpc": "2.0",
"id": 83,
"result": "0x89"
}
​

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

Request

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

Result

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

net_listening

Returns true if client is actively listening for network connections.

Parameters

none

Returns

Boolean - true when listening, otherwise false.

Request

Curl
Postman
Curl
curl https://polygon-mainnet.g.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://polygon-mainnet.g.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

Request

Curl
Postman
Curl
curl https://polygon-mainnet.g.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://polygon-mainnet.g.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: [
'0x17fd2777f5f4f15912a6ea49bcb213c6991ba7ef57cdd64a572f719aa2a46c23',
'0x0' // 0
]

Returns

See eth_getBlockByHash

Request

Curl
Postman
Curl
curl https://polygon-mainnet.g.alchemyapi.io/v2/your-api-key \
-X POST \
-H "Content-Type: application/json" \
-d '{"jsonrpc":"2.0","method":"eth_getUncleByBlockHashAndIndex","params":["0x17fd2777f5f4f15912a6ea49bcb213c6991ba7ef57cdd64a572f719aa2a46c23", "0x0"],"id":0}'
Postman
URL: https://ethhhhhgon-mainnet.g.alchemyapi.io/v2/your-api-key
RequestType: POST
Body:
{
"jsonrpc":"2.0",
"method":"eth_getUncleByBlockHashAndIndex",
"params":["0x17fd2777f5f4f15912a6ea49bcb213c6991ba7ef57cdd64a572f719aa2a46c23", "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: [
'0x17fd2777f5f4f15912a6ea49bcb213c6991ba7ef57cdd64a572f719aa2a46c23'
]

Returns

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

Request

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

Result

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

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.

Request

Curl
Postman
Curl
curl https://polygon-mainnet.g.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://polygon-mainnet.g.alchemyapi.io/v2/your-api-key
RequestType: POST
Body:
{
"jsonrpc":"2.0",
"method":"eth_getUncleCountByBlockNumber",
"params":["0xe8"],
"id":1
}

Result

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

​πŸ–₯ Web3

web3_clientVersion

Returns the current client version.

Parameters

none

Returns

String - The current client version

Request

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

Result

{
"jsonrpc": "2.0",
"id": 0,
"result": "bor/v1.10.3-stable-d33ce83c/linux-amd64/go1.15.5"
}

web3_sha3

Returns Keccak-256 (not the standardized SHA3-256) of the given data.

Parameters

  1. DATA - the data in hex form to convert into a SHA3 hash

Note: web3_sha3 takes in a hexidecimal number, not a direct string. So, if you wanted to convert "hello world" to it's Keccak-256 hash you would need to input the hex number for "hello world", which is "68656c6c6f20776f726c64".

params: [
"0x68656c6c6f20776f726c64"
]

Returns

DATA - The SHA3 result of the given string.

Request

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

Result

{
"id":64,
"jsonrpc": "2.0",
"result": "0x47173285a8d7341e5e972fc677286384f802f8ef42a5ec5f03bbfa254cb01fad"
}

​⏰Real Time Events

Geth v1.4 and later support subscribing using JSON-RPC notifications. This allows clients to wait for events instead of polling for them.

It works by subscribing to particular events where the node will return a subscription id. For each event that matches the subscription, a notification with relevant data is sent together with the subscription id.

Below are several methods used for retrieving real time events.

eth_syncing

Returns an object with data about the sync status or falseif the node is fully synced.

Note: Your response from eth_syncing will likely return false because Alchemy only supports nodes in production that are completed synced.

Parameters

none

Returns

Object|Boolean, An object with sync status data or FALSE, when not syncing:

  • startingBlock: QUANTITY - The block at which the import started (will only be reset, after the sync reached his head)

  • currentBlock: QUANTITY - The current block, same as eth_blockNumber

  • highestBlock: QUANTITY - The estimated highest block

Request

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

Response

{
"id":1,
"jsonrpc": "2.0",
"result": false
}

eth_subscribe

If successful this returns the subscription id. Subscriptions are creates with a regular RPC call with eth_subscribe as method and the subscription name as first parameter.

Parameters

  1. subscription name

  2. optional arguments (see below)

Returns

If successful this returns the subscription id.

NOTE: eth_subscribe requests cannot be replicated in the composer tool

Request

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

Result

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

Optional Arguments:

1. newHeads

Fires a notification each time a new header is appended to the chain, including chain reorganizations.

In case of a chain reorganization the subscription will emit all new headers for the new chain. Therefore the subscription can emit multiple headers on the same height.

Paramaters

none

Request

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

Result

{
"jsonrpc":"2.0",
"id":1,
"result":"0x9ce59a13059e417087c02d3236a0b1cc"
}
{
"jsonrpc": "2.0",
"method": "eth_subscription",
"params": {
"result": {
"difficulty": "0x15d9223a23aa",
"extraData": "0xd983010305844765746887676f312e342e328777696e646f7773",
"gasLimit": "0x47e7c4",
"gasUsed": "0x38658",
"logsBloom": "0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
"miner": "0xf8b483dba2c3b7176a3da549ad41a48bb3121069",
"nonce": "0x084149998194cc5f",
"number": "0x1348c9",
"parentHash": "0x7736fab79e05dc611604d22470dadad26f56fe494421b5b333de816ce1f25701",
"receiptRoot": "0x2fab35823ad00c7bb388595cb46652fe7886e00660a01e867824d3dceb1c8d36",