import Wallet from '@logosnetwork/logos-webwallet-sdk'
const wallet = new Wallet({
password: null,
seed: null,
deterministicKeyIndex: 0,
currentAccountAddress: null,
accounts: {},
tokenAccounts: {},
walletID: null,
batchSends: true,
fullSync: true,
lazyErrors: false,
tokenSync: false,
validateSync: true,
ws: false,
mqtt: defaultMQTT,
rpc: defaultRPC
})
All wallet options are optional defaults are shown in the example above
Wallet Option | Description |
---|---|
password | Password is used to encrypt and decrypt the wallet data |
seed | Seed is the deterministic entropy that we will use to generate key pairs from |
deterministicKeyIndex | index of where you wish to start generating key paris from |
currentAccountAddress | the current selected account address |
accounts | AccountMap of all the logos accounts in the Wallet |
tokenAccounts | TokenAccountMap of all the token accounts in the Wallet |
walletID | identifier of this wallet instance |
batchSends | when batchsends is true the SDK automatically combines send transactions to reduce overall amount of transactions |
fullSync | when fullSync is true the SDK will load the full history of the TokenAccounts and Accounts in the system. This is recommend to be true when working with tokens. |
lazyErrors | when lazyErrors is true the SDK will not throw errors for transactions that have insufficient funds and will queue the transactions until the account has the funds to complete the action. |
tokenSync | when tokenSync is true the SDK will load and sync the TokenAccounts that have interacted with the LogosAccounts. |
validateSync | when validateSync is true the SDK will check all signatures of all the requests in the account chains. This is recommended to be true but when syncing an account with a long history this can be computationally heavy. |
ws | when ws is true connect to local logos node websocket. You should only use mqtt or ws not both! mqtt will take priority over WS the MQTT setup uses less resources at the current time. |
mqtt | address of your mqtt server 'wss://pla.bs:8443' is the default server. Check out the logos backend repo to run your own backend mqtt. |
rpc | Node information where you are sending requests to. See RPCOptions. Do not use the ip address of a delegate node, it won't work and also delegates shouldn't have RPC enabled... |
AccountMap of all the LogosAccounts in the wallet
wallet.accounts = {
'lgs_3e3j5tkog48pnny9dmfzj1r16pg8t1e76dz5tmac6iq689wyjfpiij4txtdo': new LogosAccount({
privateKey: 34F0A37AAD20F4A260F0A5B3CB3D7FB50673212263E58A380BC10474BB039CE4
})
}
The current balance of all the LogosAccounts in reason
const walletBalanceInReason = wallet.balance
The current account address
wallet.currentAccountAddress = 'lgs_3e3j5tkog48pnny9dmfzj1r16pg8t1e76dz5tmac6iq689wyjfpiij4txtdo'
The current delegates of the network
wallet.delegates = ['3.215.28.211'] // Should be 32 length but I cba
Full Sync - syncs the entire send and recieve chains This is recommend to be true when using an untrusted RPC node In the future this will be safe when we have BLS sig validation of Request Blocks
const isFullSyncing = wallet.fullSync
Full Sync - syncs the entire send and recieve chains This is recommend to be true when using an untrusted RPC node In the future this will be safe when we have BLS sig validation of Request Blocks
wallet.fullSync = true
Lazy Errors allows you to add request that are not valid for the current pending balances to the pending chain
const delayingErros = wallet.lazyErrors
Lazy Errors allows you to add request that are not valid for the current pending balances to the pending chain
wallet.lazyErrors = false
The password of the wallet in the future we will remove the ability to store the password and request it in realtime so it is in memory for less time
const password = wallet.password
The password of the wallet in the future we will remove the ability to store the password and request it in realtime so it is in memory for less time
wallet.password = 'password'
Return all the requests that are pending in every LogosAccount in this wallet
const pendingRequests = wallet.pendingRequests
The RPCOptions for connecting to the RPC or set this to false to disable communication
const rpcInfo = wallet.rpc
The RPCOptions for connecting to the RPC or set this to false to disable communication
wallet.rpc = {
proxy: 'https://pla.bs',
nodeURL: '3.215.28.211',
nodePort: '55000',
wsPort: '18000'
}
Returns a Logos RPC Client Instance
const rpcClient = wallet.rpcClient
Return the seed of the wallet in the future we will remove the ability to access the seed unless you pass a password
const seed = wallet.seed
Return the seed of the wallet in the future we will remove the ability to access the seed unless you pass a password
wallet.seed = '6A4C54C619A784891D5DBCA1FCC5FA08D6B910B49A51BEA13C3DC913BB45AF13'
Return boolean if all the accounts in the wallet are synced
const isWalletSynced = wallet.synced
TokenAccountMap of all the TokenAccounts in the wallet
const tokenAccounts = wallet.tokenAccounts
Sync Tokens - Syncs all associated token's of the accounts on the account sync instead of on use
const areTokensSyncing = wallet.tokenSync
Sync Tokens - Syncs all associated token's of the accounts on the account sync instead of on use
wallet.tokenSync = false
Validate Sync if this option is true the SDK will generate hashes of each requests based on the content data and verify signatures This should always be true when using a untrusted RPC node
const isValidatingSignatures = wallet.validateSync
Validate Sync if this option is true the SDK will generate hashes of each requests based on the content data and verify signatures This should always be true when using a untrusted RPC node
wallet.validateSync = false
The id of the wallet
wallet.walletID = '2c0a4be6b9ccda9158ed96f0dd596f72dad66015e8444c64e2ea0b9c7e553ec6'
When ws is true connect to local logos node websocket If mqtt is set then logos node websocket will not be used
const usingLogosWebsocket = wallet.ws
When ws is true connect to local logos node websocket If mqtt is set then logos node websocket will not be used
wallet.ws = true
Adds a account to the wallet
wallet.addAccount(new LogosAccount(
{
privateKey: 34F0A37AAD20F4A260F0A5B3CB3D7FB50673212263E58A380BC10474BB039CE4
}
))
Adds a tokenAccount to the wallet
const tokenAccount = await wallet.createTokenAccount('lgs_3q69z3kf6cq9n9smago3p1ptuyqy9pa3mdykyi9o8f7gnof47qdyxj9gejxd')
wallet.addTokenAccount(tokenAccount)
Create an account
You are allowed to create an account using your seed, precalculated account options, or a privateKey
the options to populate the account. If you send just private key it will generate the account from that privateKey. If you just send index it will genereate the account from that determinstic seed index.
sets the current account to newly created accounts this is default true
const account = await wallet.createAccount()
Create a TokenAccount
You are allowed to add a tokenAccount using the address
const tokenAccount = await wallet.createTokenAccount('lgs_3q69z3kf6cq9n9smago3p1ptuyqy9pa3mdykyi9o8f7gnof47qdyxj9gejxd')
Decrypts the wallet data
The request data or returns false if it is unable to decrypt the data
Encrypts and packs the wallet data in a hex string
wallet.encrypt()
Fetches the delegates from the server and sets our delegate list
returns the list of active delegates ips
const delegates = await wallet.fetchDelegates()
Generates an account based on the given private key
The minimal account options to create the account
Generates an account based on the determinstic index of the key
The minimal account options to create the account
Finds the request object of the specified hash of one of our accounts
The hash of the request we are looking for the object of
false if no request object of the specified hash was found
wallet.getRequest('E8CA715349FFD12DE7CB76045CAAA52448655F3B34624A1E31514763C81C4795')
Process Request finds the account if it is in our wallet and update its local ledger
JSON of the request block
address we are looking for
update logos accounts
update token accounts
Updates the balance of all the accounts
wallet.recalculateWalletBalancesFromChain()
Removes an account to the wallet
wallet.removeAccount('lgs_3e3j5tkog48pnny9dmfzj1r16pg8t1e76dz5tmac6iq689wyjfpiij4txtdo')
Resets all LogosAccounts
Subscribe to the mqtt topic
topic to subscribe to
Scans the accounts to make sure they are synced and if they are not synced it syncs them
const isWalletSynced = await wallet.sync()
Returns the base Wallet JSON
JSON request
const walletJSON = wallet.toJSON()
Unsubscribe to the mqtt topic
topic to unsubscribe to
Connect to the mqtt
wallet.wsConnect()
Disconnect from the mqtt
wallet.wsDisconnect()
Generated using TypeDoc
Wallet
The wallet is the primary way you will interact with the SDK.