Created
March 30, 2019 11:11
-
-
Save nnamon/f89ff0a7ebe4f2a0664b8aa145095426 to your computer and use it in GitHub Desktop.
Zilliqa Test Send Transaction
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const { Transaction } = require('@zilliqa-js/account'); | |
const { BN, Long, bytes, units } = require('@zilliqa-js/util'); | |
const { Zilliqa } = require('@zilliqa-js/zilliqa'); | |
const CP = require ('@zilliqa-js/crypto'); | |
const zilliqa = new Zilliqa('http://localhost:4201'); | |
// These are set by the core protocol, and may vary per-chain. | |
// These numbers are JUST AN EXAMPLE. They will NOT WORK on the developer testnet | |
// or mainnet. | |
// For more information: https://apidocs.zilliqa.com/?shell#getnetworkid | |
const CHAIN_ID = 2; | |
const MSG_VERSION = 1; | |
const VERSION = bytes.pack(CHAIN_ID, MSG_VERSION); | |
// Populate the wallet with an account | |
const privkey = '2BEE3DD04CEFD25EE17190075C1693F011CA5AAF0C50D3EA2D0934482872AB72'; | |
zilliqa.wallet.addByPrivateKey( | |
privkey | |
); | |
const address = CP.getAddressFromPrivateKey(privkey); | |
console.log("Your account address is:"); | |
console.log(`0x${address}`); | |
async function testBlockchain() { | |
// Get Balance | |
const balance = await zilliqa.blockchain.getBalance(address); | |
// Get Minimum Gas Price from blockchain | |
const minGasPrice = await zilliqa.blockchain.getMinimumGasPrice(); | |
console.log(`Your account balance is:`); | |
console.log(balance.result) | |
console.log(`Current Minimum Gas Price: ${minGasPrice.result}`); | |
const myGasPrice = units.toQa('1000', units.Units.Li); // Gas Price that will be used by all transactions | |
console.log(`My Gas Price ${myGasPrice.toString()}`) | |
console.log('Sufficient Gas Price?'); | |
console.log(myGasPrice.gte(new BN(minGasPrice.result))); // Checks if your gas price is less than the minimum gas price | |
// Send a transaction to the network | |
const tx = await zilliqa.blockchain.createTransaction( | |
zilliqa.transactions.new({ | |
version: VERSION, | |
toAddr: "573EC96638C8BB1C386394602E1460634F02ADDA", | |
amount: new BN(units.toQa("100000", units.Units.Zil)), // Sending an amount in Zil (1) and converting the amount to Qa | |
gasPrice: myGasPrice, // Minimum gasPrice veries. Check the `GetMinimumGasPrice` on the blockchain | |
gasLimit: Long.fromNumber(1) | |
}) | |
); | |
console.log(`The transaction status is:`); | |
console.log(tx.receipt); | |
} | |
testBlockchain(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment