Skip to content

Instantly share code, notes, and snippets.

@blackwatertepes
Created May 25, 2018 16:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save blackwatertepes/16b015a642dc5cb8ab006d88b7bc33ca to your computer and use it in GitHub Desktop.
Save blackwatertepes/16b015a642dc5cb8ab006d88b7bc33ca to your computer and use it in GitHub Desktop.

Introduction

Scripts in this repo...

  • eos.js (Includes the eosjs lib, and sets the basic configuration. Do not run this directly)
  • tail.js (Logs the EOS node transactions. Start this first, in its own window)
  • new_account.js (Creates a new account)

Getting Started

  • Replace the httpEndpoint in eos.js with your EOS node http address
  • Replace the private/public keys in the new_account.js file with your eosio account keys
  • Run tail.js to view transactions
  • In another tab, run new_account.js to create a new transaction
Eos = require('eosjs') // Eos = require('./src')
const config = {
keyProvider: [], // WIF string or array of keys..
logger: { // Default logging functions
log: console.log,
error: console.error,
debug: console.debug
},
httpEndpoint: 'http://000.000.000.000:8888',
mockTransactions: () = > 'pass', // or 'fail'
transactionHeaders: (expireInSeconds, callback) = > {
//callback(null/*error*/, headers)
},
expireInSeconds: 60,
broadcast: true,
debug: true,
sign: true
}
module.exports = {
local: function(args = {}) {
let configs = Object.assign(config, args);
console.log("with configs", configs);
return Eos.Localnet(configs);
}
}
const privateKey = '5KFP...'
const publicKey = 'EOS76365Yg88W72hXtz5FwioBA6422JMMGJ6Q2EgHigcLniper9Gu'
const creator = 'eosio';
const name = 'mynewacct';
const eos = require("./eos").local({
keyProvider: privateKey
});
const account = {
creator: creator,
name: name,
owner: publicKey,
active: publicKey
}
console.log("creating account", account);
eos.newaccount(account);
const eos = require("./eos").local();
let current_block = 0;
setInterval(async() = > {
let node_info = await eos.getInfo({}); //.then((node_info => {
//console.log(node_info);
let block_id = node_info.head_block_num;
if (block_id > current_block) {
current_block = block_id;
let block_info = await eos.getBlock(block_id); //.then(result => {console.log(result)});
console.log(block_info.timestamp, "Block #", block_info.block_num, "Txs Count:", block_info.transactions.length);
if (block_info.transactions.length > 0) {
console.log(block_info);
}
}
}, 100);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment