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:
Summary
Method Name | Request Params | Response |
---|---|---|
|
| |
|
| |
|
| |
|
| |
( |
| |
|
| |
|
| |
|
| |
|
| |
|
| |
|
| |
|
| |
|
| |
(none) |
| |
|
| |
|
| |
|
| |
( | (none) | |
| ( | |
|
| |
|
| |
| (none) | |
| (none) | |
|
| |
|
| |
|
| |
|
|
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:
run_rad_request
The JsonRPC method run_rad_request
is used to execute a RAD request in order to test it functionally before deploying it on the network.
The request has as parameter a rad_request
, which has itself as parameters:
time_lock
: number, indicates the epoch from which the data request could run before, before this epoch the request is ignored.retrieve
: Array, is composed of a supported retrieve method, the url of the API from which get the data of the request, and the the bytes-serialized RADON script.aggregate
: Aggregate, includes the operators needed to perform the aggregation from the retrieves.tally
: Tally, includes the operators needed to perform the tally after the aggregation.
Example:
The response includes all the partial results of the request for the three different stages (retrieve
, aggregate
and tally
).
send_transaction
The method send_transaction
is used to broadcast a given transaction to the Witnet network. Apart from the wallet_id
and session_id
, it requires an already created transaction (e.g. by using the methods create_vtt) or create_data_request).
The request requires the following 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.transaction
: Transaction, serialized transaction object. It can be created by using the methods create_vtt) or create_data_request.
Example of a send_transaction
for sending 500 nanoWits to an address.
The response includes the JsonRPC response after sending the transaction to the node API and the balance movement that affects the wallet:
balance_movement
: BalanceMovement, the wallet balance movement, which is pending and has not yet been indexed into a block.jsonrpc_result
: Bool, the result of sending the transaction to the node using theintentory
JsonRPC API method.
set
The method set
allows to store 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.value
: Object, JSON object to be stored.
Response:
shutdown
To shutdown the wallet. It has no response, directly stops the wallet specified in the parameters. If no session_id
is provided, wallet will be shutdown only if there are no open sessions.
Request with parameters:
session_id
(optional): String, session ID assigned when unlocking the wallet. See unlock_wallet.
sign_data
This method uses the wallet's master key to sign message data.
The parameters are:
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.data
: String, the data to be signed.extended_pk
: Bool, if this flag is set to true, extended public key will be include (chaincode
). If leaked, wallet public addresses might be derived.
Example:
The response includes the parameters:
chaincode
: String, cryptographic material used to derive keys.public_key
:String, the wallet's public key.signture
:String, the signature.
unlock_wallet
The JsonRPC method unlock_wallet
is used to unlock the wallet with the specified identifier by providing a decryption key. This key will be hold in memory until the wallet is locked again. By default, sessions will expired after 1 hour. As long as a wallet is unlocked, you can operate it without having to supply the password again by just using the session ID, until it expires.
Request with parameters:
wallet_id
: String, the ID associated to the wallet. See get_wallet_infos.password
: String, the password that unlocks the wallet.
Response:
session_id
: number, generated identifier for the current wallet session.session_expiration_secs
: number, amount of seconds after which the session will expire.account_balance
: number, wallet's account balance in nano Wits.name
: String, human-friendly name for the wallet.caption
: String, human-friendly caption for the wallet.current_account
: number, identifies the current active account in the session (the current version only supports the default account0
).available_accounts
: Array, list of available accounts in the wallet.
update_wallet
The JsonRPC method update_wallet
is used to update the name and/or caption of an existing wallet.
Request with parameters:
wallet_id
: String, the ID associated to the wallet. See get_wallet_infos.session_id
: number, generated identifier obtained from unlocking the wallet. See Unlock Wallet.name
: String, wallet name shown in get_wallet_infos.description
: String, wallet private description (only available for authenticated clients after unlock_wallet).
Response:
success
: Boolean, reporting if the wallet's update was successfull.
validate_mnemonics
The JsonRPC method validate_mnemonics
is used to verify that validity of the seed source that might be used to generate a new wallet.
Request with parameters:
seed_source
:"mnemonics"|"xprv"
, literal to identify if the seed source is of the type mnemonics or xprv.seed_data
: String, containing the used seed data, either a list of mnemonic words or axprv
.backup_password
(optional): String, in case that seed source is"xprv"
,seed_data
must be decrypted with this parameter.
Response:
valid
: Boolean, true if valid seed in form of mnemonics orxprv
.
Last updated