cam server API文档

The CAM Project edited this page Apr 26, 2018 · 3 revisions

cam-server API文档

目录

一接口说明

1环境配置

每个 CAM 节点 cam-server 都可选的提供了一套 API 接口,用于从节点获取区块链数据,使得开发区块链应用变得十分方便。接口通过 JSON-RPC 的方式提供,底层使用 HTTP/HTTPS 协议进行通讯。要启动一个提供 RPC 服务的节点,可运行以下命令:

dotnet cam-server.dll /rpc

若要通过 HTTPS 的方式访问 RPC 服务器,需要在启动节点前修改配置文件 config.json,并设置域名、证书和密码:

{
  "ApplicationConfiguration": {
    "Paths": {
      "Chain": "Chain",
      "Notifications": "Notifications"
    },
    "P2P": {
      "Port": 16333,
      "WsPort": 16334
    },
    "RPC": {
      "Port": 16332,
      "SslCert": " YourSslCertFile.xxx ",
      "SslCertPassword": " YourPassword "
    }
  }
}

JSON-RPC 服务器启动后,会监听 TCP 端口,默认端口如下。

主网(Main Net) 测试网(Test Net)
JSON-RPC HTTPS 18331 16331
JSON-RPC HTTP 18332 16332

2访问示例(测试网)

所有的api请求地址为:http://node6.camatrix.org:16332

请求区块高度

请求参数

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

请求结果

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

二接口列表

1账户操作

1.1创建钱包地址

请求参数

参数说明:

创建钱包时需设置标签,用于后期查询对应账户的最近交易

账户标签:"zerowood"

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

返回结果

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

1.2验证钱包地址

请求参数

参数说明:

需要验证的钱包地址:ANRUbj8BADeEoPPEvJUA1727N25nX2Ucvm

{
  "jsonrpc": "2.0",
  "method": "validateaddress",
  "params": ["ANRUbj8BADeEoPPEvJUA1727N25nX2Ucvm"],
  "id": 1
}

返回结果

{
  "jsonrpc": "2.0",
  "id": 1,
  "result": {
    "address": "ANRUbj8BADeEoPPEvJUA1727N25nX2Ucvm",
    "isvalid": true
  }
}

1.3发送资产

请求参数

CAM资产的ID为:ceac4961fe81a783516519d263efe4b614777d427b2eccebd1bdb897b705edec

交易结果可在网上查询:

正式网:https://camchain.xyz/

测试网:http://testnet.camchain.xyz/

参数说明:

资产id:ceac4961fe81a783516519d263efe4b614777d427b2eccebd1bdb897b705edec

从此账户中转出资产:AG5nRuzxW2yjLb1K8c5UwQtrRnjQ6Wf24d

接收资产的账户:ARb9LtCmNwBpwurXG73FR8ofvgoZywi5Nr

转账数额:55

{
  "jsonrpc": "2.0",
  "method": "sendfrom",
  "params": ["ceac4961fe81a783516519d263efe4b614777d427b2eccebd1bdb897b705edec","AG5nRuzxW2yjLb1K8c5UwQtrRnjQ6Wf24d","ARb9LtCmNwBpwurXG73FR8ofvgoZywi5Nr",55],
  "id": 1
}

返回结果

返回结果中存在result字段则说明发送交易成功,等待区块确认

{
  "jsonrpc": "2.0",
  "id": 1,
  "result": {
    "txid": "0xbb063b1c06ab8001b8da74c5c52f4cfc347971c765c31b1f1299fa5144fcdaaf",
    "size": 262,
    "type": "ContractTransaction",
    "version": 0,
    "attributes": [],
    "vin": [{
      "txid": "0xac17e796182b6a026b66e2144e6adfe23253c4d0dcae275dd795030ec0564cd2",
      "vout": 1
    }],
    "vout": [{
      "n": 0,
      "asset": "0xceac4961fe81a783516519d263efe4b614777d427b2eccebd1bdb897b705edec",
      "value": "55",
      "address": "ARb9LtCmNwBpwurXG73FR8ofvgoZywi5Nr"
    }, {
      "n": 1,
      "asset": "0xceac4961fe81a783516519d263efe4b614777d427b2eccebd1bdb897b705edec",
      "value": "999933",
      "address": "AG5nRuzxW2yjLb1K8c5UwQtrRnjQ6Wf24d"
    }],
    "sys_fee": "0",
    "net_fee": "0",
    "scripts": [{
      "invocation": "4083f4e051bf43dd42a197d73b0911d0454a1f7bb63d40848f4b543075983822479ce6a079268ccf3d0aad2d73004460ffed9606fb13f8a06c87b5b8e76d1a6ed6",
      "verification": "2103d52fe7125a1b8bd05ab222c07441209a4bb653db52d117b7a42d26cbaebecdb5ac"
    }]
  }
}

1.4获取交易内容

请求参数

参数说明:

交易id:0xbb063b1c06ab8001b8da74c5c52f4cfc347971c765c31b1f1299fa5144fcdaaf

{
  "jsonrpc": "2.0",
  "method": "gettransaction",
  "params": ["0xbb063b1c06ab8001b8da74c5c52f4cfc347971c765c31b1f1299fa5144fcdaaf"],
  "id": 1
}

返回结果

timereceived:节点收到请求后,获取交易确认数时的区块时间戳

time:交易所在区块的时间戳

{
  "jsonrpc": "2.0",
  "id": 1,
  "result": {
    "timereceived": 1524641841,
    "confirmations": 39,
    "height": 324805,
    "time": 1524640524,
    "txInfo": {
      "txid": "0xbb063b1c06ab8001b8da74c5c52f4cfc347971c765c31b1f1299fa5144fcdaaf",
      "size": 262,
      "type": "ContractTransaction",
      "version": 0,
      "attributes": [],
      "vin": [{
        "txid": "0xac17e796182b6a026b66e2144e6adfe23253c4d0dcae275dd795030ec0564cd2",
        "vout": 1
      }],
      "vout": [{
        "n": 0,
        "asset": "0xceac4961fe81a783516519d263efe4b614777d427b2eccebd1bdb897b705edec",
        "value": "55",
        "address": "ARb9LtCmNwBpwurXG73FR8ofvgoZywi5Nr"
      }, {
        "n": 1,
        "asset": "0xceac4961fe81a783516519d263efe4b614777d427b2eccebd1bdb897b705edec",
        "value": "999933",
        "address": "AG5nRuzxW2yjLb1K8c5UwQtrRnjQ6Wf24d"
      }],
      "sys_fee": "0",
      "net_fee": "0",
      "scripts": [{
        "invocation": "4083f4e051bf43dd42a197d73b0911d0454a1f7bb63d40848f4b543075983822479ce6a079268ccf3d0aad2d73004460ffed9606fb13f8a06c87b5b8e76d1a6ed6",
        "verification": "2103d52fe7125a1b8bd05ab222c07441209a4bb653db52d117b7a42d26cbaebecdb5ac"
      }]
    }
  }
}

1.5获取指定账户最近的交易

请求参数

账户地址:APjD1exi6GrsQwMEz5LSbPj5f9KjXP9LdG

最近的交易记录数:10

{
  "jsonrpc": "2.0",
  "method": "listtransactions",
  "params": ["APjD1exi6GrsQwMEz5LSbPj5f9KjXP9LdG",10],
  "id": 1
}

返回结果

{
  "jsonrpc": "2.0",
  "id": 1,
  "result": [{
    "account": "zerowood",
    "address": "APjD1exi6GrsQwMEz5LSbPj5f9KjXP9LdG",
    "time": "1524642667",
    "timereceived": "1524643595",
    "height": 324868,
    "txid": "0xe0a86e2d39a1327f093f208bdde3034d8e659e5b1b3ac2acb770ee7a3756ed12",
    "confirmations": 29,
    "transactionfee": "0",
    "category": "receive",
    "amount": "55",
    "remoteaddress": "AG5nRuzxW2yjLb1K8c5UwQtrRnjQ6Wf24d"
  }, {
    "account": "zerowood",
    "address": "APjD1exi6GrsQwMEz5LSbPj5f9KjXP9LdG",
    "time": "1524642667",
    "timereceived": "1524643595",
    "height": 324868,
    "txid": "0xdd5498392081c4b260659d9c7cfe08acc878ce1bd84b0b655691bc64fbf1c427",
    "confirmations": 29,
    "transactionfee": "0",
    "category": "receive",
    "amount": "6",
    "remoteaddress": "AG5nRuzxW2yjLb1K8c5UwQtrRnjQ6Wf24d"
  }, {
    "account": "zerowood",
    "address": "APjD1exi6GrsQwMEz5LSbPj5f9KjXP9LdG",
    "time": "1524643269",
    "timereceived": "1524643595",
    "height": 324885,
    "txid": "0x5c53660a57906cb090726302dc00b77a5fc14fa13dd06e407b7d023c5a8e182a",
    "confirmations": 12,
    "transactionfee": "0",
    "category": "send",
    "amount": "12",
    "remoteaddress": "AG5nRuzxW2yjLb1K8c5UwQtrRnjQ6Wf24d"
  }, {
    "account": "zerowood",
    "address": "APjD1exi6GrsQwMEz5LSbPj5f9KjXP9LdG",
    "time": "1524643230",
    "timereceived": "1524643595",
    "height": 324883,
    "txid": "0x675de57e6f9c1dbe6a50ecb62df0bedc65372808fea58cce9f31da6661ba3b92",
    "confirmations": 14,
    "transactionfee": "0",
    "category": "send",
    "amount": "6",
    "remoteaddress": "AG5nRuzxW2yjLb1K8c5UwQtrRnjQ6Wf24d"
  }, {
    "account": "zerowood",
    "address": "APjD1exi6GrsQwMEz5LSbPj5f9KjXP9LdG",
    "time": "1524643019",
    "timereceived": "1524643595",
    "height": 324877,
    "txid": "0x36a0cf0266eb4dbdb98718e8ef06eaa00ea16dbde1c29e33f4597c6b57b28ad1",
    "confirmations": 20,
    "transactionfee": "0",
    "category": "receive",
    "amount": "12",
    "remoteaddress": "AG5nRuzxW2yjLb1K8c5UwQtrRnjQ6Wf24d"
  }]
}

1.6查询账户余额

请求参数

参数说明:

资产id:ceac4961fe81a783516519d263efe4b614777d427b2eccebd1bdb897b705edec

账户地址:APjD1exi6GrsQwMEz5LSbPj5f9KjXP9LdG

{
  "jsonrpc": "2.0",
  "method": "getaccountbalance",
  "params": ["ceac4961fe81a783516519d263efe4b614777d427b2eccebd1bdb897b705edec","APjD1exi6GrsQwMEz5LSbPj5f9KjXP9LdG"],
  "id": 1
}

返回结果

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

2区块查询

2.1查询区块高度

请求参数

参数说明:

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

返回结果:

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

2.2根据高度查询区块内容

请求参数

参数说明:

区块高度:324883

是否返回详细(未设置,则返回区块的序列化后的信息):1(返回交易详细信息)

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

或者返回区块的序列化后的信息

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

返回结果:

交易详细信息

{
  "jsonrpc": "2.0",
  "id": 1,
  "result": {
    "hash": "0xf5455f712a3e250ad8d8c67cb496e315f8b8e81e86b5d25dec9db9c113d0a7ac",
    "size": 948,
    "version": 0,
    "previousblockhash": "0x87bd1b5cf28ea9d3c9e286d51ab3dc3d352b49c929cacf599149953f7d1ad0fe",
    "merkleroot": "0xeb79d05fd75b60b6362b3bbc116fbdda5973c64a12747aeef8a7e1eef6d5940d",
    "time": 1524643230,
    "index": 324883,
    "nonce": "834747c741cbb26b",
    "nextconsensus": "ASmiCrtCia2WnxuA18VautJ5de8z89hnU8",
    "script": {
      "invocation": "40e9705cc65719431ac178bbdf1238ed7d5ab9fecf7939defcf9a95851c45d128b1ea988804120dc767fc760ca280013108c02ef9a3a7b8bde703b5b938323bb1f4094a69717a05b3c3a57291878d6c81f476ad13392ff54e2e5428a580607a5a860f880393fc2d35dbb28365428a46d729fba55d86a7fe4effa49f3388bc9cdee8440a5447529dc7a7554885a603f8618724d84357cd89f32a5b64939f90f90a9b8362a46a0b96014aba03bf579a817b9c16db1a36494fcd2cbf6e0307c10a3741fe040fe3e9c5d5528ae7ff17fb63440257e3786b57418c0f78c1d079fdbc94e83d6a549bfd12869d7f50aca363146e116adfbe7ce0e8850b36c8a38d8e5428fd686834080a364d015a2f94685398768a4d21305caefdebcbeb55ca2a54611df88b8567ef9812aa67ca1af2fa898ddd6f72406609a9ebf0d19ee5f29b1f96c83374c0a67",
      "verification": "5521025e82b0d87946507bcfac71117b756640a136da6685aea4dc6828c6e6ca0d68832103681649df11f826afc16adceab7af57bc937e290da08323502fda7d1914ee18a0210275e022cb64dff870b9df068c3d928cd011655665e15432895158e064f44e9be5210298ff2c553a553f78042709658ca720eab8a48f902aebaae862f398845c15eb342103a905fe6b018eead29561567ba76267e22fd3549404091bacd243e74d99b816442103b515281957e6cda1e22489a95bc5d2090d0893c63bb40a438d84db4affc87bac2102d6d2032b4cd0e5b4c87675afb72234ee19ae6840bfc696e56adace062f7dda5157ae"
    },
    "tx": [{
      "txid": "0xa8f906812c8e90ee10ef3df7c8ac49baecc923e5306bd07441c9abc731c9d767",
      "size": 10,
      "type": "MinerTransaction",
      "version": 0,
      "attributes": [],
      "vin": [],
      "vout": [],
      "sys_fee": "0",
      "net_fee": "0",
      "scripts": [],
      "nonce": 1103868523
    }, {
      "txid": "0x675de57e6f9c1dbe6a50ecb62df0bedc65372808fea58cce9f31da6661ba3b92",
      "size": 262,
      "type": "ContractTransaction",
      "version": 0,
      "attributes": [],
      "vin": [{
        "txid": "0xdd5498392081c4b260659d9c7cfe08acc878ce1bd84b0b655691bc64fbf1c427",
        "vout": 0
      }],
      "vout": [{
        "n": 0,
        "asset": "0xceac4961fe81a783516519d263efe4b614777d427b2eccebd1bdb897b705edec",
        "value": "3",
        "address": "ARb9LtCmNwBpwurXG73FR8ofvgoZywi5Nr"
      }, {
        "n": 1,
        "asset": "0xceac4961fe81a783516519d263efe4b614777d427b2eccebd1bdb897b705edec",
        "value": "3",
        "address": "AG5nRuzxW2yjLb1K8c5UwQtrRnjQ6Wf24d"
      }],
      "sys_fee": "0",
      "net_fee": "0",
      "scripts": [{
        "invocation": "40b38e74473c6527c8645444c54c224af946343daa76b5c4d241369184f6af888bdece2ffb3f34af9af764e4b84f169fb7e0dd8a820c4f40ea0d6a1f610e23c426",
        "verification": "21022cf7a69694dec23510f2c824a414c58878abfed630ff21dea2584f64bfc3be2aac"
      }]
    }],
    "confirmations": 166,
    "nextblockhash": "0x53f1a8b4ccdb025a3dabc9004feedde56bb885738e3362833e33790f0b39612c"
  }
}

交易序列化后的信息

{
  "jsonrpc": "2.0",
  "id": 1,
  "result": "00000000fed01a7d3f95499159cfca29c9492b353ddcb31ad586e2c9d3a98ef25c1bbd870d94d5f6eee1a7f8ee7a74124ac67359dabd6f11bc3b2b36b6605bd75fd079eb9e35e05a13f504006bb2cb41c747478378a180770083f58694ea82a9b635ccb20d45c5e101fd450140e9705cc65719431ac178bbdf1238ed7d5ab9fecf7939defcf9a95851c45d128b1ea988804120dc767fc760ca280013108c02ef9a3a7b8bde703b5b938323bb1f4094a69717a05b3c3a57291878d6c81f476ad13392ff54e2e5428a580607a5a860f880393fc2d35dbb28365428a46d729fba55d86a7fe4effa49f3388bc9cdee8440a5447529dc7a7554885a603f8618724d84357cd89f32a5b64939f90f90a9b8362a46a0b96014aba03bf579a817b9c16db1a36494fcd2cbf6e0307c10a3741fe040fe3e9c5d5528ae7ff17fb63440257e3786b57418c0f78c1d079fdbc94e83d6a549bfd12869d7f50aca363146e116adfbe7ce0e8850b36c8a38d8e5428fd686834080a364d015a2f94685398768a4d21305caefdebcbeb55ca2a54611df88b8567ef9812aa67ca1af2fa898ddd6f72406609a9ebf0d19ee5f29b1f96c83374c0a67f15521025e82b0d87946507bcfac71117b756640a136da6685aea4dc6828c6e6ca0d68832103681649df11f826afc16adceab7af57bc937e290da08323502fda7d1914ee18a0210275e022cb64dff870b9df068c3d928cd011655665e15432895158e064f44e9be5210298ff2c553a553f78042709658ca720eab8a48f902aebaae862f398845c15eb342103a905fe6b018eead29561567ba76267e22fd3549404091bacd243e74d99b816442103b515281957e6cda1e22489a95bc5d2090d0893c63bb40a438d84db4affc87bac2102d6d2032b4cd0e5b4c87675afb72234ee19ae6840bfc696e56adace062f7dda5157ae0200006bb2cb41000000008000000127c4f1fb64bc9156650b4bd81bce78c8ac08fe7c9c9d6560b2c48120399854dd000002eced05b797b8bdd1ebcc2e7b427d7714b6e4ef63d219655183a781fe6149acce00a3e111000000006ba9c8ed1c179f2de59bfe71f5264260e9992e28eced05b797b8bdd1ebcc2e7b427d7714b6e4ef63d219655183a781fe6149acce00a3e11100000000036321e5ca81155030e9f49d5debecf58c3d4f5a014140b38e74473c6527c8645444c54c224af946343daa76b5c4d241369184f6af888bdece2ffb3f34af9af764e4b84f169fb7e0dd8a820c4f40ea0d6a1f610e23c4262321022cf7a69694dec23510f2c824a414c58878abfed630ff21dea2584f64bfc3be2aac"
}

2.3根据区块哈希值返回区块内容

请求参数

参数说明:

区块哈希值:0xf5455f712a3e250ad8d8c67cb496e315f8b8e81e86b5d25dec9db9c113d0a7ac

是否返回详细(未设置,则返回区块的序列化后的信息):1(返回交易详细信息)

{
  "jsonrpc": "2.0",
  "method": "getblock",
  "params": ["0xf5455f712a3e250ad8d8c67cb496e315f8b8e81e86b5d25dec9db9c113d0a7ac",1],
  "id": 1
}

返回序列化后的信息

{
  "jsonrpc": "2.0",
  "method": "getblock",
  "params": ["0xf5455f712a3e250ad8d8c67cb496e315f8b8e81e86b5d25dec9db9c113d0a7ac"],
  "id": 1
}

请求结果

请参照 2.2根据高度查询区块内容

Clone this wiki locally
You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.
Press h to open a hovercard with more details.