-
Notifications
You must be signed in to change notification settings - Fork 1
Wallet and Account Lifecycle
Justin Craig-Kuhn edited this page Oct 1, 2018
·
9 revisions
To create a new wallet, we connect to our local node and ask it to create one.
node = NanoRpc.node
wallet = node.create_wallet
wallet.id
# => 'A0BD2ED02A3F4718FF241EB763B7EEE053B362311B15567EA9D8D547A6D695BF'Note: the wallet id is NOT the same as the wallet seed. The seed is not provided over RPC and must be fetched from the node itself via command line. You should always fetch the seed for every created wallet in order to ensure disaster recovery.
Now we create a few accounts.
accounts = wallet.create_accounts(count: 3)
# => #<NanoRpc::Accounts:0x0000000001997630 @addresses=["xrb_1a6juq686ztbiduiuwcco7xg1kewhss6778co4n7pw3h7nne9dxed3rg57cy", "xrb_3j3cnbas9y3f9db7tb8jewmhrwfho8xuiwrhrkb9cofw5ydy7o8atcihmrj6", "xrb_18a3tdygaaeyt9kdtau3884z6o54kmfr3tcnmsxrbubpqkp5yxxw8fapdirb"], @node=#<NanoRpc::Node:0x000000000100ef28 @url="localhost:7076">>Look at the public address on the first account we just created.
account = accounts.first
account.address
# => "xrb_1a6juq686ztbiduiuwcco7xg1kewhss6778co4n7pw3h7nne9dxed3rg57cy"
address = account.address
# => 'xrb_3e3j5tkog48pnny9dmfzj1r16pg8t1e76dz5tmac6iq689wyjfpi00000001'
wallet.contains?(address)
# => trueWhat's the balance and pending_balance on the last one?
accounts.last.balance
# => 0
accounts.last.pending_balance
# => 0Let's create a second wallet.
wallet2 = node.create_wallet
wallet2.id
# => "D396C705495B09C4BAAED0187FCFE09F7BE9AF44C72A7FC2D00E4E28C04B8EB2"
wallet2.representative
# => "xrb_1stofnrxuz3cai7ze75o174bpm7scwj9jn3nxsn8ntzg784jf1gzn1jjdkou"
wallet2.work
# => ""Now we'll remove the first account.
wallet.remove_account(wallet.accounts.first)
# => true
wallet.accounts.size
# => 1
wallet.contains?(address)
# => falseNow let's destroy the second wallet including all accounts contained within.
wallet2.destroy
# => {}
wallet2.accounts
# => NanoRpc::InvalidRequest (Invalid request: Wallet not found)