I have a local EOS network and I am trying to make my application work through a web page. I am using eosjs version 16.0.9. I downloaded it and ran npm install. I am able to run the following code ok both using node and from a web page:
const Eos = require('eosjs')
const fs = require("fs")
const config = {
chainId: 'cf057bbfb72640471fd910bcb67639c22df9f92470936cddc1ade0e2f2e7dc4f',
keyProvider: ['myprivateky'],
httpEndpoint: 'http://127.0.0.1:7777',
expireInSeconds: 60,
broadcast: true,
verbose: false, // API activity
sign: true
}
const eos = Eos(config)
const eosinfo = eos.getInfo((error, info) => {
console.log(error, info);})
// Promise
eos.getBlock(1).then(result => console.log(result)).catch(error => console.error(error)
The above code works fine. I am able to see the output both on my terminal and javascript console. When I try to call an action from a smart contract (using the syntax from Readme.md that came with EOSJS) I am running into some errors. This is the code I added:
const wasm = fs.readFileSync('/Users/Jyothi/Documents/contracts/ktc/ktc.wasm')
const abi = fs.readFileSync('/Users/Jyothi/Documents/contracts/ktc/ktc.abi')
eos.setcode('ktc', 0, 0, wasm)
I get the following error when I run it with node:
(node:40092) UnhandledPromiseRejectionWarning: AssertionError [ERR_ASSERTION]: keyProvider function is needed for private key lookup at /Users/Jyothi/Sites/node_modules/eosjs/lib/index.js:443:17 at at process._tickCallback (internal/process/next_tick.js:188:7) (node:40092) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1) (node:40092) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
Any idea what I am missing here? I clearly need to send the keys but where and how? Also, are there any tutorials/examples on how to install EOSJS and integrate it with front end? I looked around but wasn't very successful. I am very new to node.js and so trying to figure this out