Geth snap同步模式下可用的RPC接口

Geth客户端共有三种同步模式:”snap”, “full” 和 “light”,默认是snap(前身为fast),本篇文章探究snap模式下可用的RPC接口。

  • snap:同步所有的区块头、区块体和状态数据,但不对区块中的交易进行重放以生成状态数据,只会在后期对区块中的数据(包括交易)进行校验
  • full:同步所有的区块头,区块体,并重放区块中的交易以生成状态数据。所有区块和区块中的交易都会被逐一验证
  • light:同步所有区块头,不同步区块体和状态数据,仅在需要时从网络上其他节点处获取。不会主动进行校验(仅在读取时进行哈希校验)。

关于以太坊客户端的更多信息:以太坊学习笔记

即使是snap模式,在同步后期(约80%进度之后)依然需要类似full模式参与加密校验(同步trienode),不幸的是,HDD无法支撑起这一过程所需的大量读写请求(geth progress when switching to trie download · Issue #20938 · ethereum/go-ethereum (github.com))。因此,本文中某些被标记为不可用的接口可能只是因为尚未完全同步。

state trie:

snap节点因为没有执行任何交易,所以没有任何可用的账户状态(即余额、智能合约代码和数据)。这些需要单独下载并与最新块进行交叉检查。这个阶段称为state trie 下载。节点以加密方式链接到每个块,以便可以实际验证账户没有被篡改。这种加密链接是通过在账户之上创建一个树结构来完成的,这个包含所有帐户和中间加密证明的巨大数据结构称为state trie。

而这个巨型的数据结构仍然在不断变化:每个块(每15 秒)要从这个树中删除约 1000 个节点,并添加约 2000 个新节点。这意味着节点需要同步每秒更改200次的数据集(这对机械硬盘来说是不可承受的)。在下载时,一个块只包含一个root state,当节点开始同步时,它只知道 1 个trie节点并尝试下载它。但是该节点最多可以引用 16 个新节点,因此在下一步中,节点又开始同步 16 个新节点。

官方API文档:OPEN-RPC Playground

中文API文档:以太坊JSON RPC手册

web3

✔web3_clientVersion

返回当前的客户端版本。可用。

请求:

1
2
3
4
5
6
{
"id": 0,
"jsonrpc": "2.0",
"method": "web3_clientVersion",
"params": []
}

响应:

1
2
3
4
5
{
"id": 0,
"jsonrpc": "2.0",
"result": "Geth/v1.10.16-unstable-f9ce40bb-20220124/linux-amd64/go1.17.6"
}

✔web3_sha3

返回指定数据的Keccak-256哈希值。可用。

请求:

1
2
3
4
5
6
7
8
{
"id": 0,
"jsonrpc": "2.0",
"method": "web3_sha3",
"params": [
"0x68656c6c6f20776f726c64"
]
}

响应:

1
2
3
4
5
{
"id": 0,
"jsonrpc": "2.0",
"result": "0x47173285a8d7341e5e972fc677286384f802f8ef42a5ec5f03bbfa254cb01fad"
}

net

✔net_version

返回当前连接网络的ID。可用。

请求:

1
2
3
4
5
6
{
"id": 0,
"jsonrpc": "2.0",
"method": "net_version",
"params": []
}

响应:

1
2
3
4
5
{
"id": 0,
"jsonrpc": "2.0",
"result": "1"
}

解释:

  • 1: Ethereum Mainnet
  • 2: Morden Testnet (deprecated)
  • 3: Ropsten Testnet
  • 4: Rinkeby Testnet
  • 42: Kovan Testnet

✔net_listening

返回客户端是否处于监听网络连接的状态。可用。

请求:

1
2
3
4
5
6
{
"id": 0,
"jsonrpc": "2.0",
"method": "net_listening",
"params": []
}

响应:

1
2
3
4
5
{
"id": 0,
"jsonrpc": "2.0",
"result": true
}

✔net_peerCount

返回当前客户端所连接的对端节点数量。可用。

请求:

1
2
3
4
5
6
{
"id": 0,
"jsonrpc": "2.0",
"method": "net_peerCount",
"params": []
}

响应:

1
2
3
4
5
{
"id": 0,
"jsonrpc": "2.0",
"result": "0x32" // 16进制
}

eth

❌eth_protocolVersion

返回当前以太坊协议的版本。不可用。

请求:

1
2
3
4
5
6
{
"id": 0,
"jsonrpc": "2.0",
"method": "eth_protocolVersion",
"params": []
}

响应:

1
2
3
4
5
6
7
8
{
"error": {
"code": -32601,
"message": "the method eth_protocolVersion does not exist/is not available"
},
"id": 0,
"jsonrpc": "2.0"
}

✔eth_syncing

对于已经同步的客户端,该调用返回一个描述同步状态的对象;对于未同步客户端,返回false。可用。

请求:

1
2
3
4
5
6
{
"id": 0,
"jsonrpc": "2.0",
"method": "eth_syncing",
"params": []
}

响应:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
{
"id": 0,
"jsonrpc": "2.0",
"result": {
"currentBlock": "0xd6d765", // 当前块
"healedBytecodeBytes": "0x23ba0f",
"healedBytecodes": "0x108",
"healedTrienodeBytes": "0x469c3cba",
"healedTrienodes": "0x3baacb",
"healingBytecode": "0x0",
"healingTrienodes": "0x454",
"highestBlock": "0xd6d7c1", // 预估最高块
"startingBlock": "0x0", // 开始块
"syncedAccountBytes": "0x955cae310",
"syncedAccounts": "0x9f891ad",
"syncedBytecodeBytes": "0xb24fd499",
"syncedBytecodes": "0x78dfc",
"syncedStorage": "0x24528b05",
"syncedStorageBytes": "0x1e667173fe"
}
}

❌eth_coinbase

返回客户端的coinbase地址。不可用。

请求:

1
2
3
4
5
6
{
"id": 0,
"jsonrpc": "2.0",
"method": "eth_coinbase",
"params": []
}

响应:

1
2
3
4
5
6
7
8
{
"error": {
"code": -32000,
"message": "etherbase must be explicitly specified"
},
"id": 0,
"jsonrpc": "2.0"
}

✔eth_mining

返回客户端是否在挖矿。可用。

请求:

1
2
3
4
5
6
{
"id": 0,
"jsonrpc": "2.0",
"method": "eth_mining",
"params": []
}

响应:

1
2
3
4
5
{
"id": 0,
"jsonrpc": "2.0",
"result": false
}

✔eth_hashrate

返回节点挖矿时每秒可算出的哈希数量。可用。

请求:

1
2
3
4
5
6
{
"id": 0,
"jsonrpc": "2.0",
"method": "eth_hashrate",
"params": []
}

响应:

1
2
3
4
5
{
"id": 0,
"jsonrpc": "2.0",
"result": "0x0" // 没有在挖矿,返回0
}

✔eth_gasPrice

返回当前的gas价格,单位:wei。可用。

经与Etherscan比较,确为实时gas价格。

请求:

1
2
3
4
5
6
{
"id": 0,
"jsonrpc": "2.0",
"method": "eth_gasPrice",
"params": []
}

响应:

1
2
3
4
5
{
"id": 0,
"jsonrpc": "2.0",
"result": "0x14bcbeb9e7" // 16进制
}

✔eth_accounts

返回客户端持有的地址列表。可用。

请求:

1
2
3
4
5
6
{
"id": 0,
"jsonrpc": "2.0",
"method": "eth_accounts",
"params": []
}

响应:

1
2
3
4
5
{
"id": 0,
"jsonrpc": "2.0",
"result": []
}

❌eth_getBalance

返回指定地址账户的余额。不可用。

请求:

1
2
3
4
5
6
7
8
9
{
"id": 0,
"jsonrpc": "2.0",
"method": "eth_getBalance",
"params": [
"0x00000000219ab540356cbb839cbe05303d7705fa", // 要检查余额的地址
"latest" // 整数块编号,或者字符串"latest"、"earliest"、"pending"
]
}

响应:

1
2
3
4
5
{
"id": 0,
"jsonrpc": "2.0",
"result": "0x0" // 无论什么地址始终为0
}

❌eth_getStorageAt

返回指定地址指定存储位置的值。不可用。

请求:

1
2
3
4
5
6
7
8
9
10
{
"id": 0,
"jsonrpc": "2.0",
"method": "eth_getStorageAt",
"params": [
"0x091B5Ff4Ec84aEE78Cd586571f81DEA8548938d7", // 指定的地址
"0x0", // 存储的位置号
"latest" // 整数块号,或者字符串"latest"、"earliest"、"pending"
]
}

响应:

1
2
3
4
5
{
"id": 0,
"jsonrpc": "2.0",
"result": "0x0000000000000000000000000000000000000000000000000000000000000000" // 始终为0
}

❌eth_getTransactionCount

返回指定地址发生的交易数量。不可用。

请求 #1:

1
2
3
4
5
6
7
8
9
{
"id": 0,
"jsonrpc": "2.0",
"method": "eth_getTransactionCount",
"params": [
"0x0F42798dEf01713f2e710669e2182B2d3D4110E3", // 地址
"latest" // 整数块编号,或者字符串"latest"、"earliest"、"pending"
]
}

响应 #1:

1
2
3
4
5
{
"id": 0,
"jsonrpc": "2.0",
"result": "0x0" //若为"latest",始终为0
}

请求 #2:

1
2
3
4
5
6
7
8
9
{
"id": 0,
"jsonrpc": "2.0",
"method": "eth_getTransactionCount",
"params": [
"0x3c29081b8898f1095d1ba0b2e05eacd45fda61bd",
"0xD6C9AA"
]
}

响应 #2:

1
2
3
4
5
{
"id": 0,
"jsonrpc": "2.0",
"result": "0x0" //始终为0
}

✔eth_getBlockTransactionCountByHash

返回指定块内的交易数量,使用哈希来指定块。可用。

请求:

1
2
3
4
5
6
7
8
{
"id": 0,
"jsonrpc": "2.0",
"method": "eth_getBlockTransactionCountByHash",
"params": [
"0x28c1de373975f51eeaea73ab46bb900ffc9c2b63199eda739b7053ed51720c1a" // 块哈希
]
}

响应:

1
2
3
4
5
{
"id": 0,
"jsonrpc": "2.0",
"result": "0x65"
}

✔eth_getBlockTransactionCountByNumber

返回指定块内的交易数量,使用块编号指定块。可用。

请求:

1
2
3
4
5
6
7
8
{
"id": 0,
"jsonrpc": "2.0",
"method": "eth_getBlockTransactionCountByNumber",
"params": [
"0xD6D85B" // 16进制的块编号
]
}

响应:

1
2
3
4
5
{
"id": 0,
"jsonrpc": "2.0",
"result": "0xd7" // 该块内发生的交易
}

✔eth_getUncleCountByBlockHash

返回指定块的叔伯数量,使用哈希指定块。可用。

请求:

1
2
3
4
5
6
7
8
{
"id": 0,
"jsonrpc": "2.0",
"method": "eth_getUncleCountByBlockHash",
"params": [
"0x14f5174e081999db250e08e57c7bbfa7ea502d2016f8ce7a3facb5025715f80c" // 块哈希
]
}

响应:

1
2
3
4
5
{
"id": 0,
"jsonrpc": "2.0",
"result": "0x0"
}

✔eth_getUncleCountByBlockNumber

返回指定块的叔伯数量,使用块编号指定块。可用。

请求:

1
2
3
4
5
6
7
8
{
"id": 0,
"jsonrpc": "2.0",
"method": "eth_getUncleCountByBlockNumber",
"params": [
"0xD6D85B"
]
}

响应:

1
2
3
4
5
{
"id": 0,
"jsonrpc": "2.0",
"result": "0x0"
}

❌eth_getCode

返回指定地址的代码。不可用。

请求 #1:

1
2
3
4
5
6
7
8
9
{
"id": 0,
"jsonrpc": "2.0",
"method": "eth_getCode",
"params": [
"0x60BB16c4A931b1a0B8A7D945C651DD90f41D42Cf",
"0x0"
]
}

响应 #1:

1
2
3
4
5
{
"id": 0,
"jsonrpc": "2.0",
"result": "0x" // 始终为"0x"
}

请求 #2:

1
2
3
4
5
6
7
8
9
{
"id": 0,
"jsonrpc": "2.0",
"method": "eth_getCode",
"params": [
"0x60BB16c4A931b1a0B8A7D945C651DD90f41D42Cf",
"0x2" // 非0值
]
}

响应 #2:

1
2
3
4
5
6
7
8
{
"error": {
"code": -32000,
"message": "missing trie node 4943d941637411107494da9ec8bc04359d731bfd08b72b4d0edcbd4cd2ecb341 (path )"
},
"id": 0,
"jsonrpc": "2.0"
}

✔eth_sign

计算以太坊签名。可用。

签名公式:

1
sign(keccak256("\x19Ethereum Signed Message:\n" + len(message) + message))

请求:

1
2
3
4
5
6
7
8
9
{
"id": 0,
"jsonrpc": "2.0",
"method": "eth_sign",
"params": [
"0x0F42798dEf01713f2e710669e2182B2d3D4110E3", // 地址
"0xdeadbeaf" // 要签名的消息
]
}

响应:

1
2
3
4
5
6
7
8
{
"error": {
"code": -32000,
"message": "unknown account" // 始终为"unknown account"
},
"id": 0,
"jsonrpc": "2.0"
}

❓eth_sendTransaction

创建一个新的消息调用交易,如果数据字段中包含代码,则创建一个合约。需要切换至测试网,暂未测试。

请求:

1

响应:

1

❓eth_sendRawTransaction

为签名交易创建一个新的消息调用交易或合约。暂未测试。

请求:

1

响应:

1

❓eth_call

立刻执行一个新的消息调用,无需在区块链上创建交易。暂未测试。

请求:

1

响应:

1

❓eth_estimateGas

执行并估算一个交易需要的gas用量,该次交易不会写入区块链,估算的数值可能比实际用量大的多。暂未测试。

请求:

1

响应:

1

✔eth_getBlockByHash

返回使用哈希指定的块中的交易信息。可用。

请求 #1:

1
2
3
4
5
6
7
8
9
{
"id": 0,
"jsonrpc": "2.0",
"method": "eth_getBlockByHash",
"params": [
"0x28c1de373975f51eeaea73ab46bb900ffc9c2b63199eda739b7053ed51720c1a", // 块哈希
false // 仅返回交易哈希
]
}

响应 #1:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
{
"id": 0,
"jsonrpc": "2.0",
"result": {
"baseFeePerGas": "0x2e7dbfbd45",
"difficulty": "0x2a938acf800899", // 块难度
"extraData": "0xe4b883e5bda9e7a59ee4bb99e9b1bc4a1421", // 块额外数据
"gasLimit": "0x1c9509e", // 本块允许的最大gas用量
"gasUsed": "0x742d2c", // 本块中所有交易使用的总gas用量
"hash": "0x28c1de373975f51eeaea73ab46bb900ffc9c2b63199eda739b7053ed51720c1a", // 块哈希,挂起块为null
"logsBloom": "0x812....40a1", // 快日志的bloom过滤器,挂起块为null
"miner": "0x829bd824b016326a401d083b33d092293333a830", // 挖矿奖励的接收账户
"mixHash": "0xf1e75a3be84b59080b0db836a3c739576b8f08cb499adfc6ccfff484236504dd",
"nonce": "0x0000c91c35389817", // 生成的pow哈希,挂起块为null
"number": "0xd6c9aa", // 块编号,挂起块为null
"parentHash": "0x093ff6c4ea93d0fe104f573718c30b0fdf1eca20e7649d324bb52b40ccc0fe11", // 父块的哈希
"receiptsRoot": "0x1f2463476fcbcee92c2fef2def36da9c77fffe6d7445a63c1882322e2b6b0922", // 块交易收据树的根节点
"sha3Uncles": "0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347", // 块中叔伯数据的SHA3哈希
"size": "0xa205",
"stateRoot": "0x5aa4eb405fbde30d601519d3e1b41bc238b24ccc87d9a5ed492e29cc712344b0", // 块最终状态树的根节点
"timestamp": "0x61f040be", // 块时间戳
"totalDifficulty": "0x86fab69939731be5b81", // 截止到本块的链上总难度
"transactions": [
"0x0f4f3fa3bc04b53feaf6a12d0112cf33a2449727d35f4d5b1fb7541fe3c896e4",
"0xa161c7f5daefaa211f1eefd3b6862f99b3d176e057b64abc69d8b20d8ed925f8",
......,
"0x8e373a16fab08652607273427925f0dac5730896761010a963eef623816c14e1"
], // 交易哈希数组
"transactionsRoot": "0x8cfd6631ebde34f2b39fdc7b281c305790925b4aae0c09179285109c1474f886", // 块中的交易树根节点
"uncles": [] // 叔伯哈希数组
}
}

请求 #2:

1
2
3
4
5
6
7
8
9
{
"id": 0,
"jsonrpc": "2.0",
"method": "eth_getBlockByHash",
"params": [
"0x28c1de373975f51eeaea73ab46bb900ffc9c2b63199eda739b7053ed51720c1a",
true // 返回完整的交易对象
]
}

响应 #2:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
{
"id": 0,
"jsonrpc": "2.0",
"result": {
"baseFeePerGas": "0x2e7dbfbd45",
"difficulty": "0x2a938acf800899",
"extraData": "0xe4b883e5bda9e7a59ee4bb99e9b1bc4a1421",
"gasLimit": "0x1c9509e",
"gasUsed": "0x742d2c",
"hash": "0x28c1de373975f51eeaea73ab46bb900ffc9c2b63199eda739b7053ed51720c1a",
"logsBloom": "0x8128218....4240a1",
"miner": "0x829bd824b016326a401d083b33d092293333a830",
"mixHash": "0xf1e75a3be84b59080b0db836a3c739576b8f08cb499adfc6ccfff484236504dd",
"nonce": "0x0000c91c35389817",
"number": "0xd6c9aa",
"parentHash": "0x093ff6c4ea93d0fe104f573718c30b0fdf1eca20e7649d324bb52b40ccc0fe11",
"receiptsRoot": "0x1f2463476fcbcee92c2fef2def36da9c77fffe6d7445a63c1882322e2b6b0922",
"sha3Uncles": "0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347",
"size": "0xa205",
"stateRoot": "0x5aa4eb405fbde30d601519d3e1b41bc238b24ccc87d9a5ed492e29cc712344b0",
"timestamp": "0x61f040be",
"totalDifficulty": "0x86fab69939731be5b81",
"transactions": [
{
"accessList": [],
"blockHash": "0x28c1de373975f51eeaea73ab46bb900ffc9c2b63199eda739b7053ed51720c1a",
"blockNumber": "0xd6c9aa",
"chainId": "0x1",
"from": "0x3c29081b8898f1095d1ba0b2e05eacd45fda61bd",
"gas": "0x8c746",
"gasPrice": "0x30969e0d37",
"hash": "0x0f4f3fa3bc04b53feaf6a12d0112cf33a2449727d35f4d5b1fb7541fe3c896e4",
"input": "0xa0050....b43d",
"maxFeePerGas": "0x310da2876d",
"maxPriorityFeePerGas": "0x218de4ff2",
"nonce": "0xa1",
"r": "0xba242a077779245b4e5ea0692c3aa64fb8304602b80634c4dd51b1ac94d32322",
"s": "0x617828cfb4ed14373643aeae1ba9adde0d5294e65a7549d9ecc87f351ecdf8a7",
"to": "0xa10fca31a2cb432c9ac976779dc947cfdb003ef0",
"transactionIndex": "0x0",
"type": "0x2",
"v": "0x0",
"value": "0x0"
},
......
], // 交易数组,含义可参考 eth_getTransactionByHash
"transactionsRoot": "0x8cfd6631ebde34f2b39fdc7b281c305790925b4aae0c09179285109c1474f886",
"uncles": []
}
}

✔eth_getBlockByNumber

返回指定编号的块。可用。

请求:

1
2
3
4
5
6
7
8
9
{
"id": 0,
"jsonrpc": "2.0",
"method": "eth_getBlockByNumber",
"params": [
"0xD6C9AA", // 指定块的编号
false // 返回完整的交易对象或仅返回交易哈希
]
}

响应:

eth_getBlockByHash

✔eth_getTransactionByHash

返回指定哈希对应的交易。可用。

请求:

1
2
3
4
5
6
7
8
{
"id": 0,
"jsonrpc": "2.0",
"method": "eth_getTransactionByHash",
"params": [
"0x0f4f3fa3bc04b53feaf6a12d0112cf33a2449727d35f4d5b1fb7541fe3c896e4"
]
}

响应:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
{
"id": 0,
"jsonrpc": "2.0",
"result": {
"accessList": [],
"blockHash": "0x28c1de373975f51eeaea73ab46bb900ffc9c2b63199eda739b7053ed51720c1a", // 交易所在块的哈希,挂起块为null
"blockNumber": "0xd6c9aa", // 交易所在块的编号,挂起块为null
"chainId": "0x1",
"from": "0x3c29081b8898f1095d1ba0b2e05eacd45fda61bd", // 交易发送方地址
"gas": "0x8c746", // 发送方提供的gas可用量
"gasPrice": "0x30969e0d37", // 发送方提供的gas价格
"hash": "0x0f4f3fa3bc04b53feaf6a12d0112cf33a2449727d35f4d5b1fb7541fe3c896e4", // 交易哈希
"input": "0xa0050....5b43d", // 随交易发送的数据
"maxFeePerGas": "0x310da2876d",
"maxPriorityFeePerGas": "0x218de4ff2",
"nonce": "0xa1", // 本次交易之前发送方已经生成的交易数量
"r": "0xba242a077779245b4e5ea0692c3aa64fb8304602b80634c4dd51b1ac94d32322",
"s": "0x617828cfb4ed14373643aeae1ba9adde0d5294e65a7549d9ecc87f351ecdf8a7",
"to": "0xa10fca31a2cb432c9ac976779dc947cfdb003ef0", // 交易接收方地址
"transactionIndex": "0x0", // 交易在块中的索引位置,挂起块为null
"type": "0x2",
"v": "0x0",
"value": "0x0" // 发送的以太数量
}
}

✔eth_getTransactionByBlockHashAndIndex

返回指定哈希的块内指定索引序号的交易。可用。

请求:

1
2
3
4
5
6
7
8
9
{
"id": 0,
"jsonrpc": "2.0",
"method": "eth_getTransactionByBlockHashAndIndex",
"params": [
"0x28c1de373975f51eeaea73ab46bb900ffc9c2b63199eda739b7053ed51720c1a",
"0x0"
]
}

响应:

eth_getBlockByHash

✔eth_getTransactionByBlockNumberAndIndex

返回指定编号的块内指定索引序号的交易。可用。

请求:

1
2
3
4
5
6
7
8
9
{
"id": 0,
"jsonrpc": "2.0",
"method": "eth_getTransactionByBlockNumberAndIndex",
"params": [
"0xD6C9AA",
"0x0"
]
}

响应:

eth_getBlockByHash

✔eth_getTransactionReceipt

返回指定哈希的交易的收据,挂起的交易其收据无效。可用。

请求:

1
2
3
4
5
6
7
8
{
"id": 0,
"jsonrpc": "2.0",
"method": "eth_getTransactionReceipt",
"params": [
"0x0f4f3fa3bc04b53feaf6a12d0112cf33a2449727d35f4d5b1fb7541fe3c896e4"
]
}

响应:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
{
"id": 0,
"jsonrpc": "2.0",
"result": {
"blockHash": "0x28c1de373975f51eeaea73ab46bb900ffc9c2b63199eda739b7053ed51720c1a", // 交易所在块的哈希
"blockNumber": "0xd6c9aa", // 交易所在块的编号
"contractAddress": null, // 对于合约创建交易,该值为新创建的合约地址,否则为null
"cumulativeGasUsed": "0x68fbd", // 交易所在块消耗的gas总量
"effectiveGasPrice": "0x30969e0d37",
"from": "0x3c29081b8898f1095d1ba0b2e05eacd45fda61bd", // 交易发送方地址
"gasUsed": "0x68fbd", // 该次交易消耗的gas用量
"logs": [
{
"address": "0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48",
"blockHash": "0x28c1de373975f51eeaea73ab46bb900ffc9c2b63199eda739b7053ed51720c1a",
"blockNumber": "0xd6c9aa",
"data": "0x0000000000000000000000000000000000000000000000000000000b7a3400e3",
"logIndex": "0x0",
"removed": false,
"topics": [
"0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef",
"0x00000000000000000000000088e6a0c2ddd26feeb64f039a2c41296fcb3f5640",
"0x000000000000000000000000a10fca31a2cb432c9ac976779dc947cfdb003ef0"
],
"transactionHash": "0x0f4f3fa3bc04b53feaf6a12d0112cf33a2449727d35f4d5b1fb7541fe3c896e4",
"transactionIndex": "0x0"
},
], // 本次交易生成的日志对象数组
"logsBloom": "0x0000....4080", // bloom过滤器,便于轻节点快速提取相关日志
"status": "0x1",
"to": "0xa10fca31a2cb432c9ac976779dc947cfdb003ef0", // 交易接收方地址,对于合约创建交易该值为null
"transactionHash": "0x0f4f3fa3bc04b53feaf6a12d0112cf33a2449727d35f4d5b1fb7541fe3c896e4", // 交易哈希
"transactionIndex": "0x0", // 交易在块内的索引序号
"type": "0x2"
}
}

✔eth_getUncleByBlockHashAndIndex

返回指定哈希的块指定索引位置的叔伯。可用。

请求:

1
2
3
4
5
6
7
8
9
{
"id": 0,
"jsonrpc": "2.0",
"method": "eth_getUncleByBlockHashAndIndex",
"params": [
"0x0f4f3fa3bc04b53feaf6a12d0112cf33a2449727d35f4d5b1fb7541fe3c896e4",
"0x0"
]
}

响应:

1
2
3
4
5
{
"id": 0,
"jsonrpc": "2.0",
"result": null
}

✔eth_getUncleByBlockNumberAndIndex

返回指定编号的块内指定索引序号的叔伯。可用。

请求:

1
2
3
4
5
6
7
8
9
{
"id": 0,
"jsonrpc": "2.0",
"method": "eth_getUncleByBlockNumberAndIndex",
"params": [
"0xD6C9AA",
"0x0"
]
}

响应:

1
2
3
4
5
{
"id": 0,
"jsonrpc": "2.0",
"result": null
}

❌eth_getCompilers

返回客户端中有效的编译器列表。不可用。

请求:

1
2
3
4
5
6
{
"id": 0,
"jsonrpc": "2.0",
"method": "eth_getCompilers",
"params": []
}

响应:

1
2
3
4
5
6
7
8
{
"error": {
"code": -32601,
"message": "the method eth_getCompilers does not exist/is not available"
},
"id": 0,
"jsonrpc": "2.0"
}

❌eth_compileSolidity

返回编译后的solidity代码。不可用。

请求:

1
2
3
4
5
6
7
8
{
"id": 0,
"jsonrpc": "2.0",
"method": "eth_compileSolidity",
"params": [
"contract test { function multiply(uint a) returns(uint d) { return a * 7; } }"
]
}

响应:

1
2
3
4
5
6
7
8
{
"error": {
"code": -32601,
"message": "the method eth_compileSolidity does not exist/is not available"
},
"id": 0,
"jsonrpc": "2.0"
}

❌eth_compileLLL

返回编译后的LLL代码。不可用。

请求:

1
2
3
4
5
6
7
8
{
"id": 0,
"jsonrpc": "2.0",
"method": "eth_compileLLL",
"params": [
"(returnlll (suicide (caller)))"
]
}

响应:

1
2
3
4
5
6
7
8
{
"error": {
"code": -32601,
"message": "the method eth_compileLLL does not exist/is not available"
},
"id": 0,
"jsonrpc": "2.0"
}

❌eth_compileSerpent

返回编译后的Serpent代码。不可用。

请求:

1
2
3
4
5
6
7
8
{
"id": 0,
"jsonrpc": "2.0",
"method": "eth_compileSerpent",
"params": [
"/* some serpent */"
]
}

响应:

1
2
3
4
5
6
7
8
{
"error": {
"code": -32601,
"message": "the method eth_compileSerpent does not exist/is not available"
},
"id": 0,
"jsonrpc": "2.0"
}

✔eth_newFilter

基于给定的选项创建一个过滤器对象,接收状态变化时的通知。可用。

假定一个交易的主题为[A, B],该主题会被以下过滤器匹配:

  • [] 任何主题
  • [A] 第一个主题为A,第二个主题不限
  • [null, B] 第一个主题不限,第二个主题为B
  • [A, B] 第一个主题为A,第二个主题为B
  • [[A, B], [B, C]] 第一个主题为A或B,第二个主题为B或C

请求:

1
2
3
4
5
6
7
8
9
10
11
12
13
{
"id": 0,
"jsonrpc": "2.0",
"method": "eth_newFilter",
"params": [
{
"fromBlock": "0xd6c9aa", // 整数块编号或者"latest"、"pending"、"earliest",可选,默认值"latest"。
"toBlock": "0xd6c9ab", // 整数块编号或者"latest"、"pending"、"earliest",可选,默认值"latest"。
//"address": 合约地址或生成日志的一组地址,可选
"topics": [] // 主题数组,可选
}
]
}

响应:

1
2
3
4
5
{
"id": 0,
"jsonrpc": "2.0",
"result": "0xffe210b5c962996a6664dc1ebc9eb05b" // 过滤器编号
}

❌eth_newBlockFilter

创建过滤器,当新块生成时进行通知。不可用。

可以成功创建过滤器,但由于可能尚未跟上主网的出块速度,查询过滤器无法得到日志。

请求:

1
2
3
4
5
6
{
"id": 0,
"jsonrpc": "2.0",
"method": "eth_newBlockFilter",
"params": []
}

响应:

1
2
3
4
5
{
"id": 0,
"jsonrpc": "2.0",
"result": "0xbeb626deabcdf93d2167cdb27ad6d230" // 过滤器编号
}

❌eth_newPendingTransactionFilter

创建过滤器,当产生挂起交易时进行通知。 不可用。

可以成功创建过滤器,但查询过滤器无法得到日志。

请求:

1
2
3
4
5
6
{
"id": 0,
"jsonrpc": "2.0",
"method": "eth_newPendingTransactionFilter",
"params": []
}

响应:

1
2
3
4
5
{
"id": 0,
"jsonrpc": "2.0",
"result": "0xb7303ea3aeab1d706126ecaac9dcfc25"
}

✔eth_uninstallFilter

卸载指定编号的过滤器。可用。

注意,过滤器在一定时间内若未接收到eth_getFilterChanges调用,则会自动超时。

请求:

1
2
3
4
5
6
7
8
{
"id": 0,
"jsonrpc": "2.0",
"method": "eth_uninstallFilter",
"params": [
"0x5c005232da23c8f5705623c81d415989" // 过滤器编号
]
}

响应:

1
2
3
4
5
{
"id": 0,
"jsonrpc": "2.0",
"result": true // 是否成功卸载
}

✔eth_getFilterChanges

查询指定的过滤器,返回自上次查询之后新生成的日志数组。可用。

请求:

1
2
3
4
5
6
7
8
{
"id": 0,
"jsonrpc": "2.0",
"method": "eth_getFilterChanges",
"params": [
"0xffe210b5c962996a6664dc1ebc9eb05b"
]
}

响应:

1
2
3
4
5
{
"id": 0,
"jsonrpc": "2.0",
"result": []
}

✔eth_getFilterLogs

返回指定编号过滤器中的全部日志。可用。

请求:

1
2
3
4
5
6
7
8
{
"id": 0,
"jsonrpc": "2.0",
"method": "eth_getFilterLogs",
"params": [
"0xffe210b5c962996a6664dc1ebc9eb05b"
]
}

响应:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
{
"id": 0,
"jsonrpc": "2.0",
"result": [
{
"address": "0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48",
"blockHash": "0x28c1de373975f51eeaea73ab46bb900ffc9c2b63199eda739b7053ed51720c1a",
"blockNumber": "0xd6c9aa",
"data": "0x0000000000000000000000000000000000000000000000000000000b7a3400e3",
"logIndex": "0x0",
"removed": false,
"topics": [
"0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef",
"0x00000000000000000000000088e6a0c2ddd26feeb64f039a2c41296fcb3f5640",
"0x000000000000000000000000a10fca31a2cb432c9ac976779dc947cfdb003ef0"
],
"transactionHash": "0x0f4f3fa3bc04b53feaf6a12d0112cf33a2449727d35f4d5b1fb7541fe3c896e4",
"transactionIndex": "0x0"
},
......
]
}

✔eth_getLogs

返回匿名过滤器中的所有日志。可用。

请求:

1
2
3
4
5
6
7
8
9
10
11
12
{
"id": 0,
"jsonrpc": "2.0",
"method": "eth_getLogs",
"params": [
{
"fromBlock": "0xd6c9aa",
"toBlock": "0xd6c9ab",
"topics": []
}
]
}

响应:

eth_getFilterLogs

❌ eth_getWork

返回当前块的哈希、种子哈希、以及要满足的边界条件,即目标。不可用。

可能是因为节点并不在挖矿。

请求:

1
2
3
4
5
6
{
"id": 0,
"jsonrpc": "2.0",
"method": "eth_getWork",
"params": []
}

响应:

1
2
3
4
5
6
7
8
{
"error": {
"code": -32000,
"message": "no mining work available yet"
},
"id": 0,
"jsonrpc": "2.0"
}

❓eth_submitWork

用于提交POW解决方案。暂未测试。

请求:

1

响应:

1

❓eth_submitHashrate

用于提交挖矿的哈希速率。暂未测试。

请求:

1

响应:

1

❌eth_blockNumber

返回最新块的编号。不可用。

请求:

1
2
3
4
5
6
{
"id": 0,
"jsonrpc": "2.0",
"method": "eth_blockNumber",
"params": []
}

响应:

1
2
3
4
5
{
"id": 0,
"jsonrpc": "2.0",
"result": "0x0"
}

db

数据库相关操作。均已被废弃。

❌db_putString

在本地数据库中存入字符串。已被废弃。

请求:

1
2
3
4
5
6
7
8
9
10
{
"id": 0,
"jsonrpc": "2.0",
"method": "db_putString",
"params": [
"testDB",
"myKey",
"myString"
]
}

响应:

1
2
3
4
5
6
7
8
{
"error": {
"code": -32601,
"message": "the method db_putString does not exist/is not available"
},
"id": 0,
"jsonrpc": "2.0"
}

❌db_getString

从本地数据库读取字符串。已被废弃。

❌db_putHex

将二进制数据写入本地数据库。已被废弃。

❌db_getHex

从本地数据库中读取二进制数据。已被废弃。

shh

Whisper协议 相关。均不可用。

❌shh_version

返回当前的whisper协议版本。不可用。

请求:

1
2
3
4
5
6
{
"id": 0,
"jsonrpc": "2.0",
"method": "shh_version",
"params": []
}

响应:

1
2
3
4
5
6
7
8
{
"error": {
"code": -32601,
"message": "the method shh_version does not exist/is not available"
},
"id": 0,
"jsonrpc": "2.0"
}

❌shh_post

发送whisper消息。不可用。

请求:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
{
"id": 0,
"jsonrpc": "2.0",
"method": "shh_post",
"params": [
{
"payload": "0x7b2274797065223a226d6",
"priority": "0x64",
"topics": [
"0x776869737065722d636861742d636c69656e74",
"0x4d5a695276454c39425154466b61693532"
],
"ttl": "0x64"
}
]
}

响应:

1
2
3
4
5
6
7
8
{
"error": {
"code": -32601,
"message": "the method shh_post does not exist/is not available"
},
"id": 0,
"jsonrpc": "2.0"
}

❌shh_newIdentity

在客户端创建一个新的whisper身份标识。不可用。

请求:

1
2
3
4
5
6
{
"id": 0,
"jsonrpc": "2.0",
"method": "shh_newIdentity",
"params": []
}

响应:

1
2
3
4
5
6
7
8
{
"error": {
"code": -32601,
"message": "the method shh_newIdentity does not exist/is not available"
},
"id": 0,
"jsonrpc": "2.0"
}

❌shh_hasIdentity

检查客户端是否持有指定身份标识的私钥。不可用。

❌shh_newGroup

创建分组。不可用。

❌shh_addToGroup

将指定身份标识加入分组。 不可用。

❌shh_newFilter

创建一个过滤器,以便在客户端接收到匹配的whisper消息时进行通知。 不可用。

❌shh_uninstallFilter

卸载指定编号的过滤器 不可用。

❌shh_getFilterChanges

询问Whisper过滤器,返回自上次询问后的新消息。 不可用。

❌shh_getMessages

读取指定过滤器的所有消息。 不可用。