Create a Wallet Account
The first thing you will need to do when you are getting started with the wallet.rs library is to create a wallet account.
Account Approaches
Wallet.rs supports a multi-account approach and a single-account approach.
Code Example
The following example will:
- Create an account manager.
- Use it to store the Stronghold mnemonic.
- Create a wallet with the alias "Alice".
- Rust
- Nodejs
- Python
- Java
Dotenv
This example uses dotenv, which is not safe for use in production environments.
wallet/examples/01_create_wallet.rs
loading...
Run the example by running the following command:
cargo run --example create_wallet --release
wallet/bindings/nodejs/examples/1-create-account.js
loading...
You can run the example by running the following command from the wallet/bindings/nodejs/examples/
folder:
node 1-create-account.js
wallet/bindings/python/examples/0-create-account.py
loading...
You can run the example by running the following command from the binding/python/examples
folder:
python3 0-create-account.py
wallet/bindings/java/examples/src/CreateAccount.java
loading...
Expected Output
- Rust
- Nodejs
- Python
- Java
Generated a new account
Account created: Account {
meta: {
index: 0,
coinType: 4219,
alias: 'Alice',
publicAddresses: [ [Object] ],
internalAddresses: [],
addressesWithUnspentOutputs: [],
outputs: {},
lockedOutputs: [],
unspentOutputs: {},
transactions: {},
pendingTransactions: [],
incomingTransactions: {}
},
messageHandler: MessageHandler { messageHandler: [External: 7f29dde5bf80] }
}
Account created: Account {
meta: {
index: 1,
coinType: 4219,
alias: 'Bob',
publicAddresses: [ [Object] ],
internalAddresses: [],
addressesWithUnspentOutputs: [],
outputs: {},
lockedOutputs: [],
unspentOutputs: {},
transactions: {},
pendingTransactions: [],
incomingTransactions: {}
},
messageHandler: MessageHandler { messageHandler: [External: 7f29dde5bf80] }
}
{
'index': 0,
'coinType': 4219,
'alias': 'Alice',
'publicAddresses': [
{
'address': 'rms1qzpf0tzpf8yqej5zyhjl9k3km7y6j0xjnxxh7m2g3jtj2z5grej67sl6l46',
'keyIndex': 0,
'internal': False,
'used': False
}
],
'internalAddresses': [],
'addressesWithUnspentOutputs': [],
'outputs': {},
'lockedOutputs': [],
'unspentOutputs': {},
'transactions': {},
'pendingTransactions': [],
'incomingTransactions': {}
}
{
"index": 0,
"coinType": 4219,
"alias": "Hans",
"publicAddresses": [
{
"address": "rms1qpx0mcrqq7t6up73n4na0zgsuuy4p0767ut0qq67ngctj7pg4tm2ynsuynp",
"keyIndex": 0,
"isInternal": false,
"used": false
}
],
"internalAddresses": [],
"addressesWithUnspentOutputs": [],
"outputs": {},
"lockedOutputs": [],
"unspentOutputs": {},
"transactions": {},
"pendingTransactions": [],
"incomingTransactions": {}
}