Giter VIP home page Giter VIP logo

eosjs-node-cli's Introduction

eosjs-node-cli js-standard-style npm version

eosjs-node-cli made by Marcel Morales
using eosjs

Versions

MarcelBlockchain/eosjs-node-cli Npm
tag: 0.1.1 npm install eosjs-node-cli

Usage

  • Using standard private key on test net by default. Change config in ./eos.js
  • Make sure to have docker running as explained here
  • Uncomment lines to enable functions in ./app.js
  • Functions print and return all of their values, see ./eos.js

Blockchain

eos.getBlockHeight()
eos.getCurrentBlockInfo()

Keys

//  src: https://github.com/bitcoinjs/bip39/blob/master/index.js
//  Generates a random mnemonic (uses crypto.randomBytes under the hood), defaults to //  128-bits of entropy
//  strength = 256 for 24 words, 128 for 12
eos.generateMnemonic(128)
//  derives the master, owner & active private and public keys from mnemonic
eos.deriveFromMnemonic(eos.generateMnemonic(128))
eos.generateRandomPrivKey()
console.log(eos.generatePrivKeyFromSeed('SEED123'))
eos.fromPrivToPub(privKeyTest)
eos.isPubKeyValid(pubKeyTest)
eos.isPrivKeyValid(privKeyTest)

Accounts

EOS public and private keys can be generated off the chain, but EOS users need to create an account before they can operate on the chain. So activated users are needed to send on-chain transactions to new users in order to help them create accounts. By default users need to find tripartite help.

//  main net only:  
eos.getAccountNamesFromPubKey(pubKeyTest2)
//  main net only: (i.e. 'binancecleos'):
eos.getAccSystemStats(accBinance)
//  account name must be less than 13 characters
//  can only contain the following symbols: .12345abcdefghijklmnopqrstuvwxyz:
//  default: bytes = 8192, stake_net_quantity = '10.0000 SYS', stake_cpu_quantity = '10.0000 SYS', transfer = 0:
//  ownerPubKey and activePubKey can be the same, but is less secure
//  optional: bytes, stake_net_quantity, stake_cpu_quantity, transfer
eos.createAccountPackage('ownerPubKey', 'activePubKey', 'accountName', bytes, stake_net_quantity, stake_cpu_quantity, transfer)
//  args: 'accountName', ownerPubKey, activePubKey
eos.createSingleAccount('accountName', pubKeyTest, pubKeyTest)

Transactions

  • Transactions can be considered confirmed with 99.9% certainty after an average of 0.25 seconds from time of broadcast.
  • The EOS aBFT algorithm provides 100% confirmation of irreversibility within 1 second.
//  sender, receiver, quantity in format: '50.0000 SYS' , memo, | + optional: sign = true, broadcast = true
eos.transfer(acc1, acc2, '4.0000 SYS', 'myMemo1', true, true)
//  first creates an unsigned transaction, signs it and then broadcasts it. All separately. See logs()
eos.transferSignPushTransaction(acc1, acc2, '5.0000 SYS', 'myMemo2', privKeyTest)
//  just signs the transaction and returns it:
//  returns signature. Args: (from, to, quantity, memo = '')
eos.getSignature(acc1, acc2, quantityTest, memo = 'myMemo7')
//  signs transaction and returns it. Args: (transaction, from, to, quantity, memo = '')
eos.signTr(tr, from, to, quantity, memo = 'otherMemo')
//  insert return value from eos.transfer(..., signed = true, broadcast = false);
eos.pushTransaction(returnValueFrom.eos.transfer)
//  accountName, (+ int allAboveBlockHeightX --> optional)
eos.getOutgoingTransactions(accBinance)
//  get transaction info. Optionally with a block number hint (trBlockHeight)
//  note: example tr only visible when switching to main net
eos.getTransaction(exampleTrxMainNet, trBlockHeight) // sender e.g.: 'binancecleos' on main net
//  was tr executed? Optionally pass a block number hint (trBlockHeight). Returns bool
eos.isTransactionExecuted(exampleTrxMainNet, trBlockHeight)

Currency

// If you look at the result value, you can see an array in the form of a string.
// This is because there could be tokens with many different symbols in the account
eos.getCurrencyBalance(acc1) //  using EOS account name
// works for tokens as well, see https://github.com/eoscafe/eos-airdrops
// 'SYMBOL', 'eos.contractName'. E.g. 'EOS', 'eosio.token' (main net) / 'SYS', 'eosio.token' (local test net)
eos.getCurrencyStats('IQ', 'everipediaiq') // IQ on main net
//  amount in format '1000.0000 XYZ', receiver, memo:
eos.createToken('1000.0000 XXZX', acc1, 'new token memo')

Other

//  converts '1.3000 EOS' --> 1.3, see floatRegex in eosjs.js
console.log('tofloat: ', eos.toFloat('1.03002000'))

eosjs-node-cli's People

Stargazers

 avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.