I am trying to send a transaction that updates the state of a smart contract. I have locally deployed a ethereum network using Geth and three VM.
Here is my JS code:
import { Web3 } from 'web3';
import { promises as fs } from 'fs';
const network = "ws://192.168.X.X:8546";
const web3 = new Web3(network);
const wallet = web3.eth.accounts.wallet;
const account = web3.eth.accountProvider.privateKeyToAccount('PRIVATE_KEY');
web3.eth.defaultAccount = account.address;
wallet.add(account);
console.log(wallet);
const abi = JSON.parse(await fs.readFile("contracts/Contract.abi", "utf-8"));
const contract_address = await fs.readFile("contracts/Contract.address", "utf-8");
const contract = new web3.eth.Contract(abi, contract_address);
contract.defaultAccount = account.address;
let registered = await contract.methods.isRegistered(account.address).call();
console.log(registered);
let response = await contract.methods.registerEV(account.address).send();
console.log(response);
I can send money from the account I am trying to send a smart contract transaction from, and also run the first call() method. However, when it tries to run the send() function, I get the following error message:
innerError: { code: -32000, message: 'unknown account' },
code: 101,
data: undefined,
request: {
jsonrpc: '2.0',
id: '3d40b26e-d5d8-4c27-8cb3-5293308f7c1c',
method: 'eth_sendTransaction',
params: [
{
to: '0xbB94D2d82e1464a9Fbb8f150b981a82fB6C8bb8e',
from: '0x5DAff3F5C181fE4692CAD290d729D8478ee34E1D',
input: '0x937d117b0000000000000000000000005daff3f5c181fe4692cad290d729d8478ee34e1d',
gasPrice: '0x3b9aca00',
maxPriorityFeePerGas: undefined,
maxFeePerGas: undefined
}
]
}
What can the problem be?
I am running this on Node, using web3js. The account used was created using: web3.eth.accounts.create()
Thanks for any help!