交易
原文:https://docs.elrond.com/sdk-and-tools/rest-api/transactions
将交易发送到区块链,并查询有关交易的信息。
发文发送交易
https://gateway.elrond.com/transaction/send
这个端点允许向区块链发送签名的交易。
RequestResponse 身体参数
参数 | 需要 | 类型 | 描述 |
---|---|---|---|
目前 | 必需的 | number |
发送者的随机数。 |
价值 | 必需的 | string |
要传输的值,以大整数的字符串形式表示(可以是“0”)。 |
听筒 | 必需的 | string |
接收者的地址(bech32)。 |
发报机 | 必需的 | string |
发件人的地址(bech32)。 |
senderUsername | OPTIONAL | string |
发送方用户名的 base64 字符串表示形式。 |
接收用户名 | OPTIONAL | string |
接收端用户名的 base64 字符串表示形式。 |
天然气价格 | 必需的 | number |
期望的天然气价格(每单位天然气)。 |
气体极限 | 必需的 | number |
消耗气体单位的最大数量。 |
数据 | OPTIONAL | string |
交易消息(数据)的 base64 字符串表示形式。 |
签名 | 必需的 | string |
交易的签名(十六进制编码)。 |
chainID | 必需的 | string |
链标识符。 |
版本 | 必需的 | number |
交易的版本(例如 1)。 |
选择 | OPTIONAL | number |
交易的选项(如 1)。 |
交易发送成功。返回一个交易哈希。
{
"data": {
"txHash": "6c41c71946b5b428c2cfb560e3ea425f8a00345de4bb2eb1b784387790914277"
},
"error": "",
"code": "successful"
}
🔴400:错误请求
无效的交易签名。
{
"data": null,
"error": "transaction generation failed: ed25519: invalid signature",
"code": "bad_request"
}
警告
对于节点(启用了 HTTP API 的观察者或验证者),这个端点只接受发送者在节点碎片中的交易。
这是一个请求的例子:
POST https://gateway.elrond.com/transaction/send HTTP/1.1
Content-Type: application/json
{
"nonce": 42,
"value": "100000000000000000",
"receiver": "erd1cux02zersde0l7hhklzhywcxk4u9n4py5tdxyx7vrvhnza2r4gmq4vw35r",
"sender": "erd1njqj2zggfup4nl83x0nfgqjkjserm7mjyxdx5vzkm8k0gkh40ezqtfz9lg",
"gasPrice": 1000000000,
"gasLimit": 70000,
"data": "Zm9vZCBmb3IgY2F0cw==", #base64 representation of "food for cats"
"signature": "93207c579bf57be03add632b0e1624a73576eeda8a1687e0fa286f03eb1a17ffb125ccdb008a264c402f074a360442c7a034e237679322f62268b614e926d10f",
"chainId": "1",
"version": 1
}
发文发送多笔交易
https://gateway.elrond.com/transaction/send-multiple
这个端点允许向区块链发送大量交易。
RequestResponse 身体参数
数组:
参数 | 需要 | 类型 | 描述 |
---|---|---|---|
目前 | 必需的 | number |
发送者的随机数。 |
价值 | 必需的 | string |
要传输的值,以大整数的字符串形式表示(可以是“0”)。 |
听筒 | 必需的 | string |
接收者的地址(bech32)。 |
发报机 | 必需的 | string |
发件人的地址(bech32)。 |
senderUsername | OPTIONAL | string |
发送方用户名的 base64 字符串表示形式。 |
接收用户名 | OPTIONAL | string |
接收端用户名的 base64 字符串表示形式。 |
天然气价格 | 必需的 | number |
期望的天然气价格(每单位天然气)。 |
气体极限 | 必需的 | number |
消耗气体单位的最大数量。 |
数据 | OPTIONAL | string |
交易消息(数据)的 base64 字符串表示形式。 |
签名 | 必需的 | string |
交易的签名(十六进制编码)。 |
chainID | 必需的 | string |
链标识符。 |
版本 | 必需的 | number |
交易的版本(例如 1)。 |
选择 | OPTIONAL | number |
交易的选项(如 1)。 |
大量交易已成功发送。
{
"data": {
"numOfSentTxs": 2,
"txsHashes": {
"0": "6c41c71946b5b428c2cfb560e3ea425f8a00345de4bb2eb1b784387790914277",
"1": "fa8195bae93d4609a6fc5972a7a6176feece39a6c4821acae2276701aee12fb0"
}
},
"error": "",
"code": "successful"
}
警告
对于节点(启用了 HTTP API 的观察者或验证者),这个端点只接受发送者在节点碎片中的交易。
这是一个请求的例子:
POST https://gateway.elrond.com/transaction/send-multiple HTTP/1.1
Content-Type: application/json
[
{
"nonce": 42,
"value": "100000000000000000",
"receiver": "erd1cux02zersde0l7hhklzhywcxk4u9n4py5tdxyx7vrvhnza2r4gmq4vw35r",
"sender": "erd1njqj2zggfup4nl83x0nfgqjkjserm7mjyxdx5vzkm8k0gkh40ezqtfz9lg",
"gasPrice": 1000000000,
"gasLimit": 70000,
"data": "Zm9vZCBmb3IgY2F0cw==", #base64 representation of "food for cats"
"signature": "93207c579bf57be03add632b0e1624a73576eeda8a1687e0fa286f03eb1a17ffb125ccdb008a264c402f074a360442c7a034e237679322f62268b614e926d10f",
"chainId": "1",
"version": 1
}
{
"nonce": 43,
"value": "100000000000000000",
"receiver": "erd1cux02zersde0l7hhklzhywcxk4u9n4py5tdxyx7vrvhnza2r4gmq4vw35r",
"sender": "erd1rhp4q3qlydyrrjt7dgpfzxk8n4f7yrat4wc6hmkmcnmj0vgc543s8h7hyl",
"gasPrice": 1000000000,
"gasLimit": 70000,
"data": "YnVzIHRpY2tldHM=", #base64 representation of "bus tickets"
"signature": "01535fd1d40d98b7178ccfd1729b3f526ee4542482eb9f591d83433f9df97ce7b91db07298b1d14308e020bba80dbe4bba8617a96dd7743f91ee4b03d7f43e00",
"chainID": "1",
"version": 1
}
]
过帐模拟交易
节点和观察者
https://gateway.elrond.com/transaction/simulate
该端点允许向区块链发送签名的交易,以模拟其执行。这对于在实际发送之前检查交易是否会成功执行非常有用。它接收与/transaction/send
端点相同的请求。
移动余额成功交易处理模拟
RequestResponse 身体参数
参数 | 需要 | 类型 | 描述 |
---|---|---|---|
目前 | 必需的 | number |
发送者的随机数。 |
价值 | 必需的 | string |
要传输的值,以大整数的字符串形式表示(可以是“0”)。 |
听筒 | 必需的 | string |
接收者的地址(bech32)。 |
发报机 | 必需的 | string |
发件人的地址(bech32)。 |
senderUsername | OPTIONAL | string |
发送方用户名的 base64 字符串表示形式。 |
接收用户名 | OPTIONAL | string |
接收端用户名的 base64 字符串表示形式。 |
天然气价格 | 必需的 | number |
期望的天然气价格(每单位天然气)。 |
气体极限 | 必需的 | number |
消耗气体单位的最大数量。 |
数据 | OPTIONAL | string |
交易消息(数据)的 base64 字符串表示形式。 |
签名 | 必需的 | string |
交易的签名(十六进制编码)。 |
chainID | 必需的 | string |
链标识符。 |
版本 | 必需的 | number |
交易的版本(例如 1)。 |
选择 | OPTIONAL | number |
交易的选项(如 1)。 |
田 | 类型 | 描述 |
---|---|---|
状态 | 线 | 成功,失败... |
失败原因 | 线 | 错误消息 |
scResults 结果 | []ApiSmartContractResult | 智能合约结果的数组(如果有) |
收入 | []API 收据 | 收据的数组(如果有) |
混杂 | 线 | 交易的哈希 |
❕注意到,空字段不会包含在响应中。这可以从下面的例子中看出
🟢 200:好的
交易将会成功。
{
"data": {
"status": "success",
"hash": "bb24ccaa2da8cddd6a3a8eb162e6ff62ad4f6e1914d9aa0cacde6772246ca2dd"
},
"error": "",
"code": "successful"
}
🟢 200:模拟成功,但交易无法执行。
无效的交易签名。
{
"data": {
"status": "fail",
"failReason": "higher nonce in transaction",
"hash": "bb24ccaa2da8cddd6a3a8eb162e6ff62ad4f6e1914d9aa0cacde6772246ca2dd"
},
"error": "",
"code": "successful"
}
🔴400:错误请求
{
"data": null,
"error": "transaction generation failed: invalid chain ID",
"code": "bad_request"
}
代理
在代理端,如果要模拟的交易是一个跨片交易,那么响应格式将包含两个名为senderShard
和receiverShard
的元素,它们属于上面解释的SimulationResults
类型。
跨分片交易的响应示例:
{
"data": {
"receiverShard": {
"status": "success",
"hash": "bb24ccaa2da8cddd6a3a8eb162e6ff62ad4f6e1914d9aa0cacde6772246ca2dd"
},
"senderShard": {
"status": "success",
"hash": "bb24ccaa2da8cddd6a3a8eb162e6ff62ad4f6e1914d9aa0cacde6772246ca2dd"
}
},
"error": "",
"code": "successful"
}
过帐估计交易成本
https://gateway.elrond.com/transaction/cost
这个端点允许人们估计交易的成本。
RequestResponse 身体参数
参数 | 需要 | 类型 | 描述 |
---|---|---|---|
价值 | 必需的 | string |
要传输的值,以大整数的字符串形式表示(可以是“0”)。 |
听筒 | 必需的 | string |
接收者的地址(bech32)。 |
发报机 | 必需的 | string |
发件人的地址(bech32)。 |
数据 | OPTIONAL | string |
交易消息(数据)的 base64 字符串表示形式。 |
chainID | 必需的 | string |
链标识符。 |
版本 | 必需的 | number |
交易的版本(例如 1)。 |
目前 | OPTIONAL | number |
发送方随机数。 |
成本估算成功。
{
"data": {
"txGasUnits": "77000"
},
"error": "",
"code": "successful"
}
提示
该端点返回以气体单位表示的交易成本。返回值可用于填写交易的 gasLimit 字段。
这是一个请求的例子:
POST https://gateway.elrond.com/transaction/cost HTTP/1.1
Content-Type: application/json
{
"value": "100000",
"receiver": "erd188nydpkagtpwvfklkl2tn0w6g40zdxkwfgwpjqc2a2m2n7ne9g8q2t22sr",
"sender": "erd1l453hd0gt5gzdp7czpuall8ggt2dcv5zwmfdf3sd3lguxseux2fsmsgldz",
"data": "dGhpcyBpcyBhbiBleGFtcGxl", #base64 representation of "this is an example"
"chainID": "1",
"version": 1,
"nonce": 1
}
获取 获取交易
https://gateway.elrond.com/transaction/:txHash
这个端点允许用户查询交易的细节。
RequestResponseExample with results 路径参数
参数 | 需要 | 类型 | 描述 |
---|---|---|---|
txHash | 必需的 | string |
交易的哈希(标识符)。 |
查询参数
参数 | 需要 | 类型 | 描述 |
---|---|---|---|
发报机 | OPTIONAL | string |
发送者的地址——优化请求的提示。 |
有结果 | OPTIONAL | bool |
用于指定是否应返回智能合约结果和其他详细信息的布尔参数。 |
成功检索交易详细信息。
{
"data": {
"transaction": {
"type": "normal",
"nonce": 3,
"round": 186580,
"epoch": 12,
"value": "1000000000000000000",
"receiver": "erd1...",
"sender": "erd1...",
"gasPrice": 1000000000,
"gasLimit": 70000,
"data": "Zm9yIHRlc3Rz",
"signature": "1047...",
"sourceShard": 2,
"destinationShard": 1,
"blockNonce": 186535,
"miniblockHash": "e927...",
"blockHash": "50a1...",
"status": "executed"
}
},
"error": "",
"code": "successful"
}
``` 请求 URL:
`https://gateway.elrond.com/transaction/:txHash?withResults=true`
回应:
响应可以包含附加字段,如`smartContractResults`或`receipt`
```rust
{
"data": {
"transaction": {
"type": "normal",
"nonce": 3,
"round": 186580,
"epoch": 12,
"value": "1000000000000000000",
"receiver": "erd1...",
"sender": "erd1...",
"gasPrice": 1000000000,
"gasLimit": 70000,
"data": "Zm9yIHRlc3Rz",
"signature": "1047...",
"sourceShard": 2,
"destinationShard": 1,
"blockNonce": 186535,
"miniblockHash": "e927...",
"blockHash": "50a1...",
"status": "executed",
"receipt": {
"value": 100,
"sender": "erd1...",
"data": "...",
"txHash": "b37..."
},
"smartContractResults": [
{
"hash": "...",
"nonce": 5,
"value": 1000,
"receiver": "erd1...",
"sender": "erd1...",
"data": "@6f6b",
"prevTxHash": "3638...",
"originalTxHash": "3638...",
"gasLimit": 0,
"gasPrice": 1000000000,
"callType": 0
}
]
}
},
"error": "",
"code": "successful"
}
重要
可选的查询参数 sender
只适用于针对代理的请求(不针对观察者节点)。
获取 获取交易状态
https://gateway.elrond.com/transaction/:txHash/status
这个端点允许用户查询交易的状态。
RequestResponse 路径参数
参数 | 需要 | 类型 | 描述 |
---|---|---|---|
txHash | 必需的 | string |
交易的哈希(标识符)。 |
查询参数
参数 | 需要 | 类型 | 描述 |
---|---|---|---|
发报机 | OPTIONAL | string |
发送者的地址——优化请求的提示。 |
成功检索交易状态。
{
"data": {
"status": "executed"
},
"error": "",
"code": "successful"
}
重要
可选的查询参数 sender
只适用于针对代理的请求(不针对观察者节点)。
获取 获取交易池
http://local-proxy-instance/transaction/pool
警告
此端点在公共网关上不可用。但是,通过将AllowEntireTxPoolFetch
设置为true
,可以在本地代理实例上使用它
这个端点允许获取整个交易池,合并来自每个碎片的交易池。
默认
RequestResponse 示例:
http://local-proxy-instance/transaction/pool
🟢 200:好的
成功检索交易状态。
{
"data": {
"txPool": {
"regularTransactions": [
{
"txFields": {
"hash": "84bb8a..."
}
},
{
"txFields": {
"hash": "4e2c43..."
}
}
],
"smartContractResults": [],
"rewards": []
},
"error": "",
"code": "successful"
}
使用自定义字段
RequestResponse 查询参数
参数 | 需要 | 类型 | 描述 |
---|---|---|---|
田地(复数);场;域;字段 | OPTIONAL | string |
要包含的字段列表。 |
碎片标识 | OPTIONAL | string |
特定的碎片 id(0、1、2 等。或者元链为 4294967295) |
如上所示,如果fields
项为空,则只显示交易哈希。
如果使用了shard-id
项,那么将只显示来自该特定碎片池的交易。
带有分片 id 和字段的请求示例:
https://gateway.elrond.com/transaction/pool?shard-id=0&fields=sender,receiver,value
字段项的所有可能值为:
- 混杂
- 目前
- 发报机
- 听筒
- 气体极限
- 天然气价格
- 接收用户名
- 数据
- 价值 🟢 200:好的
成功检索交易状态。
{
"data": {
"txPool": {
"regularTransactions": [
{
"txFields": {
"gasLimit": 10,
"gasPrice": 1000,
"receiver": "erd1...",
"sender": "erd1...",
"value": "10000000000000000000"
}
}
],
"smartContractResults": [
{
"txFields": {
"gasLimit": 10,
"gasPrice": 1000,
"receiver": "erd1...",
"sender": "erd1...",
"value": "10000000000000000000"
}
}
],
"rewards": [
{
"txFields": {
"gasLimit": 10,
"gasPrice": 1000,
"receiver": "erd1...",
"sender": "erd1...",
"value": "10000000000000000000"
}
}
]
}
},
"error": "",
"code": "successful"
}
获取 获取发送方的交易池
https://gateway.elrond.com/transaction/pool?by-sender=:sender:
此端点允许从交易池中获取发送方的所有交易。
默认
RequestResponse 查询参数
参数 | 需要 | 类型 | 描述 |
---|---|---|---|
发件人 | 必需的 | string |
发件人的地址。 |
示例:
https://gateway.elrond.com/transaction/pool?by-sender=erd1qyu5wthldzr8wx5c9ucg8kjagg0jfs53s8nr3zpz3hypefsdd8ssycr6th
🟢 200:好的
成功检索交易状态。
{
"data": {
"txPool": {
"transactions": [
{
"txFields": {
"hash": "1daea5..."
}
}
]
}
},
"error": "",
"code": "successful"
}
使用自定义字段
RequestResponse 查询参数
参数 | 需要 | 类型 | 描述 |
---|---|---|---|
发件人 | 必需的 | string |
发件人的地址。 |
田地(复数);场;域;字段 | OPTIONAL | string |
要包含的字段列表。 |
如上所示,如果fields
项为空,则只显示交易哈希。
带字段的请求示例:
https://gateway.elrond.com/transaction/pool?by-sender=erd1at9...&fields=sender,receiver,value
字段项的所有可能值为:
- 混杂
- 目前
- 发报机
- 听筒
- 气体极限
- 天然气价格
- 接收用户名
- 数据
- 价值 🟢 200:好的
成功检索交易状态。
{
"data": {
"txPool": {
"transactions": [
{
"txFields": {
"hash": "1daea...",
"receiver": "erd1932...",
"sender": "erd1at9ke...",
"value": 0
}
}
]
}
},
"error": "",
"code": "successful"
}
获取 从发送池中获取发送方的最新随机数
https://gateway.elrond.com/transaction/pool?by-sender=:sender:&last-nonce=true
这个端点允许获取整个交易池,合并来自每个碎片的交易池。
RequestResponse 查询参数
参数 | 需要 | 类型 | 描述 |
---|---|---|---|
发件人 | 必需的 | string |
发件人的地址。 |
最后一次 | 必需的 | bool |
指定是否必须返回最后一个 nonce。 |
成功检索交易状态。
{
"data": {
"nonce": 38
},
"error": "",
"code": "successful"
}
获取 从 Tx 池中获取发送方的 nonce gaps】
https://gateway.elrond.com/transaction/pool?by-sender=:sender:&nonce-gaps=true
这个端点允许获取整个交易池,合并来自每个碎片的交易池。
RequestResponse 查询参数
参数 | 需要 | 类型 | 描述 |
---|---|---|---|
发件人 | 必需的 | string |
发件人的地址。 |
临时缺口 | 必需的 | bool |
指定是否应返回随机数间隙。 |
成功检索交易状态。
{
"data": {
"nonceGaps": {
"gaps": [
{
"from": 34,
"to": 35
},
{
"from": 37,
"to": 37
}
]
}
},
"error": "",
"code": "successful"
}