@midnight-ntwrk/wallet-api v3.5.0 • Readme | API
@midnight-ntwrk/wallet-api v3.5.0 / Wallet
Interface: Wallet
Wallet API
Remarks
Wallet is a data structure that holds the state of the wallet and provides methods for proving, balancing, and submitting transactions.
Methods
balanceTransaction()
balanceTransaction(tx, newCoins): Promise<BalanceTransactionToProve | NothingToProve>
Balances the provided transaction.
Parameters
• tx: Transaction
Transaction to balance
• newCoins: CoinInfo
[]
CoinInfo array of coins created by the transaction, which the wallet will watch for and apply to the state
The newCoins
parameter should be used in cases where a new coin is created (for example, a DApp mints a coin and wants to send it to the wallet).
Because of how Midnight works, newly created coins must be explicitly sent to the wallet using this method. This allows the wallet to monitor them and
incorporate them into its state.
Returns
Promise
<BalanceTransactionToProve
| NothingToProve
>
BalanceTransactionToProve or NothingToProve recipe (for the already balanced transaction) or error.
Remarks
Balancing a transaction means that for any given output and transaction fees, the wallet will take the available coins from the state to cover them.
proveTransaction()
proveTransaction(recipe): Promise<Transaction>
Calls the proving server with the proving recipe and returns the proven transaction or error.
Parameters
• recipe: ProvingRecipe
ProvingRecipe with data to prove
Returns
Promise
<Transaction
>
Transaction or error
Remarks
- Proof generation takes time and resources, therefore depending on the user's computer specs, this can be an expensive operation
- There can be wallet implementations that do not need to support proving, in which case this method should return an error
serializeState()
serializeState(): Promise<string>
Serializes and returns the current state of the wallet which contains:
- The zswap local state
- The transaction history
- The offset in the blockchain corresponding to this state
- The protocol version
- The network ID
Returns
Promise
<string
>
Serialized WalletState in stringified JSON format
state()
state(): Observable<WalletState>
Observable (rx.js) stream of WalletState
Returns
Observable
<WalletState
>
Remarks
Should update every time there's a state update
submitTransaction()
submitTransaction(tx): Promise<string>
Submits the provided transaction to the node
Parameters
• tx: Transaction
Transaction to submit
Returns
Promise
<string
>
TransactionIdentifier - First transaction identifier from identifiers list or error
transferTransaction()
transferTransaction(outputs): Promise<TransactionToProve>
Prepares a transfer transaction
Parameters
• outputs: TokenTransfer
[]
An array of TokenTransfer a user wants to perform.
Returns
Promise
<TransactionToProve
>
Recipe with TransactionToProve or error