Skip to content

Wallet RPC

BitHaru edited this page Jul 3, 2021 · 21 revisions

Overview

  • Only POST requests are allowed.
  • The data format should be JSON object.
  • All requests should contain a 'rai_api_key' field for authorization. You can set it in the http header or put it directly in JSON object.
  • The value of 'rai_api_key' can be found in wallet_rpc_config.json
  • You can add any extra fields in the request, the wallet will ignore them, but pass back in callback message.

RPC interfaces of raicoin_wallet_rpc

1. account_info

Get account information.
Request:

{
    "action":"account_info",  
    "account":"rai_1ikz4dmpt8m63hnt69b81977nsdozzsfgd7nd67oknnbsunkhmffm1sdox9m"  
}

Response:

{  
    "account": "rai_3bkdfk9id6acbqfma7iah4gahk6irhufaw4pkceitwe9ttgemubixqc7iemu",  
    "type": "transaction",  
    "head": "EE664793FE5D660A28585AC0F84232F435AE9BA94F7C0B215FBE14BD5F88E83F",  
    "head_height": "59",  
    "tail": "4DBFC63BFA920DB6D7BEFCF9E3459B28284C7638B6C70EFF65658909F228BAB6",  
    "tail_height": "0",  
    "confirmed_height": "59",  
    "forks": "0",  
    "restricted": "false",  
    "head_block": {  
        "type": "transaction",  
        "opcode": "receive",  
        "credit": "2",  
        "counter": "3",  
        "timestamp": "1600071141",  
        "height": "59",  
        "account": "rai_3bkdfk9id6acbqfma7iah4gahk6irhufaw4pkceitwe9ttgemubixqc7iemu",  
        "previous": "02357F23DD2244F6B55CAC7AC9C117347A43ECFAC35E8909F51B8DDFF34D90E6",  
        "representative": "rai_1nwbq4dzmo7oe8kzz6ox3bdp75n6chhfrd344yforc8bo4n9mbi66oswoac9",  
        "balance": "847500000000",  
        "link": "0E527BA98FD30923396A40266494CE1BE984F6BDA41C4D022DB37CDA747B5A03",  
        "extensions_length": "0",  
        "extensions": "",  
        "signature": "16B4ADEF878163FA8200CAB8C12819435257091E3853193EA01ECA4F0BBC023A30E"  
                     "D4ECCCED0F126BF04853BB5D79447D52151FD26CC6B018B42B7FCDB930500"
    },  
    "tail_block": {  
        "type": "transaction",  
        "opcode": "receive",  
        "credit": "1",  
        "counter": "1",  
        "timestamp": "1597477842",  
        "height": "0",  
        "account": "rai_3bkdfk9id6acbqfma7iah4gahk6irhufaw4pkceitwe9ttgemubixqc7iemu",  
        "previous": "0000000000000000000000000000000000000000000000000000000000000000",  
        "representative": "rai_1nwbq4dzmo7oe8kzz6ox3bdp75n6chhfrd344yforc8bo4n9mbi66oswoac9",  
        "balance": "9000000000",  
        "link": "5E2CA39A444155EC4FA04C97BA66AC3A38F82974D4041E779328578783ABB17E",  
        "extensions_length": "0",  
        "extensions": "",  
        "signature": "E8F24D79278C8D76162DEA1357FC20C4A370982F1FB961C9CA4A381EE837B2"  
                     "CC56985AC7FEE60393944233FF92ECA41AB50F1615B379826542123C1934967808"  
    },  
    "ack": "account_info"  
} 

2. account_send

Send coins to other.
Request:

{  
    "action": "account_send",  
    "amount": "100000000000000",  
    "to": "rai_1ikz4dmpt8m63hnt69b81977nsdozzsfgd7nd67oknnbsunkhmffm1sdox9m",  
    "note": "will be wrote into block, optional"  
}

Response:
The state "success" just means the request is accepted, you need to check the processed result in callback message.

{
    "success": "",
    "ack": "account_send"
}

or

{
    "error": "error reason",
    "ack": "account_send"
}

3. block_query

Query block details.
Request:
(1) by hash

{  
"action":"block_query",  
"hash":"EE664793FE5D660A28585AC0F84232F435AE9BA94F7C0B215FBE14BD5F88E83F"  
}  

(2) by block height

{  
"action":"block_query",  
"height":"59"  
}  

Response:

    {   'amount': '30000000000',
    'amount_in_rai': '30 RAI',
    'block': {   'account': 'rai_3bkdfk9id6acbqfma7iah4gahk6irhufaw4pkceitwe9ttgemubixqc7iemu',
                 'balance': '847500000000',
                 'counter': '3',
                 'credit': '2',
                 'extensions': '',
                 'extensions_length': '0',
                 'height': '59',
                 'link': '0E527BA98FD30923396A40266494CE1BE984F6BDA41C4D022DB37CDA747B5A03',
                 'opcode': 'receive',
                 'previous': '02357F23DD2244F6B55CAC7AC9C117347A43ECFAC35E8909F51B8DDFF34D90E6',
                 'representative': 'rai_1nwbq4dzmo7oe8kzz6ox3bdp75n6chhfrd344yforc8bo4n9mbi66oswoac9',
                 'signature': '16B4ADEF878163FA8200CAB8C12819435257091E3853193EA01ECA4F0BBC023A30ED4ECCCED0F126BF04853BB5D79447D52151FD26CC6B018B42B7FCDB930500',
                 'timestamp': '1600071141',
                 'type': 'transaction'},
    'hash': 'EE664793FE5D660A28585AC0F84232F435AE9BA94F7C0B215FBE14BD5F88E83F',
    'successor': '0000000000000000000000000000000000000000000000000000000000000000',
    'notify': 'account_receive',
    'source_block': {   'account': 'rai_3wiuzumk8nkgknkaze1grhrcid33xr4g85p6d91pjurq1es3cz3qbq3znr4c',
                        'balance': '2934105527252094',
                        'counter': '9',
                        'credit': '25',
                        'extensions': [{'length': '16', 'type': 'sub_account', 'value': 'your_app_user_id'}],
                        'extensions_length': '20',
                        'height': '1542',
                        'link': 'rai_3bkdfk9id6acbqfma7iah4gahk6irhufaw4pkceitwe9ttgemubixqc7iemu',
                        'opcode': 'send',
                        'previous': '71ED8566AED79B32E3D86FBCB5170831AEBF2C67729A452F1AC38CFE2D1EF99D',
                        'representative': 'rai_16zh585frh9umq1ts4kzfs3uxiyynt5pheyg8frnjou9n8566fsw8ro3bwpb',
                        'signature': '00C848AB8F4685E1E4DACE6463090D0F485687B25E418329B2F5814721829009C9871CAA9BD2BF1AA8B7A03CD290BB05CC21C077686735A57D4CC1AE9DACFA06',
                        'timestamp': '1600071135',
                        'type': 'transaction'},
    'success': ''}


Or

{
    "status": "miss",
    "ack": "block_query"
}

4. current_account

Get the working account in the wallet, in current version only one account is allowed.
Request:

{"action": "current_account"}

Response:

{
    "account": "rai_3bkdfk9id6acbqfma7iah4gahk6irhufaw4pkceitwe9ttgemubixqc7iemu",
    "ack": "current_account"
}

5. status

Get the wallet status.
Request:

{"action":"status"}

Response:

{
    "actions": "0",
    "requests": "0",
    "synced": "true",
    "ack": "status"
}

Reference:

https://github.com/raicoincommunity/Raicoin/blob/master/rai/rai_wallet_rpc/wallet_rpc.cpp#L178