UNPKG

revos-sdk-js-mainnet

Version:
137 lines (105 loc) 4.21 kB
"use strict"; const nkn = require("../lib"); // const walletJson = require("../wallet.json"); // const password = "node"; (async function () { // random new wallet // let wallet = new nkn.Wallet({ password }); // wallet from seed // wallet = new nkn.Wallet({ seed: wallet.getSeed(), password }); // save wallet to json // let walletJson = JSON.stringify(wallet); // load wallet from json and password // let wallet = nkn.Wallet.fromJSON(walletJson, { password }); // or load wallet asynchronously to avoid blocking eventloop // let wallet = await nkn.Wallet.fromJSON(walletJson, { password, async: true }); // verify password of a wallet // console.log("verify password", wallet.verifyPassword(password)); // verify password of a wallet asynchronously to avoid blocking eventloop // console.log( // "verify password", // await wallet.verifyPassword(password, { async: true }) // ); // verify whether an address is a valid NKN wallet address (static method) // console.log("verify address:", nkn.Wallet.verifyAddress(wallet.address)); // get balance of this wallet // console.log("balance:", await wallet.getBalance()); // get balance of an address // console.log("balance:", await wallet.getBalance(wallet.address)); // get RDC balance of an address (static method) // console.log("RDC balance:", await nkn.Wallet.getRDCBalance(wallet.address)); // get nonce for next transaction of this wallet // console.log("nonce:", await wallet.getNonce()); // get nonce of an address, does not include nonce in rpc node's transaction pool // console.log( // "nonce:", // await wallet.getNonce(wallet.address, { txPool: false }) // ); // get nonce of an address (static method) // console.log( // "nonce:", // await nkn.Wallet.getNonce(wallet.address, { txPool: false }) // ); // call below will fail because a new account has no balance try { // transfer token to some address // console.log( // "transfer txn hash:", // await wallet.transferTo(wallet.address, 1, { // fee: 0.1, // attrs: "hello world", // }) // ); // amount and fee can also be string to prevent accuracy loss // console.log( // "transfer txn hash:", // await wallet.transferTo(wallet.address, "1", { fee: "0.1" }) // ); // subscribe to a topic for ths pubkey of the wallet for next 100 blocks // console.log( // "subscribe txn hash:", // await wallet.subscribe("topic", 100, "identifier", "meta", { fee: "0.1" }) // ); // unsubscribe from a topic // console.log( // "unsubscribe txn hash:", // await wallet.unsubscribe("topic", "identifier", { fee: "0.1" }) // ); // register name // console.log("register name txn hash:", await wallet.registerName("name")); // transfer name // console.log( // "transfer name txn hash:", // await wallet.transferName("name", wallet.getPublicKey()) // ); // delete name // console.log("delete name txn hash:", await wallet.deleteName("name")); //swap RVS TO RDC // console.log(await wallet.swap("RVSR1zm27PrJdzzsbRSMUj7vCbr9WqPqxfgb", 1, { // fee: 0.1, // attrs: "hello world", // })); //swapRDC // console.log(await wallet.swapRDC("RVSR1zm27PrJdzzsbRSMUj7vCbr9WqPqxfgb", 1, { // fee: 0.1, // attrs: "hello world", // })); //transfer RDC // console.log( // await wallet.transferRDCTo("RVSHdoZEUjqGVcTiB52Mi23YzEzsymQEXbEY", 1, { // fee: 0.1, // attrs: "hello world", // }) // ); //get transaction detail // let txData = await nkn.Wallet.getTransaction( // "8aaa03a388ae72bbcf54d71ed2194708a84937054791adc423a29393f7cb1196" // ); // console.log(txData); //get block detail let blockData = await nkn.Wallet.getBlockByHash("751c2c9fd796f6d8d082b0d37df74ab6861fa35e974654c49e58863bb36e2b0b") console.log(blockData); } catch (e) { console.error(e); } })();