Wallet API Reference
The wallet server 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:
Summary
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
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
(subscription_id[]
)
(none)
session_id
(subscription_id
)
request
result
session_id
, wallet_id
, transaction
balance_movement
, jsonrpc_result
session_id
, wallet_id
, key
, value
(none)
session_id
(none)
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 betweenweighted
orabsolute
. Defaults toweighted
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:
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:
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
or24
.
Response:
mnemonics
: String, list of words of the mnemonic sentences.
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 betweenweighted
orabsolute
. Defaults toweighted
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:
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, includesfee
: 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:
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 theseedData
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).
Response:
wallet_id
: String, ID associated with the given wallet.
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.
Response:
success
: Boolean, reporting if the wallet was successfully closed.
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.
Response:
success
: Boolean, reporting if the wallet was successfully deleted.
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.
Response:
wallet_id
: String, ID associated with the given wallet.
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.
Response:
address
: String, address derived deterministically.path
: String, derivation path used to generate the address.
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.
Response:
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 to0
).limit
(optional): number, size of the address list to be returned (by default is set to25
).external
(optional): Boolean, if set to false it will get internal addresses.
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 account0
).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.
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.
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.
get_transactions
The JsonRPC method get_transactions
is used to query for a list of transactions 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 transaction list to be queried (by default is set to0
).limit
(optional): number, size of the transaction list to be returned (by default is set to25
).
Response with an array of transactions and additional related information:
total
: number, total amount of wallet transactions.transactions
: Array, list of queried transactions with additional information.amount
: number, transaction value.type
:"POSITIVE"|"NEGATIVE"
, type of balance movement in relation to the wallet.transaction
: Transaction, additional transaction information.block
: Block, information of block in which the transaction was included.block_hash
: String, block hash in hexadecimal format.epoch
: number block epoch.
data
: TransactionData, additional type-specific transaction data. The supported transaction types arevalue_transfer
,data_request
,tally
,mint
andcommit
.hash
: String, transaction hash in hexadecimal format used as identifier.miner_fee
: number, amount of nanoWits for the block miner.timestamp
: number, transaction date in UTC format (Coordinated Universal Time).
get_utxo_info
The JsonRPC method get_utxo_info
is used to query the current unspent transaction outputs 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.
Response with a HashMap with all the information about the unspent transaction outputs of a specified wallet:
output_info[]
: HashMap<String, OutputInfo>, information related of all the unspent transaction outputs (amount
,pkh
andtime_lock
)
get_wallet_infos
The JsonRPC method get_wallet_infos
displays the information about the wallet.
This method has no parameters, as an example:
Response:
caption
: String, human-friendly caption for the wallet.id
: String, wallet ID.name
:String, human-friendly name for the wallet.
lock_wallet
The JsonRPC method lock_wallet
is used to lock the wallet with the specified ID and close the active session. The decryption key for that wallet (hold in memory) is forgotten and the wallet server will be unable to update that wallet information until it is unlocked again.
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.
Response:
success
: Boolean, reporting if the wallet was successfully locked.
refresh_session
The JsonRPC method refresh_session
is used to refresh an active session of a currently unlocked wallet. This call will reset the session expiration time for the given session.
Request with parameters:
session_id
: String, session ID assigned when unlocking the wallet. See unlock_wallet.
Response:
success
: Boolean, reporting if the wallet was successfully refreshed.
resync_wallet
The JsonRPC method resync_wallet
is used to trigger a re-synchronization of the wallet with the specified ID. The wallet will reset all previously synchronized wallet data and it will index again all previous blockchain transactions.
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.
Response:
success
: Boolean, reporting if the wallet has successfully re-synchronized.
rpc.off
Use this method rpc.off
to unsubscribe from previous subscriptions.
Request with parameters:
<data>
: Array, subscription identifiers assigned when subscribing to wallet sessions. See rpc.on.
The response for a successful unsubscribe:
rpc.on
Use this method rpc.on
to subscribe to update events related to your session wallets.
Request with parameters:
session_id
: String, session ID assigned when unlocking the wallet. See unlock_wallet.
The response is:
result
: String, subscription identifier that can be used to unsubscribe from notifications. See rpc.off.
Here is an example of a block event sent out by a node: