Error: unknown account sending transaction to Geth

Hi,

i am doing simple queries using OZ. It all works fine in Ganache-cli blockchain. But with Geth, it gives “unknown account” error.
Google search shows some old bug in web3 which later got resolved. Has anyone encountered that in OZ?

Err140:  Error: Returned error: unknown account
    at Object.ErrorResponse (/Users/pksingh/solydBE/node_modules/web3/node_modules/web3-core-helpers/src/errors.js:29:16)
    at /Users/pksingh/solydBE/node_modules/web3/node_modules/web3-core-requestmanager/src/index.js:170:36
    at XMLHttpRequest.request.onreadystatechange (/Users/pksingh/solydBE/node_modules/web3/node_modules/web3-providers-http/src/index.js:111:13)
    at XMLHttpRequestEventTarget.dispatchEvent (/Users/pksingh/solydBE/node_modules/xhr2-cookies/dist/xml-http-request-event-target.js:34:22)
    at XMLHttpRequest._setReadyState (/Users/pksingh/solydBE/node_modules/xhr2-cookies/dist/xml-http-request.js:208:14)
    at XMLHttpRequest._onHttpResponseEnd (/Users/pksingh/solydBE/node_modules/xhr2-cookies/dist/xml-http-request.js:318:14)
    at IncomingMessage.<anonymous> (/Users/pksingh/solydBE/node_modules/xhr2-cookies/dist/xml-http-request.js:289:61)
    at IncomingMessage.emit (events.js:203:15)
    at IncomingMessage.EventEmitter.emit (domain.js:448:20)
    at endReadableNT (_stream_readable.js:1145:12)
    at process._tickCallback (internal/process/next_tick.js:63:19)
1 Like

Hi @prabhat,

What was the simple query that you were running?

I connect to the network using Infura so haven’t run into this issue.

Hello @abcoathup,

I created a contract in OZ using createProxy. This works fine.

const MyContractV0 = Contracts.createFromText( Buffer.from(chain.contr, "base64").toString("ascii") );
const instance = await project.createProxy(MyContractV0);

Afterward, I call the initialize method from a separate function of web3.

    const instance2 = loader.fromArtifactText(Buffer.from(contractTextB4, "base64").toString("ascii"), chain.address);
              const initialValue = await instance2.methods['initialize']
                .apply(null, args)
                .send({ from: address, gas: 6e6, gasPrice: 1e6 });

I suspect that web3 sends an unsigned transaction whereas OZ sends signed one. My address is not added in Geth node. That’s why web3 transaction fails!

Is there a way to send such transactions from OZ?

1 Like

Solved it. We just had to sign the tx before sending.

encoded = contractInstance.methods.myMethod(params).encodeABI()

var tx = {
    to : myContractAddress,
    data : encoded
}

web3.eth.accounts.signTransaction(tx, privateKey).then(signed => {
    web3.eth.sendSignedTransaction(signed.rawTransaction).on('receipt', console.log)
});
1 Like