Links
Comment on page

Wallet API Reference

The wallet exposes a JSON-RPC API over Websocket by default at the URL 127.0.0.1:11212. It can be set in the Witnet configuration file as follows:
[wallet]
server_addr = "127.0.0.1:11212"

Summary

Method Name
Request Params
Response
session_id
success
session_id, wallet_id, request, fee, (fee_type)
bytes, transaction, transaction_id
length
mnemonics
session_id, wallet_id, fee, (fee_type), [address, value, (time_lock)], (utxo_strategy), (selected_utxos)
bytes, metadata, transaction, transaction_id
(name), (description), seed_source, seed_data, password, (overwrite), (backup_password), (birth_date)
wallet_id
session_id, wallet_id
success
session_id, wallet_id, password
private_key
session_id, wallet_id, (external)
address, path
get
session_id, wallet_id, key
value
session_id, wallet_id, (offset), (limit), (external)
address[], total
session_id, wallet_id
confirmed, local, unconfirmed
session_id, wallet_id, (offset), (limit)
transactions[], total
session_id, wallet_id
output_info[]
(none)
wallet_info[]
session_id, wallet_id
success
session_id
success
session_id, wallet_id
success
rpc.off
(subscription_id[])
(none)
rpc.on
session_id
(subscription_id)
request
result
session_id, wallet_id, transaction
balance_movement, jsonrpc_result
set
session_id, wallet_id, key, value
(none)
shutdown
session_id
(none)
sign_data
session_id, wallet_id, data, extended_pk
chaincode, public_key, signature
wallet_id, password
session_id, session_expiration_secs, ...
session_id, wallet_id, (name), (description)
success
seed_source, seed_data, (backup_password)
exist, wallet_id

Wallet API Endpoints

create_data_request

The method create_data_request creates a data request transaction object. It contains all required cryptographic information in order to be later sent to a Witnet node (e.g. by using the method send_transaction).
Request with parameters:
  • session_id: number, generated identifier obtained from unlocking the wallet. See Unlock Wallet.
  • wallet_id: String, the ID associated to the wallet. See get_wallet_infos.
  • fee: number, amount in nanoWitswill be earned by the miner that publishes the request.
  • fee_type: (optional) String, fee type chosen between weighted or absolute. Defaults to weighted if not inserted.
  • request: DataRequestOutput, a struct with required data request fields.
    • data_request: RADRequest, data request with CBOR codification.
    • witness_reward: number, reward in nanoWits to the witnesses of the data request.
    • witnesses: number, minimum number of witnet nodes that must perform the request.
    • commit_and_reveal_fee: number, amount in nanoWits that will be earned by the miner for each each valid commitment and reveal transaction.
    • min_consensus_percentage: number, , minimum of consensus required to consider the request as valid.
    • collateral: number, collateral amount in nanoWits.
More information about the parameters can be found in the tutorial of data request parameters fine-tuning.
As an example, this data request created a data request that retrives the last Bitcoin blockhash from two different sources using three witnesses:
{
"jsonrpc": "2.0",
"method": "create_data_request",
"id": "1",
"params": {
"session_id": "678f4320d8f8ff1a9f86f56f20f0c6a76fba92db0e8e5b1fd2f21092de985f3e",
"wallet_id": "8f5b85981addad621a86f01a1ddb646ccd90620c95247948ce8d99feefd0496c",
"request": {
"data_request": {
"time_lock": 0,
"retrieve": [
{
"kind": "HTTP-GET",
"url": "https://blockchain.info/q/latesthash",
"script": [
128
]
},
{
"kind": "HTTP-GET",
"url": "https://api-r.bitcoinchain.com/v1/status",
"script": [130, 24, 119, 130, 24, 103, 100, 104, 97, 115, 104]
}
],
"aggregate": {
"filters": [],
"reducer": 2
},
"tally": {
"filters": [
{
"op": 8,
"args": []
}
],
"reducer": 2
}
},
"witness_reward": 1000,
"witnesses": 3,
"commit_and_reveal_fee": 10,
"min_consensus_percentage": 51,
"collateral": 1000000000
},
"fee": 0
}
}
The create_data_request response will include the following data:
  • bytes: String, data request bytes represented in hexadecimal format.
  • transaction: DataRequest, all transactional information regarding the created data request.
    • body: Includes the data request output, inputs and outputs of the transaction.
    • signatures: The signature of the transaction and the public key
  • transaction_id: String, unique transaction identifier.
Example of a create_data_request response:
{
"jsonrpc": "2.0",
"result": {
"bytes": "1297030aa0020a280a260a220a201a79a8689f9ede624043993b620e6042d2b7e80573c19f6752328db4a25c6fc41001121f0a160a14e6635e52a21ab22eaf27bdd036dd104b25d712c310eeabd2d4d1031ad2010abc011229122468747470733a2f2f626c6f636b636861696e2e696e666f2f712f6c6174657374686173681a01801237122868747470733a2f2f6170692d722e626974636f696e636861696e2e636f6d2f76312f7374617475731a0b8218778218676468617368124a122868747470733a2f2f6170692e626c6f636b63686169722e636f6d2f626974636f696e2f73746174731a1e83187782186664646174618218676f626573745f626c6f636b5f686173681a02100222060a020808100210e8071803200a280a301e3833408094ebdc0312720a4b0a490a473045022100dc671fb90cab42baa3a8e26bcd91da954b05299840539288624518ecc3b85140022033d6d65405ada2a72a1a55bb33577a76ef9ab320b58df96a4ce0ab498042620212230a2103f0acd97ec011b875376888b3538f70644e2ad537f61169e95b7c703176925d00",
"transaction": {
"DataRequest": {
"body": {
"dr_output": {
"collateral": 1000000000,
"commit_and_reveal_fee": 10,
"data_request": {
"aggregate": {
"filters": [],
"reducer": 2
},
"retrieve": [
{
"kind": "HTTP-GET",
"script": [
128
],
"url": "https:\/\/blockchain.info\/q\/latesthash"
},
{
"kind": "HTTP-GET",
"script": [130,24,119,130,24,103,100,104,97,115,104],
"url": "https:\/\/api-r.bitcoinchain.com\/v1\/status"
}
],
"tally": {
"filters": [
{
"args": [],
"op": 8
}
],
"reducer": 2
},
"time_lock": 0
},
"min_consensus_percentage": 51,
"witness_reward": 1000,
"witnesses": 3
},
"inputs": [
{
"output_pointer": "1a79a8689f9ede624043993b620e6042d2b7e80573c19f6752328db4a25c6fc4:1"
}
],
"outputs": [
{
"address": "twit1ue34u54zr2ezate8hhgrdhgsfvjawykr9kxtqq",
"time_lock": 0,
"value": 124999996910
}
]
},
"signatures": [
{
"public_key": {
"bytes": [240,172,217,126,192,17,184,117,55,104,136,179,83,143,112,100,78,42,213,55,246,17,105,233,91,124,112,49,118,146,93,0],
"compressed": 3
},
"signature": {
"Secp256k1": {
"der": [48,69,2,33,0,220,103,31,185,12,171,66,186,163,168,226,107,205,145,218,149,75,5,41,152,64,83,146,136,98,69,24,236,195,184,81,64,2,32,51,214,214,84,5,173,162,167,42,26,85,187,51,87,122,118,239,154,179,32,181,141,249,106,76,224,171,73,128,66,98,2]
}
}
}
]
}
},
"transaction_id": "b7dbb6fdbf5f07ab6d0b037a9e2119d102172f372ffcdf4630122d1b2914ae02"
},
"id": "1"
}

create_mnemonics

The JsonRPC method create_mnemonics is used to generate a BIP39 mnemonic sentence that can be used to generate a new HD wallet.
Request with parameters:
  • length: number, indicating how many words the mnemonic sentence should have. Must be one of these: 12, 15, 18, 21 or 24.
{
"jsonrpc": "2.0",
"method": "create_mnemonics",
"params": {
"length": 12
},
"id": 1
}
Response:
  • mnemonics: String, list of words of the mnemonic sentences.
{
"jsonrpc": "2.0",
"result": {
"mnemonics": "day voice lake monkey suit bread occur own cattle visit object ordinary"
},
"id": 1
}

create_vtt

The method create_vtt is used to generate a Value Transfer Transaction (VTT) object. It will contain all required cryptographic information in order to be later broadcasted to a Witnet node (e.g. by using the method send_transaction).
Request with parameters:
  • session_id: String, session ID assigned when unlocking the wallet. See unlock_wallet.
  • wallet_id: String, ID associated to the wallet. See get_wallet_infos.
  • fee: number, miner fee in nanoWits.
  • fee_type (optional): String, fee type chosen between weighted or absolute. Defaults to weighted if not inserted.
  • label (optional): String, label to refer the vtt.
  • outputs: Array, list of transaction outputs.
    • address: String, the recipient address.
    • amount: number, value to transfer in nanoWits.
    • time_lock: number, indicates the epoch from which the data request could run before, before this epoch the request is ignored.
  • utxo_strategy (optional): random | big_first | small_first, enum that allows to choose 3 different strategies for selecting which unspent transaction outputs are used as input of the VTT transaction.
  • selected_utxos (optional): Array, array of selected output pointers to be spent.
Example:
{
"jsonrpc": "2.0",
"method": "create_vtt",
"params": {
"session_id": "7bbb8d1bec5419451fa57ae686de93d26e8d265b9328f5dc2f1e6e28acac4201",
"wallet_id": "8f5b85981addad621a86f01a1ddb646ccd90620c95247948ce8d99feefd0496c",
"fee": 1,
"label": "",
"outputs": [
{
"address": "twit1nfkythqds4r2hz3le2zaauxtl7yum76jd0ut9c",
"amount": 1000,
"time_lock": 0
}
],
"utxo_strategy": "random",
"selected_utxos": [
"3a1ff5de49142d21280dc62dbdc02810a9665e9c23bb27b9094d6dbd6f4e527f:0",
"3cebaae8cc942056c475d7f9866a5de1be41aea0a1bcdb63edd533b9caef4043:0"
]
},
"id": 1
}
The create_vtt response will include all the information about the transaction:
  • bytes: String, data request bytes represented in hexadecimal format.
  • metadata: description of the outcome of the transaction, includes
    • fee: number, miner fee in nanoWits.
    • time_lock: number, indicates the epoch from which the funds will be available, before this epoch the funds are blocked.
    • to: String, the address of the reciever.
    • value: number, value that has been transferd in nanoWits.
  • transaction: ValueTransfer, all transactional information regarding the created value transfer.
    • body: Includes the inputs and outputs of the transaction.
    • signatures: The signature of the transaction and the public key
  • transaction_id: String, unique transaction identifier.
Example of a create_vtt response:
{
"jsonrpc": "2.0",
"result": {
"bytes": "0add010a670a280a260a220a204c4cc66b8bf7828797596ded89db7ddb1cd5b44dc18007738ef3d40e089a6add1001121a0a160a149a6c45dc0d8546ab8a3fca85def0cbff89cdfb521001121f0a160a1425e15594103fde1d9864807d091923ab648d6d1f10fec3d2d4d10312720a4b0a490a4730450221008e0c49acdcc92f63c6c71aa1ce7bb4d0524775c8e0af9d597d1b8bdfd8d2741e02201edd0d276786f7fcf319c4157501dca9c74457cac3b385a7475e6de85e1d826712230a2103f0acd97ec011b875376888b3538f70644e2ad537f61169e95b7c703176925d00",
"metadata": {
"fee": 1,
"time_lock": 0,
"to": "wit1nfkythqds4r2hz3le2zaauxtl7yum76jr6409f",
"value": 1
},
"transaction": {
"ValueTransfer": {
"body": {
"inputs": [
{
"output_pointer": "4c4cc66b8bf7828797596ded89db7ddb1cd5b44dc18007738ef3d40e089a6add:1"
}
],
"outputs": [
{
"address": "twit1nfkythqds4r2hz3le2zaauxtl7yum76jd0ut9c",
"time_lock": 0,
"value": 1
},
{
"address": "twit1yhs4t9qs8l0pmxrysp7sjxfr4djg6mgldk69zs",
"time_lock": 0,
"value": 124999999998
}
]
},
"signatures": [
{
"public_key": {
"bytes": [240, 172, 217, 126, 192, 17, 184, 117, 55, 104, 136, 179, 83, 143, 112, 100, 78, 42, 213, 55, 246, 17, 105, 233, 91, 124, 112, 49, 118, 146, 93, 0],
"compressed": 3
},
"signature": {
"Secp256k1": {
"der": [48, 69, 2, 33, 0, 142, 12, 73, 172, 220, 201, 47, 99, 198, 199, 26, 161, 206, 123, 180, 208, 82, 71, 117, 200, 224, 175, 157, 89, 125, 27, 139, 223, 216, 210, 116, 30, 2, 32, 30, 221, 13, 39, 103, 134, 247, 252, 243, 25, 196, 21, 117, 1, 220, 169, 199, 68, 87, 202, 195, 179, 133, 167, 71, 94, 109, 232, 94, 29, 130, 103]
}
}
}
]
}
},
"transaction_id": "66387166eba2d8af0b55bf309b9557ae812bdec0039fc45ece1f744ed309816f"
},
"id": 18
}

create_wallet

The JsonRPC method create_wallet is used to generate a new Master Key for an empty HD wallet that is stored encrypted in the file system.
Request with parameters:
  • name (optional): String, human-friendly name for the wallet.
  • description (optional): String, human-friendly caption for the wallet.
  • seed_source: "mnemonics"|"xprv", literal to identify if the seed source is of the type mnemonics or xprv and determine how the HD wallet master key will be generated from the data sent in the seedData parameter.
  • seed_data: String, data used for generating the new HD wallet master key.
  • password: String, password that will seed the key used to encrypt the wallet in the file system. The password must have at least eight characters.
  • overwrite (optional): Boolean, in case that seed data was previously used for creating another wallet, this flag will overwrite the previous wallet with the new one.
  • backup_password (optional): String, in case that seed source is "xprv", seed_data must be decrypted with this parameter.
  • birth_date (optional): current | imported (number), data used to specify from which block number the wallet should start synchronizing (for importing wallets from a previously used seed phrase).
{
"jsonrpc": "2.0",
"method": "create_wallet",
"params": {
"name": "Wallet #1",
"description": "Personal use",
"seed_source": "mnemonics",
"seed_data": "exotic demand way fatigue skull poverty happy divide scrub seed jeans novel",
"password": "12345678",
"overwrite": false,
"backup_password": null,
"birth_date": {"imported": 10000}
},
"id": 1
}
Response:
  • wallet_id: String, ID associated with the given wallet.
{
"jsonrpc": "2.0",
"result": {
"wallet_id": "6c344625884c2f910065ab170dc18ad3cbbc03c7234507c7c22dbd78e3b26667"
},
"id": 1
}

close_session

The JsonRPC method close_session is used to close an active session without locking the currently unlocked wallet.
Request with parameters:
  • session_id: String, session ID assigned when unlocking the wallet. See unlock_wallet.
{
"jsonrpc": "2.0",
"method": "close_session",
"params": {
"session_id": "9fa1d779afea88a29768dd05647e37b2f64fc103c1081b0ee9e62fb283f5cd02"
},
"id": "1"
}
Response:
  • success: Boolean, reporting if the wallet was successfully closed.
{
"jsonrpc": "2.0",
"result": {
"success": true
},
"id": "1"
}

delete_wallet

The JsonRPC method delete_wallet is used to delete the wallet with the specified ID. It also removes the current active session.
Request with parameters:
  • session_id: String, session ID assigned to you when you unlocked the wallet. See unlock_wallet.
  • wallet_id: String, ID associated to the wallet. See get_wallet_infos.
{
"jsonrpc": "2.0",
"method": "delete_wallet",
"params": {
"session_id": "9fa1d779afea88a29768dd05647e37b2f64fc103c1081b0ee9e62fb283f5cd02",
"wallet_id": "6c344625884c2f910065ab170dc18ad3cbbc03c7234507c7c22dbd78e3b26667"
},
"id": "1"
}
Response:
  • success: Boolean, reporting if the wallet was successfully deleted.
{
"jsonrpc": "2.0",
"result": {
"success": true
},
"id": "1"
}

export_master_key

The JsonRPC method export_master_key is used to export the master key of an existing wallet. This key is encrypted with a user-defined password using AES-CBC.
Request with parameters:
  • session_id: String, session ID assigned when unlocking the wallet. See unlock_wallet.
  • wallet_id: String, ID associated to the wallet. See get_wallet_infos.
  • password: String, user-defined password used to encrypt the key.
{
"jsonrpc": "2.0",
"method": "create_wallet",
"params": {
"session_id": "9fa1d779afea88a29768dd05647e37b2f64fc103c1081b0ee9e62fb283f5cd02",
"wallet_id": "6c344625884c2f910065ab170dc18ad3cbbc03c7234507c7c22dbd78e3b26667",
"password":
"12345678"
},
"id": 1
}
Response:
  • wallet_id: String, ID associated with the given wallet.
{
"jsonrpc": "2.0",
"result": {
"wallet_id": "6c344625884c2f910065ab170dc18ad3cbbc03c7234507c7c22dbd78e3b26667"
},
"id": 1
}

generate_address

The JsonRPC method generate_address is used to derive deterministically a new external address for the given wallet and session ID.
Request with parameters:
  • session_id: String, session ID assigned when unlocking the wallet. See unlock_wallet.
  • wallet_id: String, ID associated to the wallet. See get_wallet_infos.
  • external (optional): Boolean, if set to false it will generate an internal address.
{
"jsonrpc": "2.0",
"method": "generate_address",
"params": {
"session_id": "9fa1d779afea88a29768dd05647e37b2f64fc103c1081b0ee9e62fb283f5cd02",
"wallet_id": "6c344625884c2f910065ab170dc18ad3cbbc03c7234507c7c22dbd78e3b26667"
},
"id": "1"
}
Response:
  • address: String, address derived deterministically.
  • path: String, derivation path used to generate the address.
{
"jsonrpc": "2.0",
"result": {
"address": "twit1gtvu9a37w9sxaej30grp9rpxkkwwjk3pq0jqf9",
"path": "m/3'/4919'/0'/0/0"
},
"id": "1"
}

get

The method get allows to retrieve a previous stored key-value data in the wallet database.
Request with parameters:
  • wallet_id: String, the ID associated to the wallet. See get_wallet_infos.
  • session_id: String, session ID assigned when unlocking the wallet. See unlock_wallet.
  • key: String, key under which the value will be stored.
{
"jsonrpc": "2.0",
"method": "get",
"params": {
"wallet_id": "d5b53a4c40388a9be87acaf5a4dec9fd5c48f94913734bff88a08b18a618c76b",
"session_id": "5982a279bbd201192f9d3685975c6cebb714ac32dea00cfea80e2013d510e35e",
"key": "templates"
},
"id": 1
}
Response:
{
"jsonrpc": "2.0",
"result": {
"value": {
"name": "object"
}
},
"id": 1
}

get_addresses

The JsonRPC method get_addresses is used to query for a list of previously derived addresses given a wallet and session ID.
Request with parameters:
  • session_id: String, session ID assigned when unlocking the wallet. See unlock_wallet.
  • wallet_id: String, ID associated to the wallet. See get_wallet_infos.
  • offset (optional): number, initial position of the address list to be queried (by default is set to 0).
  • limit (optional): number, size of the address list to be returned (by default is set to 25).
  • external (optional): Boolean, if set to false it will get internal addresses.
{
"jsonrpc": "2.0",
"method": "get_addresses",
"params": {
"session_id": "9bcb54bf7494c21c29ef97256f6741b5b5bd5cb31d09d38e5ce98699010beea7",
"wallet_id": "8f5b85981addad621a86f01a1ddb646ccd90620c95247948ce8d99feefd0496c",
"offset": 0,
"limit": 25
},
"id": "1"
}
Response with an array of addresses and additional related information:
  • addresses: Array, list of queried addresses with additional information.
    • account: number, identifies the current account in the session (the current version only supports the default account 0).
    • address: String, address serialized in Bech32 format.
    • index: number, sequential index used to derive address.
    • info: String, additional information with balance movements and dates.
      • first_payment_date: number, date of first received movement in UTC format (Coordinated Universal Time).
      • label: String, user-defined label for this address.
      • last_payment_date: number, date of last received movement in UTC format (Coordinated Universal Time).
      • received_amount: number, total amount (in nanoWits) received by this address.
      • received_payments: Array, list of Unspent Transaction Outputs (UTXOs) proving funds to this address.
    • keychain: number, change value of the derivation path (See BIP-44).
    • path: String, derivation path used to generate the address.
{
"jsonrpc": "2.0",
"result": {
"addresses": [
{
"account": 0,
"address": "twit1eghyyar76nuvdfu0h70f4gmxruj2rw4g8x2nn8",
"index": 0,
"info": {
"first_payment_date": 1592476860,
"label": null,
"last_payment_date": 1592476860,
"received_amount": 125000000000,
"received_payments": [
"78bd0d8e4ef8ab67d4f18b357545f9dc73f63b7bf97a9a20c69b91b9e17ba985:1"
]
},
"keychain": 0,
"path": "m/3'/4919'/0'/0/0",
}
],
"total": 1
},
"id": "1"
}

get_balance

The JsonRPC method get_balance is used to query the current balance for a given wallet.
Request with parameters:
  • session_id: String, session ID assigned to you when you unlocked the wallet. See unlock_wallet.
  • wallet_id: String, ID associated to the wallet. See get_wallet_infos.
{
"jsonrpc": "2.0",
"method": "get_balance",
"params": {
"session_id": "9fa1d779afea88a29768dd05647e37b2f64fc103c1081b0ee9e62fb283f5cd02",
"wallet_id": "6c344625884c2f910065ab170dc18ad3cbbc03c7234507c7c22dbd78e3b26667"
},
"id": "1"
}
Response with different types of balances:
  • local: number, amount of local pending movements not yet indexed in a block.
  • unconfirmed: BalanceInfo, total amount of wallet's funds after last block, but not yet confirmed by a superblock.
    • available: number, unconfirmed expendable funds.
    • locked: number, unconfirmed time-locked funds.
  • confirmed: BalanceInfo, total amount of wallet's funds after last confirmed superblock.
    • available: number, confirmed expendable funds.
    • locked: number, confirmed time-locked funds.
{
"jsonrpc": "2.0",
"result": {
"confirmed": {
"available": 0,
"locked": 0
},
"local": 0,
"unconfirmed": {
"available": 0,
"locked": 0
}