RPC Interfaces
RPC request uses HTTP POST method. The contents in the request are in JSON format, in which the action field sepecifies the name of the RPC interface.
Create an accout. The parameter
rpc_control
need to be set true
when run the mcp node program.- action:account_create
- password:account passward
- code:error code. The code 0 is success.
- msg:error message.
- account:the account created
// Success
{
"code": 0,
"msg": "OK",
"account": "mcp4M943gNHekWpfTmRFJHUYTYV65gnkjN5zAjqTeRTbnNCXfeJrw"
}
// Failed
{
"code": 1,
"msg": "Password can not be empty"
}
Remove an account. The parameter
rpc_control
need to be true
when run the mcp node program.- action:account_remove
- account:account to be removed
- password:account password
{
"action": "account_remove",
"account": "mcp4M943gNHekWpfTmRFJHUYTYV65gnkjN5zAjqTeRTbnNCXfeJrw",
"password": "[email protected]"
}
- code:error code. The code 0 is success.
- msg:error message.
// Success
{
"code": 0,
"msg": "OK"
}
// Failed
{
"code": 3,
"msg": "Wrong password"
}
Unlock an account. The parameter
rpc_control
need to be true
when run the mcp node program.- action:account_unlock
- account:account to be unlocked
- password:account password
{
"action": "account_unlock",
"account": "mcp4M943gNHekWpfTmRFJHUYTYV65gnkjN5zAjqTeRTbnNCXfeJrw",
"password": "[email protected]"
}
- code:error code. The code 0 is success.
- msg:error message.
// Success
{
"code": 0,
"msg": "OK"
}
// Failed
{
"code": 3,
"msg": "Wrong password"
}
Lock an account. The parameter
rpc_control
need to be true
when run the mcp node program.- action:account_lock
- account:account to be locked
{
"action": "account_lock",
"account": "mcp4M943gNHekWpfTmRFJHUYTYV65gnkjN5zAjqTeRTbnNCXfeJrw"
}
- code:error code. The code 0 is success.
- msg:error message.
// Success
{
"code": 0,
"msg": "OK"
}
// Failed
{
"code": 2,
"msg": "Account not found"
}
Import an account. The parameter
rpc_control
need to be true
when run the mcp node program.- action:account_import
- json:account in JSON format to be imported
{
"action": "account_import",
"json": "{\"account\":\"mcp3dUnMEsuSiUsKGgfft5VDpM2bX9S6T4ppApHRfn1cBmn2znyEv\",\"kdf_salt\":\"175DCAF994E6992AAD1369014670C086\",\"iv\":\"F6054D9B144A254D3D4EAB78C95F21B6\",\"ciphertext\":\"2A943F3A7316C33B16374D9076FEF5BA7770C2A0424A08501D3663A1467DEDD7\"}"
}
- code:error code. The code 0 is success.
- msg:error message.
- account:account imported.
// Success
{
"code": 0,
"msg": "OK",
"account": "mcp3dUnMEsuSiUsKGgfft5VDpM2bX9S6T4ppApHRfn1cBmn2znyEv"
}
// Failed
{
"code": 2,
"msg": "Invalid json"
}
export an account.
- action:account_export
- account:account to be exported
{
"action": "account_export",
"account": "mcp4GHUc91PYAddCiDHtwFnFDcsQrqdXW58Ps75rpHJsxAnJrQR1d"
}
- code:error code. The code 0 is success.
- msg:error message.
- json:account in JSON format exported.
// Success
{
"code": 0,
"msg": "OK",
"json": "{\"account\":\"mcp4GHUc91PYAddCiDHtwFnFDcsQrqdXW58Ps75rpHJsxAnJrQR1d\",\"kdf_salt\":\"37685A5B3413EC419CE4B5B79E0BB020\",\"iv\":\"F046EA90EA24A6CF0CB74BE8C560367B\",\"ciphertext\":\"4A2E6EE4CF04162D2A4DA6116C23CD94487837731055A1BC0FCBDA7E0D7C65A4\"}"
}
// Failed
{
"code": 2,
"msg": "Account not found"
}
Validate an account.
- action:account_validate
- account:account to be validated
{
"action": "account_validate",
"account": "mcp4GHUc91PYAddCiDHtwFnFDcsQrqdXW58Ps75rpHJsxAnJrQR1d"
}
- code:error code. The code 0 is success.
- msg:error message.
- valid:validation results (0:invalid format,1:valid format)
// Invalid format
{
"code": 0,
"msg": "OK",
"valid": 0
}
// Valid format
{
"code": 0,
"msg": "OK",
"valid": 1
}
Change an account password. The parameter
rpc_control
need to be true
when run the mcp node program.- action:account_password_change.
- account:account to have password changed.
- old_password:original password.
- new_password:new password.
{
"action": "account_password_change",
"account": "mcp4CGgMNZzmzXKvQx6TrfgSgsbGNSsWsW6FMPv4gQabhZnftrBLC",
"old_password": "JNVRNHCK2o8N",
"new_password":"qmwevFcyebqu"
}
- code:error code. The code 0 is success.
- msg:error message.
// Success
{
"code": 0,
"msg": "OK"
}
// Failed
{
"code": 5,
"msg": "Wrong old password"
}
List all accounts in the node.
- action:account_list.
{
"action": "account_list"
}
- code:error code. The code 0 is success.
- msg:error message.
// Success
{
"code": 0,
"msg": "OK"
"accounts": [
"mcp356ssGpdDhtjRqKHCP47Rt2mbUwFcFPD3mXT73FJzWEedw3Eog",
"mcp4qwoBUYAvxgoVq5FHsXCCCkLCVuJ1z4224ZUVZRGhyawuzbWyh"
]
}
List all blocks in an account.
- action: account_block_list.
- account: account to be queried for the blocks.
- limit: uplimit of the number of returned blocks. The maximum value is 1000.
- index:(optional)the current block query index. It should be derived from the return field
next_index
in the previous call ofaccount_block_list
. The default value is empty.
{
"action": "account_block_list",
"account": "mcp33EuccjKjcZgwbHYp8eLhoFiaKGARVigZojeHzySD9fQ1ysd7u",
"limit": 100
}
- code: error code. The code 0 is success.
- msg: error message.
- next_index: block query index. Return null if there are no more blocks left.
// Success
{
"code": 0,
"msg": "OK"
"blocks": [{...}, {...}, ...],
"next_index": "35EAB31538EBA6CBD8E3FC1C91BFEA425EE13A1CC66B5D650A6FF226B6698A27"
}
// Failed
{
"code": 4,
"msg": "Index not found"
}
Check balance of an account.
- action:account_balance.
- account: account to check the balance.
{
"action": "account_balance",
"account": "mcp33EuccjKjcZgwbHYp8eLhoFiaKGARVigZojeHzySD9fQ1ysd7u"
}
- code: error code. The code 0 is success.
- msg: error message.
- balance: balance of the account.
// Success
{
"code": 0,
"msg": "OK",
"balance": "1000000000000000000" // 1 CCN Token
}
// Failed
{
"code": 1,
"msg": "Invalid account"
}
Check the balance of multiple accounts.
- action:accounts_balances.
- accounts: account to check the balance.
{
"action": "accounts_balances",
"accounts": [
"mcp33EuccjKjcZgwbHYp8eLhoFiaKGARVigZojeHzySD9fQ1ysd7u",
"mcp4GHUc91PYAddCiDHtwFnFDcsQrqdXW58Ps75rpHJsxAnJrQR1d"
]
}
- code: error code. The code 0 is success.
- msg: error message.
- balances: balance of the accounts.
// Success
{
"code": 0,
"msg": "OK",
"balances": {
"mcp33EuccjKjcZgwbHYp8eLhoFiaKGARVigZojeHzySD9fQ1ysd7u": "1000000000000000000", //1 CCN Token
"mcp4m7NiSx2sBG4Hmdq1Yt6EGKqFQ3rmtBXCsmJZZp4E3pm84LkG9": "1000000000000000000" //1 CCN Token
}
}
// Failed
{
"code": 1,
"msg": "Invalid account"
}
Get the code of an account.
- action:account_code.
- account:account to get the code from.
{
"action": "account_code",
"account": "mcp4GHUc91PYAddCiDHtwFnFDcsQrqdXW58Ps75rpHJsxAnJrQR1d"
}
- code:error code. The code 0 is success.
- msg:error message.
- account_code:account code.
// Success
{
"code": 0,
"msg": "OK",
"account_code": "61016B610030600B82828239805160001A6073146000811461002057610022565BFE5B5030600052607381538281F3FE7300000000000000000000000000000000000000003014608060405260043610610052576000357C010000000000000000000000000000000000000000000000000000000090048063DCE4A44714610057575B600080FD5B6100996004803603602081101561006D57600080FD5B81019080803573FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF169060200190929190505050610114565B6040518080602001828103825283818151815260200191508051906020019080838360005B838110156100D95780820151818401526020810190506100BE565B50505050905090810190601F1680156101065780820380516001836020036101000A031916815260200191505B509250505060405180910390F35B6060813B6040519150601F19601F602083010116820160405280825280600060208401853C5091905056FEA165627A7A7230582027C83370D70C11D17B94A12CCB8F7856B88ED68CFC6363465293981CB633B25C0029"
}
// Failed
{
"code": 1,
"msg": "Invalid account"
}
Get the state of a contract.
- action: call.
- from: (optional) source account.
- to: destination account.
- data: (optional) data of the call method. Default is empty.
- mci: (optional) string. Acceptable values are "latest", "earliest" and number strings (e.g. "1352"). The default value is "latest".
{
"action":"call",
"from":"mcp4kYTyZTjRGQoEioCbT8JcKpDaqjJs2ekpxcucTC14SniuNABi6",
"to":"mcp3KfLt664eysPMc5pp1wTiRQhYELXM7EruDVoEPYWM4bmZRDZJq",
"data":"0DBE671F",
"mci": "earliest"
}
- code: error code. The code 0 is success.
- msg: error message.
- output: result of the call method
// Success
{
"code": 0,
"msg": "OK",
"output": "692A70D2E424A56D2C6C27AA97D1A86395877B3A2C6C27AA97D1A86395877B5C"
}
// Failed
{
"code": 3,
"msg": "Invalid to account"
}
Estimate the gas consumption of a transaction.
- action: estimate_gas.
- from: (optional) source account.
- to: (optional ) destination account.
- amount: (optional) string, amount of tokens for the transaction in the unit of 10-18 CCN.
- gas: (optional) string, uplimit of the gas for the transaction.
- gas_price: (optional) string, gas price in the unit of 10-18 CCN/gas.
gas fee = amount of gas consumed * gas_price
. - data: (optional) data of the transaction. The default value is empty.
- mci: (optional) string, acceptable values are "latest", "earliest" and number strings (e.g. "1352"). The default value is "latest".
{
"action": "estimate_gas",
"from": "mcp33EuccjKjcZgwbHYp8eLhoFiaKGARVigZojeHzySD9fQ1ysd7u",
"to": "mcp3dUnMEsuSiUsKGgfft5VDpM2bX9S6T4ppApHRfn1cBmn2znyEv",
"amount": "1000000000000000000",// 1 CCN Token
"gas": "21000",
"gas_price": "1000000000",
"data": "",
"mci": "838"
}
- code: error code. The code 0 is success.
- msg: error message.
- gas: estimated gas consumption.
// Success
{
"code": 0,
"msg": "OK",
"gas": "21000"
}
// Failed
{
"code": 9,
"msg": "Gas not enough or excute fail"
}
Get the event logs of smart contract execution.
- action: logs
- from_stable_block_index: (optional) begin index of the stable blocks to search for. The default value is 0.
- to_stable_block_index: (optional) end index of the stable blocks to search for. The default value is the index of the last stable block.
- account: (optional) account to search for. The default value is empty.
- topics: (optional) array of topics to search for. The default value is empty.
{
"action": "logs",
"account": "mcp3DG8FjYSAqkBNubcSVAAjAtSQ9Q2tWVNwPS8VHQ55XwWG4DsTS",
"topics":[ "260823607ceaa047acab9fe3a73ef2c00e2c41cb01186adc4252406a47d73446" ]
}
- code: error code. The code 0 is success.
- msg: error message.
- logs: arry of the logs.
// Success
{
"code": 0,
"msg": "OK",
"logs": [
{
"account": "mcp3DG8FjYSAqkBNubcSVAAjAtSQ9Q2tWVNwPS8VHQ55XwWG4DsTS",
"data": "0000000000000000000000000000000000000000000000000000000000000000",
"topics": [
"260823607ceaa047acab9fe3a73ef2c00e2c41cb01186adc4252406a47d73446"
]
},
{
"account": "mcp3DG8FjYSAqkBNubcSVAAjAtSQ9Q2tWVNwPS8VHQ55XwWG4DsTS",
"data": "0000000000000000000000000000000000000000000000000000000000000001",
"topics": [
"260823607ceaa047acab9fe3a73ef2c00e2c41cb01186adc4252406a47d73446"
]
}
]
}
// Failed
{
"code": 3,
"msg": "Invalid account"
}
Send a transaction. The parameter
rpc_control
need to be true
when run the mcp node program.- action: send_block.
- previous: (optional) specify the last block hash of the sender's account. It could be used to skip the blocks in the account that are not referenced by any witnesses.
- from: sender's account
- to: receiver's account.
- amount: string, amount of tokens to send in the unit of 10-18 CCN.
- password: sender's account password.
- gas: string, uplimit of the gas for the transaction. Unused gas fee will be returned to sender's account.
- gas_price: string, gas price in the unit of 10-18 CCN/gas.
gas fee = amount of gas consumed * gas_price
. - data: (optional) data or smart contract code. The default value is empty.
{
"action": "send_block",
"from": "mcp33EuccjKjcZgwbHYp8eLhoFiaKGARVigZojeHzySD9fQ1ysd7u",
"to": "mcp3dUnMEsuSiUsKGgfft5VDpM2bX9S6T4ppApHRfn1cBmn2znyEv",
"amount": "1000000000000000000",// 1 CCN Token
"password": "12345678",
"gas": "21000",
"gas_price": "1000000000",
"data": ""
}
- code: error code. The code 0 is success.
- msg: error message.
- hash: hash of the block.
// Success
{
"code": 0,
"msg": "OK",
"hash": "CDE1EC247CAC41C321024DCEBF065662A46A49A119EF0641C0547111FBCB315D"
}
// Failed
{
"code": 10,
"msg": "Wrong password"
}
Generate the block that has not been signed by the sender. Return the block details. The parameter
rpc_control
need to be true
when run the mcp node program.- action:generate_offline_block。
- previous: (optional) specify the last block hash of the sender's account. It could be used to skip the blocks in the account that are not referenced by any witnesses.
- from: sender's account
- to: receiver's account.
- amount: string, amount of tokens to send in the unit of 10-18 CCN.
- gas: string, uplimit of the gas for the transaction. Unused gas fee will be returned to sender's account.
- gas_price: string, gas price in the unit of 10-18 CCN/gas.
gas fee = amount of gas consumed * gas_price
. - data: (optional) data or smart contract code. The default value is empty.
{
"action": "generate_offline_block",
"from": "mcp33EuccjKjcZgwbHYp8eLhoFiaKGARVigZojeHzySD9fQ1ysd7u",
"to": "mcp3w6RT4KJ5CGocZRUqwuxUfUciLggCTAgpccLrMwxqgJuSB2iW6",
"amount": "1000000000000000000",
"gas": "21000",
"gas_price": "1000000000",
"data": ""
}
- code: error code. The code 0 is success.
- msg: error message.
- hash:hash of the block.
- previous:the last block of the sender's account.
- from: sender's account
- to: receiver's account.
- amount: string, amount of tokens to send in the unit of 10-18 CCN.
- gas: string, uplimit of the gas for the transaction. Unused gas fee will be returned to sender's account.
- gas_price: string, gas price in the unit of 10-18 CCN/gas.
gas fee = amount of gas consumed * gas_price
. - data: data or smart contract code.
// Success
{
"code": 0,
"msg": "OK",
"hash": "D6FB0D0F3D56F5B5D7C4B4D95D73701A341C68A92495D259B9836488CB60C383",
"from": "mcp33EuccjKjcZgwbHYp8eLhoFiaKGARVigZojeHzySD9fQ1ysd7u",
"to": "mcp3dUnMEsuSiUsKGgfft5VDpM2bX9S6T4ppApHRfn1cBmn2znyEv",
"amount": "1000000000000000000",
"previous": "0000000000000000000000000000000000000000000000000000000000000000",
"gas": "21000",
"gas_price": "1000000000",
"data": ""
}
// Failed
{
"code": 5,
"msg": "Invalid gas format"
}
Send a signed transaction. The value of the request fields are derived from generate_offline_block return fields. Returns the block hash. The parameter
rpc_control
need to be true
when run the mcp node program.- action:send_offline_block。
- previous: the last block of the sender's account.
- from: sender's account
- to: receiver's account.
- amount: string, amount of tokens to send in the unit of 10-18 CCN.
- password: sender's account password.
- gas: string, uplimit of the gas for the transaction. Unused gas fee will be returned to sender's account.
- gas_price: string, gas price in the unit of 10-18 CCN/gas.
gas fee = amount of gas consumed * gas_price
. - data: (optional) data or smart contract code. The default value is empty.
- signature: the signature of the block.
{
"action": "send_offline_block",
"previous": "0000000000000000000000000000000000000000000000000000000000000000",
"from": "mcp33EuccjKjcZgwbHYp8eLhoFiaKGARVigZojeHzySD9fQ1ysd7u",
"to": "mcp3w6RT4KJ5CGocZRUqwuxUfUciLggCTAgpccLrMwxqgJuSB2iW6",
"amount": "1000000000000000000",
"gas": "21000",
"gas_price": "1000000000",
"data": "",
"signature": "71408627FF461C9DE076A38B71953A3045C95D1E1E841A2224E4AC3E503C0D0046FE8FEEB6E72B257B7743F53AFEC1CE80699D5E125C60794D6D09823C3B1E0C"
}
- code: error code. The code 0 is success.
- msg: error message.
- hash: hash of the block.
// Success
{
"code": 0,
"msg": "OK",
"hash": "93B7A0ECCE8D23E6E1969FAA5B4326CEDA78032EEB44B5F85A26AFFA84F50D64"
}
// Failed
{
"code": 1,
"msg": "Invalid from account"
}
sign the message.
- action: sign_msg.
- public_key: public key of the signature.
- password: public key password.
- msg: message to be signed.
{
"action":"sign_msg",
"public_key": "mcp33EuccjKjcZgwbHYp8eLhoFiaKGARVigZojeHzySD9fQ1ysd7u",
"password":"[email protected]",
"msg":"CB09A146D83668AE13E951032D2FD94F893C9A0CA0822ED40BBE11DC0F167D1B"
}
- code: error code. The code 0 is success.
- msg: error message.
- hash: hash of the block.
// Success
{
"code": 0,
"msg": "OK",
"signature": "E09CDD795E6959C3B85FDCA0EA56BCFBBC7BE05A0D0AB6B1A0C6DD23FF0AA36F635C70CB731DAC07909A572132128120EBC12862D4BEC2FE70E9A6060F32CA0C"
}
// Failed
{
"code": 10,
"msg": "Wrong password"
}
Get details of one block.
- action: block
- hash: block hash
{
"action":"block",
"hash": "412254AB895FD2E6ADE6F9076CA8297516F2845C989A13AC008CD5D70157AFFB"
}
- code: error code. The code 0 is success.
- msg: error message.
- block: block details. If the block doesn't exist, this field is null.
- hash: block hash.
- type: block type. 0:genesis block, 1:witness block, 2:ordinary block.
- from: sender's account
- content: block contents, which are different for blocks with different types.
- genesisi block:
- to: receiver's account.
- amount: string, amount of tokens to send in the unit of 10-18 CCN.
- data_hash: hash of the data field.
- data: data or smart contract code.
- timestamp: timestamp when the block is generated.
- witness block:
- previous: hash of the latest block of sender's account before the current block. The value is 0 for the first block of the account.
- parents: list of the hashes of parent blocks on the DAG.
- links: list of the hashes of the ordinary blocks that the witness block referenced.
- last_stable_block: the last stable block of this block on the DAG.
- last_summary_block: the
last_stable_block
of the best parent of this block on the DAG.