cfx 命名空间
JSON-RPC规范说明
在GitHub上有一个cfx命名空间的JSON-RPC API规范。 您可以在open-rpc playground中查看它。
惯例
十六进制值编码
有两种关键的数据类型通过 JSON 传递:未格式化的字节数组和数量。 二者都使用十六进制编码传递,但对格式化有不同的要求。
数值
当编码数值(整数,数字)时:使用最紧凑的表示方式编码为十六进制,并加上“0x”
前缀。 零应表示为"0x0"
。 例如:
0x41
(十进制的 65)0x400
(十进制的 1024)- 错误样例:
0x
(应该至少有一位数字 - 零是“0x0”
) - 错误样例:
0x0400
(不允许有前导零) - 错误样例::
ff
(缺少0x
前缀)
未格式化的数据
当编码未格式化的数据(字节数组、哈希值、字节码数组)时:使用两个十六进制数字表示每个字节,并在前面加上“0x”
作为前缀。 例如:
0x41
(size 1,"A"
)0x004200
(size 3,"\0B\0"
)0x
(size 0,""
)- 错误:
0xf0f0f
(必须是偶数位数)。 - 错误:
004200
(缺少0x
前缀)。
请注意,区块和交易的哈希值是用32个字节来表示的。
Base32 地址
BASE32
:Base32 地址应该编码为一个ASCII字符串,包含42个字符加上网络前缀、分隔符和可选字段。 请注意以下关于base32地址作为RPC参数的限制条件:
- 网络前缀应该与节点的网络匹配,例如:
cfx:acc7uawf5ubtnmezvhu9dhc6sghea0403y2dgpyfjp
可以发送给主网节点,cfxtest:acc7uawf5ubtnmezvhu9dhc6sghea0403ywjz6wtpg
可以发送给测试网节点。 值得注意的是,这两个示例地址对应于不同网络上的同一个账户。 - 无论包含还是省去地址类型都是可以接受的,例如:
cfx:aarc9abycue0hhzgyrr53m6cxedgccrmmyybjgh4xg
和cfx:type.user:aarc9abycue0hhzgyrr53m6cxedgccrmmyybjgh4xg
是等价的。 但是,类型不正确的地址,例如:cfx:type.contract:aarc9abycue0hhzgyrr53m6cxedgccrmmyybjgh4xg
,会被拒绝。 - 全大写或者全小写地址都是可以接受的,例如:
cfx:aarc9abycue0hhzgyrr53m6cxedgccrmmyybjgh4xg
和CFX:AARC9ABYCUE0HHZGYRR53M6CXEDGCCRMMYYBJGH4XG
都是有效的。 但混合大小写地址会被拒绝。
为获取更多关于 Base32 地址的信息,请参阅 地址。
默认的 epochNumber (纪元数) 参数
有几个RPC方法有一个epoch number参数。 Epoch的概念在Conflux中有点类似于其他账本中的区块号(高度),但是一个epoch可能包含多个区块。
Epoch number指定了在一个时间点时,系统的相应状态,这些状态受到共识的约束。 Epoch number参数有以下几种可能的选项:
HEX String
- 整数纪元数。 例如,0x3e8
是epoch 1000。String “earliest”
表示创世区块的epoch。String “latest_checkpoint”
表示存储在内存中的最早的epoch。String “latest_finalized”
- 表示最新的已经确定(通过PoS)的epoch。 (添加自conflux-rustv2.0.0
)String “latest_confirmed”
- 表示最新的已经确认的epoch(使用确认计量器的估计值)。string "latest_state"
- 表示已经执行的最新纪元。String “latest_mined”
- 表示最新的已知epoch。
请注意,由于性能优化,最新的已知epoch没有被执行,所以这些epoch没有可用的状态。 对于大多数与状态查询有关的RPC,推荐使用"latest_state"
。 (有关Conflux中交易生命周期的更多信息,请参考交易生命周期)
遵循 EIP-1898 的Conflux epochNumber 参数
Conflux core space 支持纪元数参数在 EIP-1898 样式中为某些RPC 服务。 EIP-1898 样式的纪元参数是一个包含3个可选字段的对象:
epochNumber
. 对应于EIP-1898定义的blockNumber
。blockHash
. 与EIP-1898的blockHash
相同。requirePivot
. 对应于EIP-1898的requireCanonical
。 默认值为true
例如:
{
"blockHash": "0x692373025c7315fa18b2d02139d08e987cd7016025920f59ada4969c24e44e06",
"requirePivot": false
}
EIP-1898中的纪元号参数现在可用于以下RPC:
CURL 请求示例
下面提供了通过向Conflux节点发出 curl 请求来使用 JSON_RPC 应用程序接口的示例。 每个示例都包括对特定端点、其参数、返回类型的描述,以及应该如何使用它的工作示例。
Curl 请求可能会返回与内容类型相关的错误消息。 这是因为 --data
选项将内容类型设置为 application/x-www-form-urlencoded
。 如果你的节点确实抱怨此问题,请通过在调用开始时放置 -H "Content-Type: application/json"
来手动设置标头。 这些示例也未包括网址/互联网协议与端口组合,该组合必须是 curl 的最后一个参数(例如 127.0.0.1:12537
)。 包含这些附加数据的完整 curl 请求采用以下形式:
$ curl -H "Content-Type: application/json" -X POST --data '{"jsonrpc":"2.0","method":"cfx_clientVersion","params":[],"id":67}' 127.0.0.1:12537
本文档剩余部分的示例将使用 HTTP endpoint。
状态和交易可用性
Conflux的归档节点和全节点会删除历史状态树,以减少存储空间的占用。 全节点也会丢弃历史区块的交易和收据。 因此,一些RPC接口可能无法用于历史查询。
下面是Conflux RPC API的列表,以及它们在归档节点和全节点上的可用性。 *“recent”表示该RPC只支持最近的项目,“OK”*表示它应该对任何有效的输入都能正常工作。
RPC | 归档节点 | 全节点 |
---|---|---|
cfx_call | recent | recent |
cfx_checkBalanceAgainstTransaction | recent | recent |
cfx_clientVersion | OK | OK |
cfx_epochNumber | OK | OK |
cfx_estimateGasAndCollateral | recent | recent |
cfx_gasPrice | OK | OK |
cfx_getAccount | recent | recent |
cfx_getAccumulateInterestRate | OK | OK |
cfx_getAdmin | recent | recent |
cfx_getBalance | recent | recent |
cfx_getBestBlockHash | OK | OK |
cfx_getBlockByEpochNumber | OK | recent |
cfx_getBlockByHash | OK | recent |
cfx_getBlockByHashWithPivotAssumption | OK | recent |
cfx_getBlockRewardInfo | OK | recent |
cfx_getBlocksByEpoch | OK | OK |
cfx_getCode | recent | recent |
cfx_getCollateralForStorage | recent | recent |
cfx_getConfirmationRiskByHash | OK | recent |
cfx_getDepositList | recent | recent |
cfx_getInterestRate | recent | recent |
cfx_getLogs | OK | recent |
cfx_getNextNonce | recent | recent |
cfx_getSkippedBlocksByEpoch | OK | OK |
cfx_getSponsorInfo | recent | recent |
cfx_getStakingBalance | recent | recent |
cfx_getStatus | OK | OK |
cfx_getStorageAt | recent | recent |
cfx_getStorageRoot | recent | recent |
cfx_getTransactionByHash | OK | recent |
cfx_getTransactionReceipt | OK | recent |
cfx_getVoteList | recent | recent |
cfx_sendRawTransaction | OK | OK |
如果您查询的状态条目在节点上不可用,您将收到错误响应:
// Request
curl -X POST --data '{"jsonrpc":"2.0","method":"cfx_getBalance","params":["cfx:type.user:aarc9abycue0hhzgyrr53m6cxedgccrmmyybjgh4xg", "earliest"],"id":1}' -H "Content-Type: application/json" localhost:12539
// Result
{
"jsonrpc": "2.0",
"error": {
"code": -32016,
"message": "Error processing request: State for epoch (number=0 hash=0x24dcc768132dc7f651d7cb35c52e7bba632eda073d8743f81cfe905ff7e4157a) does not exist: out-of-bound StateAvailabilityBoundary { synced_state_height: 0, lower_bound: 9510001, upper_bound: 9569393, optimistic_executed_height: Some(9569392) }"
},
"id": 1
}
在这个例子中,我们被告知最早可用的状态是在纪元9510001
(0x911c71
)处。
从以太坊 JSON-RPC 迁移
以太坊和 Conflux 的一些 JSON-RPC 有对应关系。 即使 JSON-RPC 的细节可能有所不同,但以下映射表在从以太坊迁移到 Conflux 时可能会有所帮助:
以太坊 | Conflux |
---|---|
eth_blockNumber | cfx_epochNumber |
eth_call | cfx_call |
eth_estimateGas | cfx_estimateGasAndCollateral |
eth_gasPrice | cfx_gasPrice |
eth_getBalance | cfx_getBalance |
eth_getBlockByHash | cfx_getBlockByHash |
eth_getBlockByNumber | cfx_getBlockByEpochNumber |
eth_getCode | cfx_getCode |
eth_getLogs | cfx_getLogs |
eth_getStorageAt | cfx_getStorageAt |
eth_getTransactionByHash | cfx_getTransactionByHash |
eth_getTransactionCount | cfx_getNextNonce |
eth_getTransactionrecipt | cfx_getTransactionReceipt |
eth_sendRawTransaction | cfx_sendRawTransaction |
GOSSIP, STATE, HISTORY
一些核心的 JSON-RPC 方法需要从 Conflux 网络获取数据,它们可以分为三个主要类别:Gossip, State 和 History。 你可以使用这些部分中的链接跳转到每个方法,或者使用目录来浏览所有方法的列表。
Gossip 方法
这些方法跟踪链的头部。 这是交易在网络中传播、进入区块的方式,以及客户端发现新区块的方式。
- cfx_getStatus
- cfx_epochNumber
- cfx_sendRawTransaction
State 方法
这些方法报告存储的所有数据的当前状态。 “状态”就像一块大的共享内存,包括账户余额、合约数据和 gas 估算。
- cfx_getBalance
- cfx_getStorageAt
- cfx_getNonce
- cfx_getCode
- cfx_call
- cfx_estimateGasAndCollateral
History 方法
获取从创世区块开始的每个区块的历史记录。 这就像一个大型的只追加文件,包括所有区块头、区块体和交易收据。
- cfx_getBlockByHash
- cfx_getBlockByEpochNumber
- cfx_getTransactionByHash
- cfx_getTransactionReceipt
JSON-RPC 方法
cfx_getTransactionByHash
返回关于一个交易的信息,通过它的哈希来识别。
参数
DATA
,32 字节 - 交易的哈希。
params: [
"0x88df016429689c079f3b2f6ad39fa052532c56795b733da78a91ebe6a713944b"
]
返回值
Object
- 交易对象,如果没有找到交易,则为 null
:
blockHash
:DATA
, 32 字节 - 包含并执行了这个交易的区块的哈希。null
当交易是 pending 时为 nullchainId
:QUANTITY
- 发送者指定的链 IDcontractCreated
:BASE32
- 创建的合约的地址。null
当它不是一个合约部署交易时为 nulldata
:DATA
- 随交易发送的数据。epochHeight
:QUANTITY
- 发送者指定的 epoch。 注意这不是包含这个交易的区块的 epoch。from
:BASE32
- 发送者的地址。gas
:QUANTITY
- 发送者提供的 gas。gasPrice
:QUANTITY
- 发送者以 Drip 为单位提供的 gas 价格。hash
:DATA
, 32 Bytes - 交易的哈希。nonce
:QUANTITY
- 发送者在这之前发送的交易数量。r
:DATA
, 32 字节 - ECDSA 签名 rs
:DATA
, 32 字节 - ECDSA 签名 sstatus
:QUANTITY
- 0 表示成功,1 表示发生错误,2 表示跳过,null
null 表示交易被跳过或未打包storageLimit
:QUANTITY
- 发送者指定的存储限制。to
:BASE32
- 接收者的地址。null
when it is a contract deployment transaction.transactionIndex
:QUANTITY
- the transaction's position in the block.null
当交易是 pending 时为 nullv
:QUANTITY
- ECDSA recovery id.value
:QUANTITY
- value transferred in Drip.
注意,字段 blockHash
, contractCreated
, status
和 transactionIndex
是由节点提供的,因为它们依赖于交易在账本中的位置。 其余的字段是包含在原始交易中或从原始交易中派生出来的。
示例
// Request
curl -X POST --data '{"jsonrpc":"2.0","method":"cfx_getTransactionByHash","params":["0x497755f45baef13a35347933c48c0b8940f2cc3347477b5ed9f165581b082699"],"id":1}' -H "Content-Type: application/json" localhost:12539
// Result
{
"jsonrpc": "2.0",
"result": {
"blockHash": "0x564750c06c7afb10de8beebcf24411cc73439295d5abb1264d2c9b90eee5606f",
"chainId": "0x2",
"contractCreated": null,
"data": "0x0",
"epochHeight": "0x909c9f",
"from": "CFX:TYPE.USER:AARC9ABYCUE0HHZGYRR53M6CXEDGCCRMMYYBJGH4XG",
"gas": "0xf4240",
"gasPrice": "0x174876e800",
"hash": "0x497755f45baef13a35347933c48c0b8940f2cc3347477b5ed9f165581b082699",
"nonce": "0x3b518",
"r": "0x14da6cff1a3cd864b04d1b16f480fa023f449322e318b04bb1109b5754b516ce",
"s": "0x304070abe6488c3532ecb66f4be32b88ee35ce48a4607b8d0c86461987a79fc7",
"status": "0x0",
"storageLimit": "0x100",
"to": "CFX:TYPE.CONTRACT:ACC7UAWF5UBTNMEZVHU9DHC6SGHEA0403Y2DGPYFJP",
"transactionIndex": "0x0",
"v": "0x1",
"value": "0x3635c9adc5dea00000"
},
"id": 1
}
cfx_getBlockByHash
返回关于一个区块的信息,通过它的哈希来识别。
参数
DATA
,32 字节 - 区块的哈希。Boolean
- 如果true
,返回完整的交易对象 如果false
, 只返回交易的哈希值
params: [
"0xe670ec64341771606e55d6b4ca35a1a6b75ee3d5145a99d05921026d1527331",
true
]
返回值
Object
- 区块对象,或 null
(当没有找到区块时):
adaptive
:Boolean
-true
则该区块在 GHAST 规则下的权重是自适应的。blame
:QUANTITY
- 如果为 0,则该区块不责怪其父路径上的任何区块。 如果n > 0
, 则该区块责怪其父路径上的n
n 个前任,例如, 当n = 1
, 则该区块责怪其父区块,但不责怪其父区块的父区块。deferredLogsBloomHash
:DATA
, 32 Bytes - 在该区块所在 epoch 的延迟执行后的事件地址和事件topic的布隆滤波器的哈希(假设它是主区块)。deferredReceiptsRoot
:DATA
, 32 Bytes - 在该区块所在 epoch 的延迟执行后的收据的 Merkle 根(假设它是枢轴区块)。deferredStateRoot
:DATA
, 32 Bytes - 在该区块所在 epoch 的延迟执行后的状态 trie 根三元组的哈希(假设它是枢轴区块)。difficulty
:QUANTITY
- the PoW difficulty of this block.epochNumber
:QUANTITY
- the number of the epoch containing this block in the node's view of the ledger.null
when the epoch number is not determined (e.g. the block is not in the best block's past set).gasLimit
:QUANTITY
- the maximum gas allowed in this block.gasUsed
:QUANTITY
- the total gas used in this block.null
when the block is pending.hash
:DATA
, 32 Bytes - hash of the block.height
:QUANTITY
- the height of the block.miner
:BASE32
- the address of the beneficiary to whom the mining rewards were given.nonce
:DATA
, 8 Bytes - hash of the generated proof-of-work.parentHash
:DATA
, 32 Bytes - hash of the parent block.powQuality
:DATA
- the PoW quality.null
when the block is pending.refereeHashes
:Array
- array of referee block hashes.size
:QUANTITY
- the size of this block in bytes, excluding the block header.timestamp
:QUANTITY
- the unix timestamp for when the block was created.transactions
:Array
- array of transaction objects, or 32-byte transaction hashes, depending on the second parameter.transactionsRoot
:DATA
, 32 Bytes - the Merkle root of the transactions in this block.custom
:Array
- customized information. Note from v2.0custom
's type has changed from array ofnumber array
to array ofhex string
.blockNumber
:QUANTITY
- the number of this block's total order in the tree-graph.null
when the order is not determined. Added fromConflux-rust v1.1.5
posReference
:DATA
, 32 Bytes - the hash of the PoS newest committed block. Added fromConflux-rust v2.0.0
Note that the fields epochNumber
and gasUsed
are provided by the node as they depend on the ledger. The rest of the fields are included in or derived from the block header directly.
示例
// Request
curl -X POST --data '{"jsonrpc":"2.0","method":"cfx_getBlockByHash","params":["0x692373025c7315fa18b2d02139d08e987cd7016025920f59ada4969c24e44e06", false],"id":1}' -H "Content-Type: application/json" localhost:12539
// Result
{
"jsonrpc": "2.0",
"result": {
"adaptive": false,
"blame": 0,
"deferredLogsBloomHash": "0xd397b3b043d87fcd6fad1291ff0bfd16401c274896d8c63a923727f077b8e0b5",
"deferredReceiptsRoot": "0x522717233b96e0a03d85f02f8127aa0e23ef2e0865c95bb7ac577ee3754875e4",
"deferredStateRoot": "0xd449df4ba49f5ab02abf261e976197beecf93c5198a6f0b6bd2713d84115c4ec",
"difficulty": "0xeee440",
"epochNumber": "0x1394cb",
"gasLimit": "0xb2d05e00",
"gasUsed": "0xad5ae8",
"hash": "0x692373025c7315fa18b2d02139d08e987cd7016025920f59ada4969c24e44e06",
"height": "0x1394c9",
"miner": "CFX:TYPE.USER:AARC9ABYCUE0HHZGYRR53M6CXEDGCCRMMYYBJGH4XG",
"nonce": "0x329243b1063c6773",
"parentHash": "0xd1c2ff79834f86eb4bc98e0e526de475144a13719afba6385cf62a4023c02ae3",
"powQuality": "0x2ab0c3513",
"refereeHashes": [
"0xcc103077ede14825a5667bddad79482d7bbf1f1a658fed6894fa0e9287fc6be1"
],
"size": "0x180",
"timestamp": "0x5e8d32a1",
"transactions": [
"0xedfa5b9c38ba51e791cc72b8f75ff758533c8c38f426eddee3fd95d984dd59ff"
],
"custom": ["0x12"],
"transactionsRoot": "0xfb245dae4539ea49812e822adbffa9dd2ee9b3de8f3d9a7d186d351dcc9a6ed4",
"posReference": "0xd1c2ff79834f86eb4bc98e0e526de475144a13719afba6385cf62a4023c02ae3",
},
"id": 1
}
cfx_getBlockByEpochNumber
返回一个区块的信息,该区块由它的纪元号(epoch number)标识。
参数
QUANTITY|TAG
- 纪元号,或字符串"latest_mined"
、"latest_state"
、"latest_confirmed"
、"latest_checkpoint"
或"earliest"
,请参见纪元号参数。Boolean
- 如果true
,返回完整的交易对象 Iffalse
, only the hashes of the transactions are returned
params: [
"latest_mined",
true
]
返回值
See cfx_getBlockByHash.
示例
// Request
curl -X POST --data '{"jsonrpc":"2.0","method":"cfx_getBlockByEpochNumber","params":["latest_mined", false],"id":1}' -H "Content-Type: application/json" localhost:12539
结果参见 cfx_getBlockByHash.
cfx_getBestBlockHash
返回最佳区块的哈希值。
参数
无。
返回值
DATA
, 32 Bytes - hash of the best block.
示例
// Request
curl -X POST --data '{"jsonrpc":"2.0","method":"cfx_getBestBlockHash","id":1}' -H "Content-Type: application/json" localhost:12539
// Result
{
"jsonrpc" : "2.0",
"result" : "0x7d54c03f4fe971d5c45d95dddc770a0ec8d5bd27d57c049ce8adc469269e35a4",
"id" : 1
}
cfx_epochNumber
返回给定标签对应的纪元号。
参数
TAG
- (optional, default:"latest_mined"
) String"latest_mined"
,"latest_state"
,"latest_confirmed"
,"latest_checkpoint"
or"earliest"
, see the epoch number parameter.
返回值
QUANTITY
- the integer epoch number corresponding to the given tag.
示例
// Request
curl -X POST --data '{"jsonrpc":"2.0","method":"cfx_epochNumber","params":["latest_mined"],"id":1}' -H "Content-Type: application/json" localhost:12539
// Result
{
"jsonrpc" : "2.0",
"result" : "0x49",
"id" : 1
}
cfx_gasPrice
返回当前每单位gas的价格,单位为Drip。
参数
无。
返回值
QUANTITY
- 当前 Gas 价格的整数表示,单位为 Drip。
示例
// Request
curl -X POST --data '{"jsonrpc":"2.0","method":"cfx_gasPrice","id":1}' -H "Content-Type: application/json" localhost:12539
// Result
{
"jsonrpc" : "2.0",
"result" : "0x09184e72a000",
"id" : 1
}
cfx_getBlocksByEpoch
返回指定纪元中的区块哈希值。
参数
QUANTITY|TAG
- 纪元号,或字符串"latest_mined"
、"latest_state"
、"latest_confirmed"
、"latest_checkpoint"
或"earliest"
,请参见纪元号参数。
返回值
数组
- 区块哈希的数组,按照它们的执行(拓扑)顺序排序。 请注意,最后一个哈希值是主轴哈希。
示例
// Request
curl -X POST --data '{"jsonrpc":"2.0","method":"cfx_getBlocksByEpoch","params":["0x11"],"id":1}' -H "Content-Type: application/json" localhost:12539
// Result
{
"jsonrpc": "2.0",
"result": [
"0x618e813ed93f1020bab13a1ab77e1550da6c89d9c69de837033512e91ac46bd0",
"0x0f6ac81dcbc612e72e0019681bcec32254a34bd29a6bbab91e5e8dc37ecb64d5",
"0xad3238c00456adfbf847d251b004c1e306fe637227bb1b9917d77bd5b207af68",
"0x0f92c2e796be7b016d8b74c6c270fb1851e47fabaca3e464d407544286d6cd34",
"0x5bcc2b8d2493797fcadf7b80228ef5b713eb9ff65f7cdd86562db629d0caf721",
"0x7fcdc6fff506b19a2bd72cd3430310915f19a59b046759bb790ba4eeb95e9956",
"0xf4f33ed08e1c625f4dde608eeb92991d77fff26122bab28a6b3a2037511dcc83",
"0xa3762adc7f066d5cb62c683c2655be3bc3405ff1397f77d2e1dbeff2d8522e00",
"0xba7588476a5ec7e0ade00f060180cadb7430fd1be48940414baac48c0d39556d",
"0xe4dc4541d07118b598b2ec67bbdaa219eb1d649471fe7b5667a0001d83b1e9b6",
"0x93a15564544c57d6cb68dbdf60133b318a94439e1f0a9ccb331b0f5a0aaf8049"
],
"id": 1
}
cfx_getBalance
返回给定账户的余额,该账户由它的地址标识。
参数
BASE32
- address to check for balance.QUANTITY|TAG
- (optional, default:"latest_state"
) integer epoch number, or the string"latest_state"
,"latest_confirmed"
,"latest_checkpoint"
or"earliest"
, see the epoch number parameter
params: [
"cfx:type.user:aarc9abycue0hhzgyrr53m6cxedgccrmmyybjgh4xg",
"latest_state"
]
返回值
QUANTITY
- 当前余额的整数表示,单位为 Drip。
示例
// Request
curl -X POST --data '{"jsonrpc":"2.0","method":"cfx_getBalance","params":["cfx:type.user:aarc9abycue0hhzgyrr53m6cxedgccrmmyybjgh4xg", "latest_state"],"id":1}' -H "Content-Type: application/json" localhost:12539
// Result
{
"jsonrpc": "2.0",
"result": "0x0234c8a3397aab58", // 158972490234375000
"id": 1
}
cfx_getStakingBalance
返回给定账户的质押余额,该账户由它的地址标识。
参数
BASE32
- 用于检查质押余额的地址,采用 base32 编码。QUANTITY|TAG
- (可选,默认为"latest_state"
)整数纪元号,或字符串"latest_state"
、"latest_confirmed"
、"latest_checkpoint"
或"earliest"
,详见 纪元号参数。
params: [
"cfx:type.user:aarc9abycue0hhzgyrr53m6cxedgccrmmyybjgh4xg",
"latest_state"
]
返回值
QUANTITY
- integer of the current staking balance in Drip.
示例
// Request
curl -X POST --data '{"jsonrpc":"2.0","method":"cfx_getStakingBalance","params":["cfx:type.user:aarc9abycue0hhzgyrr53m6cxedgccrmmyybjgh4xg", "latest_state"],"id":1}' -H "Content-Type: application/json" localhost:12539
// Result
{
"jsonrpc": "2.0",
"result": "0x0234c8a3397aab58", // 158972490234375000
"id": 1
}
cfx_getCollateralForStorage
返回给定地址的抵押存储的大小,单位为字节。
参数
BASE32
- 要检查抵押存储的地址。QUANTITY|TAG
- (可选,默认为"latest_state"
)整数纪元号,或字符串"latest_state"
、"latest_confirmed"
、"latest_checkpoint"
或"earliest"
,详见 纪元号参数。
params: [
"cfx:type.user:aarc9abycue0hhzgyrr53m6cxedgccrmmyybjgh4xg",
"latest_state"
]
返回值
QUANTITY
- integer of the collateral storage in Byte.
示例
// Request
curl -X POST --data '{"jsonrpc":"2.0","method":"cfx_getCollateralForStorage","params":["cfx:type.user:aarc9abycue0hhzgyrr53m6cxedgccrmmyybjgh4xg", "latest_state"],"id":1}' -H "Content-Type: application/json" localhost:12539
// Result
{
"jsonrpc": "2.0",
"result": "0x0234c8a8",
"id": 1
}
cfx_getAdmin
返回指定合约的管理员。
参数
BASE32
- 合约地址QUANTITY|TAG
- (可选,默认为"latest_state"
)整数纪元号,或字符串"latest_state"
、"latest_confirmed"
、"latest_checkpoint"
或"earliest"
,详见 纪元号参数。
params: [
"cfx:type.contract:acc7uawf5ubtnmezvhu9dhc6sghea0403y2dgpyfjp",
"latest_state"
]
返回值
BASE32
- address of admin, or null
if the contract does not exist.
Although meaningless, it is also possible to use user address as the input parameter of cfx_getAdmin
method. In this case, the return value will be zero address if the input user address exists in the world state, else null
will be returned.
示例
// Request
curl -X POST --data '{"jsonrpc":"2.0","method":"cfx_getAdmin","params":["cfx:type.contract:acc7uawf5ubtnmezvhu9dhc6sghea0403y2dgpyfjp"],"id":1}' -H "Content-Type: application/json" localhost:12539
// Result
{
"jsonrpc": "2.0",
"result": "CFX:TYPE.USER:AARC9ABYCUE0HHZGYRR53M6CXEDGCCRMMYYBJGH4XG",
"id": 1
}
cfx_getCode
返回指定合约的代码。 如果合约不存在,将返回0x0
。
参数
BASE32
- 合约地址QUANTITY|TAG
- (可选,默认为"latest_state"
)整数纪元号,或字符串"latest_state"
、"latest_confirmed"
、"latest_checkpoint"
或"earliest"
,详见 纪元号参数。
params: [
"cfx:type.contract:acc7uawf5ubtnmezvhu9dhc6sghea0403y2dgpyfjp",
"latest_state"
]
返回值
DATA
- byte code of the contract, or 0x
if the account has no code.
示例
// Request
curl -X POST --data '{"jsonrpc":"2.0","method":"cfx_getCode","params":["cfx:type.contract:acc7uawf5ubtnmezvhu9dhc6sghea0403y2dgpyfjp","latest_state"],"id":1}' -H "Content-Type: application/json" localhost:12539
// Result
{
"jsonrpc": "2.0",
"result": "0x6080604052600436106100705760003560e01c80638da5cb5b1161004e5780638da5cb5b14610146578063a035b1fe14610",
"id": 1
}
cfx_getStorageAt
返回给定合约的存储条目。
参数
BASE32
- 合约地址QUANTITY
- a storage position (see here for more info).QUANTITY|TAG
- (可选,默认为"latest_state"
)整数纪元号,或字符串"latest_state"
、"latest_confirmed"
、"latest_checkpoint"
或"earliest"
,详见 纪元号参数。
params: [
"cfx:type.contract:acc7uawf5ubtnmezvhu9dhc6sghea0403y2dgpyfjp",
"0x100",
"latest_state"
]
返回值
DATA
- 32 Bytes - the contents of the storage position, or null
if the contract does not exist.
示例
// Request
curl -X POST --data '{"jsonrpc":"2.0","method":"cfx_getStorageAt","params":["cfx:type.contract:acc7uawf5ubtnmezvhu9dhc6sghea0403y2dgpyfjp","0x100","latest_state"],"id":1}' -H "Content-Type: application/json" localhost:12539
// Result
{
"jsonrpc": "2.0",
"result": "0x0000000000000000000000001dbda5dd2e952914bc74a802510d0fa59f9d7636",
"id": 1
}
cfx_getStorageRoot
返回给定合约的存储根。
参数
BASE32
- address of the contract.QUANTITY|TAG
- (optional, default:"latest_state"
) integer epoch number, or the string"latest_state"
,"latest_confirmed"
,"latest_checkpoint"
or"earliest"
, see the epoch number parameter
params: [
"cfx:type.contract:acc7uawf5ubtnmezvhu9dhc6sghea0403y2dgpyfjp",
"latest_state"
]
返回值
Object
- A storage root object, or null
if the contract does not exist:
delta
:DATA
, 32 Bytes - the storage root in the delta trie, or the string"TOMBSTONE"
, ornull
.intermediate
:DATA
, 32 Bytes - storage root in the intermediate trie, or the string"TOMBSTONE"
, ornull
.snapshot
:DATA
, 32 Bytes - storage root in the snapshot, or the string"TOMBSTONE"
, ornull
.
If all three of these fields match for two invocations of this RPC, the contract's storage is guaranteed to be identical. If they do not match, storage has likely changed (or the system transitioned into a new era).
示例
// Request
curl -X POST --data '{"jsonrpc":"2.0","method":"cfx_getStorageRoot","params":["cfx:type.contract:acc7uawf5ubtnmezvhu9dhc6sghea0403y2dgpyfjp","latest_state"],"id":1}' -H "Content-Type: application/json" localhost:12539
// Result
{
"jsonrpc": "2.0",
"result": {
"delta": "0x0240a5a3486ac1cee71db22b8e12f1bb6ac9f207ecd81b06031c407663c20a94",
"intermediate": "0x314a41f277b678a1dc811a1fc0393b6d30c35e900cb27762ec9e9042bfdbdd49",
"snapshot": "0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470"
},
"id" :1
}
cfx_getSponsorInfo
返回给定合约的赞助者信息。
参数
BASE32
- address of the contract.QUANTITY|TAG
- (optional, default:"latest_state"
) integer epoch number, or the string"latest_state"
,"latest_confirmed"
,"latest_checkpoint"
or"earliest"
, see the epoch number parameter
params: [
"cfx:type.contract:acc7uawf5ubtnmezvhu9dhc6sghea0403y2dgpyfjp",
"latest_state"
]
返回值
Object
- A sponsor info object. If the contract doesn't have a sponsor, then all fields in the object returned will be 0
:
sponsorBalanceForCollateral
:QUANTITY
- the sponsored balance for storage.sponsorBalanceForGas
:QUANTITY
- the sponsored balance for gas.sponsorGasBound
:QUANTITY
- the max gas that could be sponsored for one transaction.sponsorForCollateral
:BASE32
- the address of the storage sponsor.sponsorForGas
:BASE32
- the address of the gas sponsor.usedStoragePoints
:QUANTITY
- storage points already used.availableStoragePoints
:QUANTITY
- the storage points available for sponsorship.
Hard fork v2.3 provides the introduction for storage points. Refer to CIP-107 for the detailed explanation.
示例
// Request
curl -X POST --data '{"jsonrpc":"2.0","method":"cfx_getSponsorInfo","params":["cfx:type.contract:acc7uawf5ubtnmezvhu9dhc6sghea0403y2dgpyfjp"],"id":1}' -H "Content-Type: application/json" localhost:12539
// Result
{
"jsonrpc": "2.0",
"result": {
"sponsorBalanceForCollateral": "0x0",
"sponsorBalanceForGas": "0x0",
"sponsorForCollateral": "CFX:TYPE.NULL:AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA0SFBNJM2",
"sponsorForGas": "CFX:TYPE.NULL:AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA0SFBNJM2",
"sponsorGasBound": "0x0"
},
"id": 1
}
cfx_getNextNonce
返回给定账户在发送交易时应该使用的下一个nonce值。
参数
BASE32
- address of the account.QUANTITY|TAG
- (optional, default:"latest_state"
) integer epoch number, or the string"latest_state"
,"latest_confirmed"
,"latest_checkpoint"
or"earliest"
, see the epoch number parameter
params: [
"cfx:type.user:aarc9abycue0hhzgyrr53m6cxedgccrmmyybjgh4xg",
"latest_state"
]
返回值
QUANTITY
- integer of the next nonce that should be used by the given address.
示例
// Request
curl -X POST --data '{"jsonrpc":"2.0","method":"cfx_getNextNonce","params":["cfx:type.user:aarc9abycue0hhzgyrr53m6cxedgccrmmyybjgh4xg", "latest_state"],"id":1}' -H "Content-Type: application/json" localhost:12539
// Result
{
"jsonrpc" : "2.0",
"result" : "0xe3269d",
"id" : 1
}
cfx_sendRawTransaction
发送一个已签名的交易到网络中进行处理。
参数
DATA
, the signed transaction data.
params: [
"0xf86eea8201a28207d0830f4240943838197c0c88d0d5b13b67e1bfdbdc132d4842e389056bc75e2d631000008080a017b8b26f473820475edc49bd153660e56b973b5985bbdb2828fceacb4c91f389a03452f9a69da34ef35acc9c554d7b1d63e9041141674b42c3abb1b57b9f83a2d3"
]
返回值
DATA
, 32 Bytes - the transaction hash.
常见错误
Check send raw transaction errors for details.
示例
// Request
curl -X POST --data '{"jsonrpc":"2.0","method":"cfx_sendRawTransaction","params":[{see above}],"id":1}' -H "Content-Type: application/json" localhost:12539
// Result
{
"jsonrpc": "2.0",
"result": "0xf5338a6cb85d10acc9108869f94fe322b2dfa2715d16d264676c91f6a0404b61",
"id": 1
}
cfx_call
虚拟地调用一个合约,返回输出数据。 The transaction will not be added to the blockchain. The error message of cfx_call
is similar to cfx_estimateGasAndCollateral
and error solutions can be found in cfx_estimateGasAndCollateral behaviour#errors.
参数
-
Object
- a call request object:from
:BASE32
- (optional, default: random address) address of sender.to
:BASE32
- (optional, default:null
for contract creation) address of receiver.gasPrice
:QUANTITY
- (optional, default:0
) gas price provided by the sender in Drip.gas
:QUANTITY
- (optional, default:500000000
) gas provided by the sender.value
:QUANTITY
- (optional, default:0
) value transferred in Drip.data
:DATA
- (optional, default:0x
) the data send along with the transaction.nonce
:QUANTITY
- (optional, default:0
) the number of transactions made by the sender prior to this one.
-
QUANTITY|TAG
- (optional, default:"latest_state"
) integer epoch number, or the string"latest_state"
,"latest_confirmed"
,"latest_checkpoint"
or"earliest"
, see the epoch number parameter
params: [
{
"from": "cfx:type.user:aarc9abycue0hhzgyrr53m6cxedgccrmmyybjgh4xg",
"to": "cfx:type.contract:acc7uawf5ubtnmezvhu9dhc6sghea0403y2dgpyfjp",
"data": "0xa6f2ae3a",
"gasPrice": "0x2540be400",
"nonce": "0x0"
},
"latest_state"
]
返回值
DATA
, Bytes - the output data, or an execution error.
示例
// Request
curl -X POST --data '{"method":"cfx_call","id":1,"jsonrpc":"2.0","params":[{"from":"cfx:type.user:aarc9abycue0hhzgyrr53m6cxedgccrmmyybjgh4xg","to":"cfx:type.contract:acc7uawf5ubtnmezvhu9dhc6sghea0403y2dgpyfjp","data":"0xa6f2ae3a","gasPrice":"0x2540be400","nonce":"0x0"}]}' -H "Content-Type: application/json" localhost:12539
// Result
{
"jsonrpc": "2.0",
"result": "0x",
"id": 1
}