Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
The NodeJS example code from the recent Fuel tutorial blog post.
const { Wallet, utils, dbs } = require("fuel-core");
(async () => {
// DB and Key Setup
const db = new dbs.Level(); // persisting db
const privateKey = (await db.get('key')) || utils.randomBytes(32);
await db.put('key', privateKey);
const signer = new utils.SigningKey(privateKey);
console.log('My Fuel address is :', signer.address);
// Wallet and Faucet of Fake Dai
const wallet = new Wallet({ db, signer });
// We allow the faucet to throw once the amount per IP limit is reached
try { await wallet.faucet(); } catch (e) {}
// Listen for Incoming Transaction Data
await wallet.listen(async () => {
console.log('Balance updates in transit',
utils.formatEther(await wallet.balance(wallet.tokens.fakeDai)));
});
// Transfer of Fake Dai to Wallets
await wallet.transfer(utils.parseEther('1.5'), wallet.tokens.fakeDai, wallet.address);
// Fin.
console.log('You transfered 1.5 Fake Dai to yourself, congrats!');
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.