I'm using methods.myMethod.send to call a method on a smart contract. I'm using an infura node.
import * as RpcClient from 'web3-eth';
const rpc = new RpcClient('https://mainnet.infura.io'); // I also tested on kovan - the result remains the same
rpc.defaultAccount = address;
rpc.accounts.wallet.add({
privateKey: privateKey,
address: address,
});
/** connect to contract, etc. (omitted) **/
await mycontract.methods.foo() // within async function
.send({
from: address,
gas: gasAmount,
gasPrice: gasPrice,
value: value,
});
Transaction is relayed to the network and can be mined.
I have two different projects, both use the exact same code.
mycontract.methods.foo().send always end up with this error:The method eth_sendTransaction does not exist/is not available
I'll try to setup a reproduction repo.
(node:29921) UnhandledPromiseRejectionWarning: Error: Returned error: The method eth_sendTransaction does not exist/is not available
at Object.ErrorResponse (/Users/foo/repo/project-1-with-jest/node_modules/web3-core-helpers/src/errors.js:30:16)
at /Users/foo/repo/project-1-with-jest/node_modules/web3-core-requestmanager/src/index.js:140:36
at XMLHttpRequest.request.onreadystatechange (/Users/foo/repo/project-1-with-jest/node_modules/web3-providers-http/src/index.js:91:13)
at XMLHttpRequestEventTarget.dispatchEvent (/Users/foo/repo/project-1-with-jest/node_modules/xhr2-cookies/dist/xml-http-request-event-target.js:34:22)
at XMLHttpRequest._setReadyState (/Users/foo/repo/project-1-with-jest/node_modules/xhr2-cookies/dist/xml-http-request.js:208:14)
at XMLHttpRequest._onHttpResponseEnd (/Users/foo/repo/project-1-with-jest/node_modules/xhr2-cookies/dist/xml-http-request.js:318:14)
at IncomingMessage.<anonymous> (/Users/foo/repo/project-1-with-jest/node_modules/xhr2-cookies/dist/xml-http-request.js:289:61)
at IncomingMessage.emit (events.js:187:15)
at IncomingMessage.EventEmitter.emit (domain.js:441:20)
at endReadableNT (_stream_readable.js:1094:12)
at process._tickCallback (internal/process/next_tick.js:63:19)
at process.emitWarning (internal/process/warning.js:134:13)
at process.<anonymous> (/Users/foo/repo/project-2-with-cli/node_modules/esm/esm.js:1:282108)
at process.<anonymous> (/Users/foo/repo/project-2-with-cli/node_modules/esm/esm.js:1:281984)
at process.<anonymous> (/Users/foo/repo/project-2-with-cli/node_modules/esm/esm.js:1:277586)
at Object.apply (/Users/foo/repo/project-2-with-cli/node_modules/esm/esm.js:1:194489)
at emitWarning (internal/process/promises.js:81:15)
at emitPromiseRejectionWarnings (internal/process/promises.js:120:9)
at process._tickCallback (internal/process/next_tick.js:69:34)
(node:29921) Error: Returned error: The method eth_sendTransaction does not exist/is not available
at Object.ErrorResponse (/Users/foo/repo/project-1-with-jest/node_modules/web3-core-helpers/src/errors.js:30:16)
at /Users/foo/repo/project-1-with-jest/node_modules/web3-core-requestmanager/src/index.js:140:36
at XMLHttpRequest.request.onreadystatechange (/Users/foo/repo/project-1-with-jest/node_modules/web3-providers-http/src/index.js:91:13)
at XMLHttpRequestEventTarget.dispatchEvent (/Users/foo/repo/project-1-with-jest/node_modules/xhr2-cookies/dist/xml-http-request-event-target.js:34:22)
at XMLHttpRequest._setReadyState (/Users/foo/repo/project-1-with-jest/node_modules/xhr2-cookies/dist/xml-http-request.js:208:14)
at XMLHttpRequest._onHttpResponseEnd (/Users/foo/repo/project-1-with-jest/node_modules/xhr2-cookies/dist/xml-http-request.js:318:14)
at IncomingMessage.<anonymous> (/Users/foo/repo/project-1-with-jest/node_modules/xhr2-cookies/dist/xml-http-request.js:289:61)
at IncomingMessage.emit (events.js:187:15)
at IncomingMessage.EventEmitter.emit (domain.js:441:20)
at endReadableNT (_stream_readable.js:1094:12)
at process._tickCallback (internal/process/next_tick.js:63:19)
(node:29921) [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.
at process.emitWarning (internal/process/warning.js:134:13)
at process.<anonymous> (/Users/foo/repo/project-2-with-cli/node_modules/esm/esm.js:1:282108)
at process.<anonymous> (/Users/foo/repo/project-2-with-cli/node_modules/esm/esm.js:1:281984)
at process.<anonymous> (/Users/foo/repo/project-2-with-cli/node_modules/esm/esm.js:1:277586)
at Object.apply (/Users/foo/repo/project-2-with-cli/node_modules/esm/esm.js:1:194489)
at emitDeprecationWarning (internal/process/promises.js:95:13)
at emitWarning (internal/process/promises.js:88:3)
at emitPromiseRejectionWarnings (internal/process/promises.js:120:9)
at process._tickCallback (internal/process/next_tick.js:69:34)
This issue is related but didn't provide any useful solution and was closed: https://github.com/ethereum/web3.js/issues/1637
This comment is wrong, since it works in my case in 1 of the projects: https://github.com/ethereum/web3.js/issues/1637#issuecomment-453443600
These posts are related but don't provide a solution, other than using the sendRawTransaction endpoint:
I've tested it with my local geth node and an unlocked account and it works without any error. The transaction gets signed locally and will be sent with eth_sendRawTransaction.
Code:
const web3 = new Web3('ws://localhost:8546');
const alice = '0xb414031Aa4838A69e27Cb2AE31E709Bcd674F0Cb';
web3.eth.accounts.wallet.add('0x3a0ce9a362c73439adb38c595e739539be1e34d19c5e9f04962c101c86bd7616');
const testContract = new web3.eth.Contract(abi, '', {data: web3TokenBytecode});
testContract.transactionConfirmationBlocks = 1;
testContract.deploy().estimateGas().then((gas) => {
testContract.deploy().send({from: alice, gas: gas}).then((clonedContract) => {
clonedContract.methods.transfer('0x24BBE93E1D5b43233D921C9c73E15e8576bD7Be1', 1000)
.send({from: alice, gas: gas})
.on('transactionHash', (hash) => {
console.log('TRANSACTION_HASH');
console.log(hash);
})
.on('confirmation', (confirmations, receipt) => {
console.log('CONFIRMATION');
console.log(confirmations);
console.log(receipt);
})
.on('receipt', (receipt) => {
console.log('RECEIPT');
console.log(receipt);
})
.on('error', (error, receipt, confirmations) => {
console.log('ERROR');
console.log(error);
console.log(receipt);
console.log(confirmations);
});
});
});
Locally it works for me as well, but not if using Infura.
Infura is probably easiest the most popular choice for connecting to the ethereum network without having a private node, so I think it's in the interest of the whole community to assure integration between web3.js and Infura. Therefore I don't understand why you close this issue, without providing a solution that works on Infura.
This doesn't make a difference. :)
Infura has not activated the method eth_sendTransaction because this method needs unlocked accounts on the ethereum node. With the example I've provided above will it also work with infura :)
Edit:
Please open an issue in the infura repository to get any further details about it.
thanks for your reply @nivida
Infura has not activated the method eth_sendTransaction
As mentioned in my original post, I did write specs with jest and executed the smart contract function which resulted in the transaction getting relayed to the network.
Anyway, good point asking for advice at infura. Will do, thanks.
@takahser did you find any workaround for that?
Has there been any fix to this?
I can't even get it working with my local ganache
using require('ethereumjs-tx'); from here could be a workaround
real solution
https://ethereum.stackexchange.com/questions/70853/the-method-eth-sendtransaction-does-not-exist-is-not-available-on-infura
nothing to do with infura!
Most helpful comment
Locally it works for me as well, but not if using Infura.
Infura is probably easiest the most popular choice for connecting to the ethereum network without having a private node, so I think it's in the interest of the whole community to assure integration between web3.js and Infura. Therefore I don't understand why you close this issue, without providing a solution that works on Infura.