Skip to content

Latest commit

 

History

History
174 lines (164 loc) · 10.2 KB

ETH_JSON_RPC_API.md

File metadata and controls

174 lines (164 loc) · 10.2 KB

以太坊JSON RPC API

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.

第二个参数为false

curl -X POST --data '{"jsonrpc":"2.0","method":"eth_getBlockByNumber","params":["0x97b68f", false],"id":1}' https://ropsten.infura.io/v3/94bc20a138044cd7974fcd20b91d68ba|jq
{
  "jsonrpc": "2.0",
  "id": 1,
  "result": {
    "difficulty": "0x1865123f4",
    "extraData": "0xd883010a02846765746888676f312e31362e32856c696e7578",
    "gasLimit": "0x7a1200",
    "gasUsed": "0x2b4b6",
    "hash": "0x246f5e79320ec05563564b5f4da45d7e68c6652163e34de00cd056a2cc11c756",
    "logsBloom": "0x00200000000000000000008080000000000000000000000080010000000000000000000000008008020000000000000000000000000000000000000000000000000000000000000000000208000000200000100800000000000020000000000000000000080000000080000000000000000000000000000000000010000000000000000000000000004000000002000000000000000000080000004000000000000000000000004140040000000000000000001000000000001000000000000000000002000000200000000000002020000000000000001000000000060020000000000000000000080000000200000000000080000020000000000400400000",
    "miner": "0xb76d61836fa52bfd5d4247bfa3ea81cac9c75b25",
    "mixHash": "0x5cb9421244cce7473c1250d73f9f089f57e9720fa34b1b0ff142ce3335dbbbc8",
    "nonce": "0x00bc638ff895264e",
    "number": "0x97b68f",
    "parentHash": "0xc93a820380135a1c9ff52ba07dae7df1768c191586d35704b78a9aebd446346a",
    "receiptsRoot": "0x2126f324bc321c625ec6f0ab7f7ac619f1e9a75345bdc64f10b9ef9d496cdfd7",
    "sha3Uncles": "0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347",
    "size": "0x590",
    "stateRoot": "0x00491d7d7910b0398637aeaae2f5b1df5c6d8a81eebbbdbc3d566a76bde52054",
    "timestamp": "0x60630865",
    "totalDifficulty": "0x75764801196635",
    "transactions": [
      "0xb913c81917ca63c4d834f52917df680ac98be19eaa87c918923c0046374e3846",
      "0xa15dba89963841691757105842eb4d6289e06e7d6f28d5a5b3f73cdc51ce77b2",
      "0x6a637db64aaf423c11cd92d01ccb233d1a02ac2c598e13d17d719b625784450c"
    ],
    "transactionsRoot": "0x125199b24c7aa22d12a7ace30f67db70c70434b6e994560499893b889eb76b72",
    "uncles": []
  }
}

第二个参数为true:

 curl -X POST --data '{"jsonrpc":"2.0","method":"eth_getBlockByNumber","params":["0x97b68f", true],"id":1}' https://ropsten.infura.io/v3/94bc20a138044cd7974fcd20b91d68ba|jq
{
  "jsonrpc": "2.0",
  "id": 1,
  "result": {
    "difficulty": "0x1865123f4",
    "extraData": "0xd883010a02846765746888676f312e31362e32856c696e7578",
    "gasLimit": "0x7a1200",
    "gasUsed": "0x2b4b6",
    "hash": "0x246f5e79320ec05563564b5f4da45d7e68c6652163e34de00cd056a2cc11c756",
    "logsBloom": "0x00200000000000000000008080000000000000000000000080010000000000000000000000008008020000000000000000000000000000000000000000000000000000000000000000000208000000200000100800000000000020000000000000000000080000000080000000000000000000000000000000000010000000000000000000000000004000000002000000000000000000080000004000000000000000000000004140040000000000000000001000000000001000000000000000000002000000200000000000002020000000000000001000000000060020000000000000000000080000000200000000000080000020000000000400400000",
    "miner": "0xb76d61836fa52bfd5d4247bfa3ea81cac9c75b25",
    "mixHash": "0x5cb9421244cce7473c1250d73f9f089f57e9720fa34b1b0ff142ce3335dbbbc8",
    "nonce": "0x00bc638ff895264e",
    "number": "0x97b68f",
    "parentHash": "0xc93a820380135a1c9ff52ba07dae7df1768c191586d35704b78a9aebd446346a",
    "receiptsRoot": "0x2126f324bc321c625ec6f0ab7f7ac619f1e9a75345bdc64f10b9ef9d496cdfd7",
    "sha3Uncles": "0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347",
    "size": "0x590",
    "stateRoot": "0x00491d7d7910b0398637aeaae2f5b1df5c6d8a81eebbbdbc3d566a76bde52054",
    "timestamp": "0x60630865",
    "totalDifficulty": "0x75764801196635",
    "transactions": [
      {
        "blockHash": "0x246f5e79320ec05563564b5f4da45d7e68c6652163e34de00cd056a2cc11c756",
        "blockNumber": "0x97b68f",
        "from": "0x4edd80557f2cc893de5397d0508efe7ecba7b98d",
        "gas": "0x5208",
        "gasPrice": "0x77359400",
        "hash": "0xb913c81917ca63c4d834f52917df680ac98be19eaa87c918923c0046374e3846",
        "input": "0x",
        "nonce": "0x419",
        "r": "0xa82d2c881da7375a0cca99536ea21938f5efa1c01b7f018f2f9325551385b68e",
        "s": "0x4b408ee6deece2b1a2abe59112652166858b40490c44503c7dcd87fd35bfdeee",
        "to": "0x4edd80557f2cc893de5397d0508efe7ecba7b98d",
        "transactionIndex": "0x0",
        "type": "0x0",
        "v": "0x29",
        "value": "0xde0b6b3a7640000"
      },
      {
        "blockHash": "0x246f5e79320ec05563564b5f4da45d7e68c6652163e34de00cd056a2cc11c756",
        "blockNumber": "0x97b68f",
        "from": "0x4183d62963434056e75e9854bc4ba92aa43a2d08",
        "gas": "0x1acee",
        "gasPrice": "0x77359400",
        "hash": "0xa15dba89963841691757105842eb4d6289e06e7d6f28d5a5b3f73cdc51ce77b2",
        "input": "0x38ed173900000000000000000000000000000000000000000000000000000000007a6a89000000000000000000000000000000000000000000000000000000000000350500000000000000000000000000000000000000000000000000000000000000a00000000000000000000000004183d62963434056e75e9854bc4ba92aa43a2d080000000000000000000000000000000000000000000000000000000060fb9ee200000000000000000000000000000000000000000000000000000000000000020000000000000000000000000d9c8723b343a8368bebe0b5e89273ff8d712e3c0000000000000000000000002d80502854fc7304c3e3457084de549f5016b73f",
        "nonce": "0x2281a",
        "r": "0x3ddaa7e8ed477ed9cd257379024154dbf82648f2b7f5236ece04a4c91c79e0c5",
        "s": "0x74d8cb62f2537a0003bdee33ac3e8027bfa4e1aaa8ff7c7c48dd4657cd41586c",
        "to": "0x7a250d5630b4cf539739df2c5dacb4c659f2488d",
        "transactionIndex": "0x1",
        "type": "0x0",
        "v": "0x29",
        "value": "0x0"
      },
      {
        "blockHash": "0x246f5e79320ec05563564b5f4da45d7e68c6652163e34de00cd056a2cc11c756",
        "blockNumber": "0x97b68f",
        "from": "0x9adf4f220251d535ee4626d1e2058f09375385b1",
        "gas": "0x13000",
        "gasPrice": "0x3b9aca00",
        "hash": "0x6a637db64aaf423c11cd92d01ccb233d1a02ac2c598e13d17d719b625784450c",
        "input": "0x2e7ba6ef00000000000000000000000000000000000000000000000000000000000000060000000000000000000000009adf4f220251d535ee4626d1e2058f09375385b100000000000000000000000000000000000000000000001082389534769829300000000000000000000000000000000000000000000000000000000000000080000000000000000000000000000000000000000000000000000000000000000403b61499d5bb387ce8589f817f347211466af427efa4b0b4f711a3ccdc471246f8c475a8c240ba66b2b9fa7d09a83ea48f9e532479909938c71ec370d74a44318982d73e845ace2eb2906c843cb365de343d1e2abe1f03bede2f87b6642634a6e7154b52d79fbff401839a23f7ee2b1cd48ab7f9145c805827912430aa65afed",
        "nonce": "0x113",
        "r": "0x4a5ce6f4b7cde8187f71719d25854459772ac410cf463d5f2da88ce1b548dd51",
        "s": "0x6913bc17e8c166e665540c385421b9c9bd1bbef88d5272b08004f3e2de093024",
        "to": "0xdf0b5c23736249c23f7f4da908aad2559594d625",
        "transactionIndex": "0x2",
        "type": "0x0",
        "v": "0x2a",
        "value": "0x0"
      }
    ],
    "transactionsRoot": "0x125199b24c7aa22d12a7ace30f67db70c70434b6e994560499893b889eb76b72",
    "uncles": []
  }
}

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 only the hashes of the transactions.

$ curl -X POST --data '{"jsonrpc":"2.0","method":"eth_getBlockByHash","params": ["0xdc0818cf78f21a8e70579cb46a43643f78291264dda342ae31049421c82d21ae",false],"id":1}' https://mainnet.infura.io/v3/94bc20a138044cd7974fcd20b91d68ba |jq
{
  "jsonrpc": "2.0",
  "id": 1,
  "result": {
    "difficulty": "0x4ea3f27bc",
    "extraData": "0x476574682f4c5649562f76312e302e302f6c696e75782f676f312e342e32",
    "gasLimit": "0x1388",
    "gasUsed": "0x0",
    "hash": "0xdc0818cf78f21a8e70579cb46a43643f78291264dda342ae31049421c82d21ae",
    "logsBloom": "0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
    "miner": "0xbb7b8287f3f0a933474a79eae42cbca977791171",
    "mixHash": "0x4fffe9ae21f1c9e15207b1f472d5bbdd68c9595d461666602f2be20daf5e7843",
    "nonce": "0x689056015818adbe",
    "number": "0x1b4",
    "parentHash": "0xe99e022112df268087ea7eafaf4790497fd21dbeeb6bd7a1721df161a6657a54",
    "receiptsRoot": "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421",
    "sha3Uncles": "0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347",
    "size": "0x220",
    "stateRoot": "0xddc8b0234c2e0cad087c8b389aa7ef01f7d79b2570bccb77ce48648aa61c904d",
    "timestamp": "0x55ba467c",
    "totalDifficulty": "0x78ed983323d",
    "transactions": [],
    "transactionsRoot": "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421",
    "uncles": []
  }
}

eth_sendRawTransaction

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

Parameters DATA, The signed transaction data.

curl -X POST --data '{"jsonrpc":"2.0","method":"eth_sendRawTransaction","params":["0xd46e8dd67c5d32be8d46e8dd67c5d32be8058bb8eb970870f072445675058bb8eb970870f072445675"],"id":1}' https://mainnet.infura.io/v3/94bc20a138044cd7974fcd20b91d68ba |jq

curl -X POST --data '{"jsonrpc":"2.0","method":"eth_sendRawTransaction","params":["0xb86a01f86703800582520894fc18d8882697552737921df830102579f000008d865af3107a400080c080a0b31d443ae6c52b9d0932370980f5fe6859fcc45874a05ba29d9e1d9bd454e380a056893957d62c97b827c8fd59681002cead4246a0d61fb7cc87b44fc3eb33d777"],"id":1}' https://ropsten.infura.io/v3/94bc20a138044cd7974fcd20b91d68ba |jq