Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save SilentCicero/fb854c440dbc615df6ff419f2c33bd06 to your computer and use it in GitHub Desktop.
Save SilentCicero/fb854c440dbc615df6ff419f2c33bd06 to your computer and use it in GitHub Desktop.
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