I'm generating an account like this:
const account = this.web3.eth.accounts.create(entropy);
I'm then trying to send a transaction:
const balance = await this.web3.eth.getBalance(address);
const transaction = {
value: 10000,
to: this.bank.address,
gasLimit: 50000,
from: address,
};
I'm then trying to sign the transaction using the private key from the account I generated earlier:
const signed = await this.web3.eth.accounts.signTransaction(transaction, privateKey);
I print the signed object which looks like:
{ messageHash: '0x6c5dcd37e6a1d0c0cf84855405c85bf90844d2d58752cc3f186b7f56a5c2f8f8',
v: undefined,
r: undefined,
s: undefined,
rawTransaction: '0xf968.880850430e2340082c350944e8e1728ee0c12e15330ffefca76f65ce4606c838227108081.8fc1a0108005142fcabe7f5130efb04669d9cc3d38c75da1352bda08142c206e57a841a0262292b7744d9a1c93fd03d6867ba6651286384229914f95d1b619f2506a6b4f' }
When I try to broadcast the transaction:
const result = await this.web3.eth.sendSignedTransaction(signed.rawTransaction);
I get this error:
Error: Returned error: invalid argument 0: json: cannot unmarshal hex string of odd length into Go value of type hexutil.Bytes
Instead of creating an isolated account object, if I create it in such a way it gets added to the list of internal accounts I can sign and send transactions perfectly. It's just when I try and create an isolated account object and then send transactions do I get errors.
The rawTransaction hash has periods inside it, is this normal?
Check if private key has '0x'. I've got errors because web3.eth.sendSignedTransaction() doesn't like when the account has the prefix '0x', I don't know why...
It does have the prefix 0x but removing it does not fix the problem. Is anyone even able to send transactions using 1.0? This seems like a major bug. I've tried all the different methods now:
const account = this.web3.eth.accounts.privateKeyToAccount(privateKey);
const signed = await account.signTransaction(transaction);
const result = await this.web3.eth.sendSignedTransaction(signed.rawTransaction);
const signed = await this.web3.eth.accounts.signTransaction(transaction, privateKey);
const result = await this.web3.eth.sendSignedTransaction(signed.rawTransaction);
const account = this.web3.eth.accounts.create(entropy);
this.web3.eth.accounts.wallet.add(account);
// ...
const signed = await this.web3.eth.signTransaction(transaction, address);
const result = await this.web3.eth.sendSignedTransaction(signed.raw);
Neither of these ways work.
hi @Rob--, i have the same Problem.
Any ideas @frozeman ?
kind regards,
f.
Try adding chainId: 1 to your transaction. This results in a rawTransaction that can be validated with web3.utils.isHex.
const payload = {
data: abi,
gas: 4612388,
from: '0x313AaDcA1750CaadC7BCB26FF08175c95DCf8E38',
to: contract._address,
chainId: 1
}
const signedTx = await account.signTransaction(payload, account.privateKey)
web3.utils.isHex(signedTx.rawTransaction) // is true
const receipt = await web3.eth.sendSignedTransaction(signedTx.rawTransaction)
console.log(receipt)
I was using a private Ethereum blockchain. The issue was solved by matching the chainId inside genesis.json to the chainId property of the transaction object.
Most helpful comment
It does have the prefix
0xbut removing it does not fix the problem. Is anyone even able to send transactions using 1.0? This seems like a major bug. I've tried all the different methods now:Neither of these ways work.