小蚁NEO:RPC-API

注:以下使用的为测试网络环境

1. 创建地址

简要描述:

  • 创建新的账户地址

GET请求示例:

  • http://127.0.0.1:20332?jsonrpc=2.0&method=getnewaddress&params=[]&id=1

POST请求URL:

  • http://127.0.0.1:20332

POST请求示例:

  • { "jsonrpc": "2.0", "method": "getnewaddress", "params": [], "id": 1 }

参数:

返回示例

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

返回参数说明

参数名类型说明
resultstring账户地址

备注

执行此命令前需要在 Neo-CLI 节点中打开钱包

2. 查询某地址全部资产信息

简要描述:

  • 查询某地址全部资产信息

GET请求示例:

  • http://127.0.0.1:20332?jsonrpc=2.0&method=getaccountstate&params=["AKPzixpUZ2fWN6uSVyHzqinT5hrAw4QD8b"]&id=1

POST请求URL:

  • http://127.0.0.1:20332

POST请求示例:

  • { "jsonrpc": "2.0", "method": "getaccountstate", "params": ["AJBENSwajTzQtwyJFkiJSv7MAaaMc7DsRz"], "id": 1 }

参数:

参数名必选类型说明
AKPzixpUZ2fWN6uSVyHzqinT5hrAw4QD8bstring账户地址

返回示例

{
    "jsonrpc": "2.0",
    "id": 1,
    "result": {
        "version": 0,
        "script_hash": "0x1179716da2e9523d153a35fb3ad10c561b1e5b1a",
        "frozen": false,
        "votes": [],
        "balances": [
            {
                "asset": "0xc56f33fc6ecfcd0c225c4ab356fee59390af8560be0e930faebe74a6daff7c9b",
                "value": "94"
            }
        ]
    }
}

返回参数说明

参数名类型说明
script_hashstring合约脚本散列,在 NEO 中所有账户都是合约账户
frozenboolean该账户是否冻结
votesarray查询该地址用于投票的 NEO
balancearray该地址的资产余额
assetstring资产 ID
valuestring资产金额

备注

直接调用此方法会返回账户下所有资产的id及金额。可以根据想要查询的资产id在结果中进行筛选

3. 从某个地址转账

简要描述:

  • 从某个地址转账

GET请求示例:

  • http://127.0.0.1:20332?jsonrpc=2.0&method=sendfrom&params=["602c79718b16e442de58778e148d0b1084e3b2dffd5de6b7b16cee7969282de7","AWg3L6W68bFfSS13Tf4rt8CRdG2ktaAjGb","AWg3L6W68bFfSS13Tf4rt8CRdG2ktaAjGb",1]&id=1

POST请求URL:

  • http://127.0.0.1:20332

POST请求示例:

  • { "jsonrpc": "2.0", "method": "sendfrom", "params": ["602c79718b16e442de58778e148d0b1084e3b2dffd5de6b7b16cee7969282de7","AWg3L6W68bFfSS13Tf4rt8CRdG2ktaAjGb","AWg3L6W68bFfSS13Tf4rt8CRdG2ktaAjGb",1], "id": 1 }

参数:

参数名必选类型说明
asset_idstring资产 ID
fromstring转账地址
tostring收款地址
valuestring转账金额
feestring手续费,可选参数,默认为 0

返回示例

  {
  "jsonrpc": "2.0",
  "id": 1,
  "result": {
    "txid": "0x60170ad03627ce45c7dd56ececbf33b26eab0845aa8b2cbbeecaefc5771b9eb1",
    "size": 262,
    "type": "ContractTransaction",
    "version": 0,
    "attributes": [],
    "vin": [
      {
        "txid": "0xd2188c1bd454ac883d79826e5c677deedb91cc61ec6d819df48ff4a963873adb",
        "vout": 1
      }
    ],
    "vout": [
      {
        "n": 0,
        "asset": "0x602c79718b16e442de58778e148d0b1084e3b2dffd5de6b7b16cee7969282de7",
        "value": "1",
        "address": "AWg3L6W68bFfSS13Tf4rt8CRdG2ktaAjGb"
      },
      {
        "n": 1,
        "asset": "0x602c79718b16e442de58778e148d0b1084e3b2dffd5de6b7b16cee7969282de7",
        "value": "17.4798197",
        "address": "AWg3L6W68bFfSS13Tf4rt8CRdG2ktaAjGb"
      }
    ],
    "sys_fee": "0",
    "net_fee": "0",
    "scripts": [
      {
        "invocation": "40a8d40e1652d7ad0c7bb59ef8217237037824af54ee5e46f2fd096c44dd46ef27fa7255010e2a8a2166af8a904e13b96bd3ac82e791633685824c35e7f2731e79",
        "verification": "2102883118351f8f47107c83ab634dc7e4ffe29d274e7d3dcf70159c8935ff769bebac"
      }
    ]
  }
}

返回参数说明

参数名类型说明
result交易详情

备注

  1. 执行此命令前需要在 Neo-CLI 节点中打开钱包

  2. 返回如上的交易详情说明交易发送成功,否则交易发送失败。

  3. 如果签名不完整会返回待签名的交易。

  4. 如果余额不足会返回错误信息。

4. 转账

简要描述:

  • 转账

GET请求示例:

  • http://127.0.0.1:20332?jsonrpc=2.0&method=sendtoaddress&params=[""c56f33fc6ecfcd0c225c4ab356fee59390af8560be0e930faebe74a6daff7c9b","AK4if54jXjSiJBs6jkfZjxAastauJtjjse",1]&id=1

POST请求URL:

  • http://127.0.0.1:20332

POST请求示例:

  • { "jsonrpc": "2.0", "method": "sendtoaddress", "params": ["c56f33fc6ecfcd0c225c4ab356fee59390af8560be0e930faebe74a6daff7c9b","AK4if54jXjSiJBs6jkfZjxAastauJtjjse",1], "id": 1 }

参数:

参数名必选类型说明
asset_idstring资产 ID(资产标识符)
addressstring收款地址
valuestring转账金额
feestring手续费,可选参数,默认为 0

返回示例

 {
    "jsonrpc": "2.0",
    "id": 1,
    "result": {
        "txid": "0x06de043b9b914f04633c580ab02d89ba55556f775118a292adb6803208857c91",
        "size": 262,
        "type": "ContractTransaction",
        "version": 0,
        "attributes": [],
        "vin": [
            {
                "txid": "0x9c20c13f6b05691efbfd7e420b0edf470f8a5ae467e1e7ca7e11243c9b9fc333",
                "vout": 2
            }
        ],
        "vout": [
            {
                "n": 0,
                "asset": "0xc56f33fc6ecfcd0c225c4ab356fee59390af8560be0e930faebe74a6daff7c9b",
                "value": "1",
                "address": "AK4if54jXjSiJBs6jkfZjxAastauJtjjse"
            },
            {
                "n": 1,
                "asset": "0xc56f33fc6ecfcd0c225c4ab356fee59390af8560be0e930faebe74a6daff7c9b",
                "value": "497",
                "address": "AK5q8peiC4QKwuZHWX5Dkqhmar1TAGvZBS"
            }
        ],
        "sys_fee": "0",
        "net_fee": "0",
        "scripts": [
            {
                "invocation": "4059e40a2040fe43bf8a40230e1f136dcfe7b3ca37d492ac8d6439615f7b88601c8d9b8077cd0e4f8c9f402d10a2782945bfa50e0ed3f57f7cceebd2f792453eb0",
                "verification": "2103cf5ba6a9135f8eaeda771658564a855c1328af6b6808635496a4f51e3d29ac3eac"
            }
        ]
    }
}

返回参数说明

参数名类型说明
result交易详情

备注

  1. 执行此命令前需要在 Neo-CLI 节点中打开钱包

  2. 返回如上的交易详情说明交易发送成功,否则交易发送失败。

  3. 如果签名不完整会返回待签名的交易。

  4. 如果余额不足会返回错误信息。

5. 根据交易hash值返回交易详情

简要描述:

  • 根据交易hash值返回交易详情

GET请求示例:

  • http://127.0.0.1:20332?jsonrpc=2.0&method=getrawtransaction&params=["27160ed0e54f869ac59870dc980a0c32f45be928868e98bcc3ecebc6e3d6f137",1]&id=1

POST请求URL:

  • http://127.0.0.1:20332

POST请求示例:

  • { "jsonrpc": "2.0", "method": "getrawtransaction", "params": ["f4250dab094c38d8265acc15c366dc508d2e14bf5699e12d9df26577ed74d657", 1], "id": 1 }

参数:

参数名必选类型说明
27160ed0e54f869ac59870dc980a0c32f45be928868e98bcc3ecebc6e3d6f137string交易hash

返回示例

{
    "jsonrpc": "2.0",
    "id": 1,
    "result": {
        "txid": "0x27160ed0e54f869ac59870dc980a0c32f45be928868e98bcc3ecebc6e3d6f137",
        "size": 289,
        "type": "InvocationTransaction",
        "version": 0,
        "attributes": [],
        "vin": [
            {
                "txid": "0x757291d837ee9075e04d114ea40263e51431ae23682708416df0d11c7fe8e78f",
                "vout": 0
            }
        ],
        "vout": [
            {
                "n": 0,
                "asset": "0x602c79718b16e442de58778e148d0b1084e3b2dffd5de6b7b16cee7969282de7",
                "value": "530.997",
                "address": "ALhYzeoL7r7CLggtnyFpgF9kSxKuekWMGg"
            }
        ],
        "sys_fee": "0",
        "net_fee": "0",
        "scripts": [
            {
                "invocation": "403f7c9c00f41f0aad9fc1f3faad44cddddd2b79e20f89e9c31e3bafcf706ca92af827c371bd6279384885785e295cfbec7354ca57bf1588b485f26ab442a7e702",
                "verification": "2102857c8c7cebd9c5f71997d84257b0d6e6753bd92f82bb9f005f4350bc521f1225ac"
            }
        ],
        "script": "0500a0acb90314acaf7703adff027af0d52206d3c20b00b67d30ac143607650d7faa60d2a7ca32f39a367f058d49bbf353c1087472616e736665726780f71387da4dc6c7bd0416178cd6d5a4dea70508660424dd4e5b",
        "gas": "0",
        "blockhash": "0xac7f9eab14bdbed68020737af312cea75b930d8770203929ef5efb9a69f44209",
        "confirmations": 6,
        "blocktime": 1531895074
    }
}

返回参数说明

参数名类型说明
result交易详情

6. 获取区块高度

简要描述:

  • 获取区块高度

GET请求示例:

  • http://127.0.0.1:20332?jsonrpc=2.0&method=getblockcount&params=[]&id=1

POST请求URL:

  • http://127.0.0.1:20332

POST请求示例:

  • { "jsonrpc": "2.0", "method": "getblockcount", "params": [], "id": 1 }

参数:

返回示例

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

返回参数说明

参数名类型说明
resultint区块高度

7. 根据区块hash值返回区块详情

简要描述:

  • 根据区块hash值返回区块详情

GET请求示例:

  • http://127.0.0.1:20332?jsonrpc=2.0&method=getblock&params=["0x361f8f724690bd60804f0f83a823d8ae1f5f55b2d6307604fe6ec98368881c05", 1]&id=1

POST请求URL:

  • http://127.0.0.1:20332

POST请求示例:

  • { "jsonrpc": "2.0", "method": "getblock", "params": ["773dd2dae4a9c9275290f89b56e67d7363ea4826dfd4fc13cc01cf73a44b0d0e", 1], "id": 1 }

参数:

参数名必选类型说明
hashstring区块散列值

返回示例

{
    "jsonrpc": "2.0",
    "id": 1,
    "result": {
        "hash": "0x361f8f724690bd60804f0f83a823d8ae1f5f55b2d6307604fe6ec98368881c05",
        "size": 686,
        "version": 0,
        "previousblockhash": "0x482193256be13d20d6dc2088738901d9c8bc61d573ccbe25d7a9b5755a07b2bf",
        "merkleroot": "0x13e6917e628e17a362b1749c518e43b13c9711c68342302295d39619d16d3efe",
        "time": 1531816457,
        "index": 1602239,
        "nonce": "b09b1cefa835bf42",
        "nextconsensus": "AarH7d8Zg92UKVTVNUXR4YDagVj4rEmpFZ",
        "script": {
            "invocation": "4052405f4d6b442dc55727a001914a6e1e72e7afb1fa0ebeac15443a31e023df600eba2df06aee7d019785a9ce13250c579f422c6362a5dc7c3f2e73bf22c3d9fb40840868afa2ce1079f15774f82c2442e71b2b30417ef3b9084303c22a7681fca0cf85d9635279fcb380a4ef2005a94e2bac90ac7eed1afaaf5643da92a0f85e9b40707be04b161b6ff689304dae533027eaef32a02c427b69ee0d66353fcbdbe4d60fc7808e28c11301fede0edebbf6b7de68f4afe6af055cfbe55d8a8600e2f16f40464722da5e57d9ab0227e42fcc8b2f17a5088a6578727712c961cc34f2e4722a1c48cb279cc0e92cecec60b991b8291c504a09c15ce87f615851fc3890a5cc3e40d9b2f2bcee8670dc1e1a785cbcc68964831489c3df80f1eabf3b402051afec3cea7619cc6b8bc05c792652dc12c8efb26df81a40fa6301e00861fe10567f8d15",
            "verification": "55210209e7fd41dfb5c2f8dc72eb30358ac100ea8c72da18847befe06eade68cebfcb9210327da12b5c40200e9f65569476bbff2218da4f32548ff43b6387ec1416a231ee8210344925b6126c8ae58a078b5b2ce98de8fff15a22dac6f57ffd3b108c72a0670d121025bdf3f181f53e9696227843950deb72dcd374ded17c057159513c3d0abe20b64210266b588e350ab63b850e55dbfed0feeda44410a30966341b371014b803a15af0721026ce35b29147ad09e4afe4ec4a7319095f08198fa8babbe3c56e970b143528d222103c089d7122b840a4935234e82e26ae5efd0c2acb627239dc9f207311337b6f2c157ae"
        },
        "tx": [
            {
                "txid": "0x13e6917e628e17a362b1749c518e43b13c9711c68342302295d39619d16d3efe",
                "size": 10,
                "type": "MinerTransaction",
                "version": 0,
                "attributes": [],
                "vin": [],
                "vout": [],
                "sys_fee": "0",
                "net_fee": "0",
                "scripts": [],
                "nonce": 2822094658
            }
        ],
        "confirmations": 4,
        "nextblockhash": "0x064d949a0464bc9ea2a59856ba0a24e2ae1916ebf1d802bf7e8ba6c3255a12f4"
    }
}

返回参数说明

参数名类型说明
resultarray区块详情

8. 根据区块索引返回区块详情

简要描述:

  • 根据区块索引返回区块详情

GET请求示例:

  • http://127.0.0.1:20332?jsonrpc=2.0&method=getblock&params=[10000, 1]&id=1

POST请求URL:

  • http://127.0.0.1:20332

POST请求示例:

  • { "jsonrpc": "2.0", "method": "getblock", "params": [10000, 1], "id": 1 }

参数:

参数名必选类型说明
indexint区块索引(区块高度) = 区块数 – 1
verboseint可选参数,verbose 默认值为 0,verbose 为 0 时返回的是区块的序列化后的信息,用 16 进制字符串表示,如果从中获取详细信息需要调用 SDK 来进行反序列化。verbose 为 1 时返回的是对应区块的详细信息,用 Json 格式字符串表示

返回示例

  {
  "jsonrpc": "2.0",
  "id": 1,
  "result": {
    "hash": "0x4c1e879872344349067c3b1a30781eeb4f9040d3795db7922f513f6f9660b9b2",
    "size": 686,
    "version": 0,
    "previousblockhash": "0x53ce15a53a184faa058be9008ece887d7f0b30a459342ce42753f73f9ed390e9",
    "merkleroot": "0x9c909e1e3ba03290553a68d862e002c7a21ba302e043fc492fe069bf6a134d29",
    "time": 1476834896,
    "index": 10000,
    "nonce": "aa2c0fd5dc445445",
    "nextconsensus": "APyEx5f4Zm4oCHwFWiSTaph1fPBxZacYVR",
    "script": {
      "invocation": "405e31eb19b1feaeb27c3a5b95f568b9b256fefe0ea61f6296eb8af836c29597617fe81d23a8bf66309000e4c7568b7f43560f61e4ee6cd1f78a2a42f50a5008c240ccf73ce9f7f810273730bdfc786d346086a697cc06239e88e040ed2ec0583c7dbb6eccb8b8a74afbd75cfbaff06c051b7e82abe65f96f50a1673e1536f91a3d540618e43cce18c7c91b54b2a5e44ba1e4a71a8dd0af0ec95c8c4f05343e66129b150057a5f79399a92eda1226fddd254702ffc682309787ab241509b2244e410334070a5ac50d897bf39f98780f79fb1a2416c41dc2e202b4ad797bd0c70e2b57f1157c4ff5551ec6df58bec6244dc72a3f25cd1836e8cdd4c0d8c2e5ba7e2d8859b40ae80743c9a2a8e154671eb156266971439a9017e96ea072c848287a71b2d6a99a67ba50fc7935a6de4d8884794291fc6cebd77158954ef03b10d5d0a30b52bc9",
      "verification": "552102486fd15702c4490a26703112a5cc1d0923fd697a33406bd5a1c00e0013b09a7021024c7b7fb6c310fccf1ba33b082519d82964ea93868d676662d4a59ad548df0e7d2102aaec38470f6aad0042c6e877cfd8087d2676b0f516fddd362801b9bd3936399e2103b209fd4f53a7170ea4444e0cb0a6bb6a53c2bd016926989cf85f9b0fba17a70c2103b8d9d5771d8f513aa0869b9cc8d50986403b78c6da36890638c3d46a5adce04a2102ca0e27697b9c248f6f16e085fd0061e26f44da85b58ee835c110caa5ec3ba5542102df48f60e8f3e01c48ff40b9b7f1310d7a8b2a193188befe1c2e3df740e89509357ae"
    },
    "tx": [
      {
        "txid": "0x9c909e1e3ba03290553a68d862e002c7a21ba302e043fc492fe069bf6a134d29",
        "size": 10,
        "type": "MinerTransaction",
        "version": 0,
        "attributes": [],
        "vin": [],
        "vout": [],
        "sys_fee": "0",
        "net_fee": "0",
        "scripts": [],
        "nonce": 3695465541
      }
    ],
    "confirmations": 981987,
    "nextblockhash": "0xc9a32cd215837c02dd72613bfad6ed064579e77bafd859907f87b3e67fa498cc"
  }
}

返回参数说明

参数名类型说明
result区块详情

9. 导出指定地址的私钥

简要描述:

  • 导出指定地址的私钥

GET请求示例:

  • http://127.0.0.1:20332?jsonrpc=2.0&method=dumpprivkey&params=["AKPzixpUZ2fWN6uSVyHzqinT5hrAw4QD8b"]&id=1

POST请求URL:

  • http://127.0.0.1:20332

POST请求示例:

  • { "jsonrpc": "2.0", "method": "dumpprivkey", "params": ["ASMGHQPzZqxFB2yKmzvfv82jtKVnjhp1ES"], "id": 1 }

参数:

参数名必选类型说明
AKPzixpUZ2fWN6uSVyHzqinT5hrAw4QD8bstring账户地址

返回示例

 {
    "jsonrpc": "2.0",
    "id": 1,
    "result": "L3FdgAisCmV******************************9XM65cvjYQ1"
}

返回参数说明

参数名类型说明
resultstring返回该标准地址的私钥

备注

执行此命令前需要在 Neo-CLI 节点中打开钱包

10. 查询钱包中指定的资产信息

简要描述:

  • 查询钱包中指定的资产信息

GET请求示例:

  • http://127.0.0.1:20332?jsonrpc=2.0&method=getbalance&params=["025d82f7b00a9ff1cfe709abe3c4741a105d067178e645bc3ebad9bc79af47d4"]&id=1

POST请求URL:

  • http://127.0.0.1:20332

POST请求示例:

  • { "jsonrpc": "2.0", "method": "getbalance", "params": ["025d82f7b00a9ff1cfe709abe3c4741a105d067178e645bc3ebad9bc79af47d4"], "id": 1 }

参数:

参数名必选类型说明
asset_idstring资产 ID(资产标识符),如果是全局资产,此处为注册资产时的 Register Transaction 或 Publish Transaction 的交易 ID,如果是合约内部资产,此处为合约的 Script Hash。

常用资产ID:

  • NEO为:c56f33fc6ecfcd0c225c4ab356fee59390af8560be0e930faebe74a6daff7c9b
  • NeoGas为:602c79718b16e442de58778e148d0b1084e3b2dffd5de6b7b16cee7969282de7
  • RPX Sale 为:ecc6b20d3ccac1ee9ef109af5a7cdb85706b1df9

返回示例

 {
  "jsonrpc": "2.0",
  "id": 1,
  "result": {
    "balance": "1.01",
    "confirmed": "1.01"
  }
}

返回参数说明

参数名类型说明
balancestring钱包中该资产的真实余额
confirmedstring钱包中该资产的已确认的金额,只有已确认的金额可以用来转账

balance 和 confirmed 二者可能会不相等,仅在从钱包中转出一笔钱,而且有找零未确认时时,confirmed 值会小于balance。当这笔交易确定后,二者会变得相等。

备注

  • 当区块未完全同步时,返回的资产余额可能不是最新的,请确保使用该 API 时区块已经同步到最新高度。
    原文作者:yuyangray
    原文地址: https://www.jianshu.com/p/84b63574b9d8
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞