0

I am trying to send a transaction to a Besu node that I have running locally. However, from the following code, when I run npx ts-node myFile.ts, I get Error: Invalid JSON RPC response:

const Web3 = require('web3');
let web3 = new Web3(new Web3.providers.HttpProvider('https://localhost:88888'));

const e2f = require("./build/contracts/ERC20Fixed.json");
const e2fBytecode = e2f.bytecode;
const e2fAbi = e2f.abi

const myAcct = web3.eth.accounts.create(web3.utils.randomHex(32));
const myAddr = myAcct.address;
const besuMinerCoinbase = <besuMinerCoinbaseAddress>;

web3.eth.sendTransaction({
    from: besuMinerCoinbase,
    to: myAddr,
    data: e2fBytecode,
}).then('transactionHash', function(transactionHash){
    console.log('Hash: ', transactionHash);
}).then('error', function(e){
    console.log(e);
});

Here is the full error message:

Hash:  Error: Invalid JSON RPC response: ""
    at Object.InvalidResponse (/Users/asdf/node_modules/web3-core-helpers/src/errors.js:45:16)
    at XMLHttpRequest.request.onreadystatechange (/Users/ahan/node_modules/web3-providers-http/src/index.js:107:32)
    at XMLHttpRequestEventTarget.dispatchEvent (/Users/ahan/node_modules/xhr2-cookies/xml-http-request-event-target.ts:44:13)
    at XMLHttpRequest._setReadyState (/Users/ahan/node_modules/xhr2-cookies/xml-http-request.ts:219:8)
    at XMLHttpRequest._onHttpRequestError (/Users/ahan/node_modules/xhr2-cookies/xml-http-request.ts:379:8)
    at ClientRequest.<anonymous> (/Users/ahan/node_modules/xhr2-cookies/xml-http-request.ts:266:37)
    at ClientRequest.emit (events.js:315:20)
    at ClientRequest.EventEmitter.emit (domain.js:482:12)
    at TLSSocket.socketErrorListener (_http_client.js:426:9)
    at TLSSocket.emit (events.js:315:20)
    at TLSSocket.EventEmitter.emit (domain.js:482:12)
    at emitErrorNT (internal/streams/destroy.js:92:8)
    at emitErrorAndCloseNT (internal/streams/destroy.js:60:3)
    at processTicksAndRejections (internal/process/task_queues.js:84:21)

I know that I am pinging is correct b/c when I CURL other endpoints, I get correct responses. Looking at the web3.js docs, I'm not sure what I am missing. How do I successfully send a transaction?

  • What client are you using? Is the sender account unlocked? – Ismael Aug 15 '20 at 4:42
  • @Ismael I'm using Besu, not sure if that's what you mean by client. – TheRealFakeNews Aug 15 '20 at 5:19
0

On issue #1158 on their github they say that:

Besu deliberately doesn't support key management inside the client.

In particular they also say that the methods

  • web3.eth.personal.newAccount('Password')
  • web3.eth.personal.unlockAccount(address, password, duration)
  • web3.eth.sendTransaction(from, to, value, gas)

won't be implemented because they require key management.


As alternative for javascript you can use hdwallet-provider.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.