Returns invalid chain id if two caver-js instance are used
Closed this issue · 0 comments
kjhman21 commented
Describe the bug
As seen below, if we create two caver-js instances and use the first one to make a signature, it returns invalid chain ID error.
It seems that chain id is a shared variable for all caver-js instances.
const fs = require('fs')
const Caver = require('caver-js')
async function testFunction() {
const caver = new Caver('https://api.baobab.klaytn.net:8651/')
const caver2 = new Caver('https://public-node-api.klaytnapi.com/v1/cypress')
const keyring = caver.wallet.keyring.generate()
// Add to caver.wallet
caver.wallet.add(keyring)
// Create value transfer transaction
const vt = caver.transaction.valueTransfer.create({
from: keyring.address,
to: '0x8084fed6b1847448c24692470fc3b2ed87f9eb47',
value: caver.utils.toPeb(1, 'KLAY'),
gas: 25000,
})
// Sign to the transaction
const signed = await caver.wallet.sign(keyring.address, vt)
// Send transaction to the Klaytn blockchain platform (Klaytn)
const receipt = await caver.rpc.klay.sendRawTransaction(signed)
console.log(receipt)
}
testFunction()
You can find this also in https://github.com/kjhman21/caver-js-test
How to reproduce
$ git clone git@github.com:kjhman21/caver-js-test.git
$ npm install
$ node index.js
(node:13544) UnhandledPromiseRejectionWarning: Error: Returned error: invalid chain id
at Object.ErrorResponse (/Users/colin.klaytn/playground/caver-js-test/node_modules/caver-js/packages/caver-core-helpers/src/errors.js:87:16)
at /Users/colin.klaytn/playground/caver-js-test/node_modules/caver-js/packages/caver-core-requestmanager/src/index.js:155:44
at XMLHttpRequest.request.onreadystatechange (/Users/colin.klaytn/playground/caver-js-test/node_modules/caver-js/packages/caver-core-requestmanager/caver-providers-http/src/index.js:122:13)
at XMLHttpRequestEventTarget.dispatchEvent (/Users/colin.klaytn/playground/caver-js-test/node_modules/xhr2-cookies/dist/xml-http-request-event-target.js:34:22)
at XMLHttpRequest._setReadyState (/Users/colin.klaytn/playground/caver-js-test/node_modules/xhr2-cookies/dist/xml-http-request.js:208:14)
at XMLHttpRequest._onHttpResponseEnd (/Users/colin.klaytn/playground/caver-js-test/node_modules/xhr2-cookies/dist/xml-http-request.js:318:14)
at IncomingMessage.<anonymous> (/Users/colin.klaytn/playground/caver-js-test/node_modules/xhr2-cookies/dist/xml-http-request.js:289:61)
at IncomingMessage.emit (events.js:326:22)
at endReadableNT (_stream_readable.js:1241:12)
at processTicksAndRejections (internal/process/task_queues.js:84:21)
(node:13544) 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(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 1)
(node:13544) [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.
Expected behavior
- This should be executed without error.
Attachments
N/A
Environment (please complete the following information)
- caver-js@1.6.8
- MacOS Monterey (12.1)
Additional context