SDK for developers to create and interact with Bicoin nano wallets easily with Typescript or Javascript
- 🎉 Easy to use, no need to configure RPC calls
- 🧑💻 Allows you to configure multiple RPC and Work Servers separately.
- 👷 Automatic fallback when a request fails
- 🌐 Runtime agnostic: Compatible with Node.js, Browser, EDGE, Bun, Deno and others.
- ⚡️ Efficient and agnostic state management allows you to store the wallet state with your favorite tool and start the instance with the previous state.
- 🔒️ Safe and non-custodial: Your privateKey is never shared with RPC or any server, all signatures and key derivation is made on client side by nanocurrency.js library
npm install btconano-wallet-js
import BTCONanoWallet from 'btconano-wallet-js';
const config = {
privateKey: '000AAFF...', // The privateKey (secret) of your wallet (not the SEED, neither the MNEMONIC)
rpcUrls: ['http://[::1]:7076'], // A string or an array of RPC addresses
workerUrls: ['http://[::1]:7076'], // A string or an array of RPC Worker Server. Can be the same as rpcUrls
representative:
'btco_3kc8wwut3u8g1kwa6x4drkzu346bdbyqzsn14tmabrpeobn8igksfqkzajbb', // representative account
debug: true, // show console log message (optional)
};
const wallet = new BTCONanoWallet(config);
await wallet.sync();
// It is only needed at wallet initialization.
// You can use a Database, Filesystem, KV, Redux or whatever...
const state = await getFromMyStorage();
const wallet = new BTCONanoWallet(config, state);
// Subscribe to state changes to persist in your storage
wallet.subscribe(async state => {
await saveIntoMyStorage(state);
});
wallet.account
: Your wallet account / addresswallet.balance
: Your wallet balance in rawswallet.receivable
: Total amount to be receivedwallet.receivableBlocks
: Array of pending blocks to receive with blockHash and amountwallet.frontier
: Previous block hash (your last transaction)wallet.representative
: The representative you set when initing the instancewallet.currentRepresentative
: Your current representative. Make a transaction or call.setRepresentative()
to update.
Sync: Force wallet synchronization, updating frontier, balance, receivable and representative.
await wallet.sync();
console.log(wallet.frontier, wallet.balance, ...)
Get Receivables:
Returns an array containing the blocks that have not been received yet by this account. Each block contains
the hash
property which you need to receive it using Receive.
await wallet.getReceivable();
console.log(wallet.receivable, wallet.receivableBlocks);
Receive: Receive amount manually. This process will be automated in next releases.
for (const receivable of wallet.receivableBlocks) {
const { hash } = await wallet.receive(receivables.blockHash);
}
Send: Send amount in raws to another wallet.
const to = 'btco_1abcd...';
const amount = '1000000000000000000000000000'; // 0.001 Nano
const { hash } = await wallet.send(to, amount);
// print the updated balance
console.log('Balance:', wallet.balance);
Sweep: Send all balance to another wallet (Careful!)
const to = 'btco_3efgh...';
const { hash } = await wallet.sweep(to);
Set Representative: Set a new representative
const rep = 'btco_4ijk1mno...';
await wallet.setRepresentative(rep);
// print
console.log(wallet.representative, wallet.currentRepresentative);