I am trying to send a method on a contract using web3. I'm creating an account using the privateKeyToAccount method but when sending the method on the contract I get the following error:
Provided address [object Object] is invalid, the capitalization checksum test failed, or it's an indirect IBAN address which can't be converted.
Am I missing a step? I already created an instance of web3 and the contract interface works. I attached part of the code below. Thanks in advance for the help.
const web3 = new Web3(
new Web3.providers.WebsocketProvider(
'wss://rinkeby.infura.io/ws/v3/<api>'
)
);
const dummyPrivateKey = '0x38544e1555a3553829219281253d2400fa20ebbd922fdh3918a7s2b53b9e1358';
const accounts = web3.eth.accounts.privateKeyToAccount(dummyPrivateKey);
await contract.methods // add username
.addMessage(_username, _message)
.send({ from: accounts });
I am trying to send a method on a contract using web3. I'm creating an account using the privateKeyToAccount method but when sending the method on the contract I get the following error:
Provided address [object Object] is invalid, the capitalization checksum test failed, or it's an indirect IBAN address which can't be converted.
Am I missing a step? I already created an instance of web3 and the contract interface works. I attached part of the code below. Thanks in advance for the help.
const web3 = new Web3(
new Web3.providers.WebsocketProvider(
'wss://rinkeby.infura.io/ws/v3/<api>'
)
);
const dummyPrivateKey = '0x38544e1555a3553829219281253d2400fa20ebbd922fdh3918a7s2b53b9e1358';
const accounts = web3.eth.accounts.privateKeyToAccount(dummyPrivateKey);
await contract.methods // add username
.addMessage(_username, _message)
.send({ from: accounts });
Share
Improve this question
edited Oct 12, 2022 at 20:58
TylerH
21.1k77 gold badges79 silver badges112 bronze badges
asked Aug 17, 2021 at 20:06
Andrei FlorianAndrei Florian
1411 gold badge2 silver badges8 bronze badges
4 Answers
Reset to default 9Petr is right. I missed the part where you are giving the whole object instead of address.
But if you want to checksum an address. You can simply use Web3 utility function web3.utils.toChecksumAddress(address)
to convert. More details here
You're passing the account object to the from
field. But you need to pass just the address.
Replace the from: accounts
to from: accounts.address
.
Note: This is how the accounts
object looks like:
{
address: '0x29B67BB1cFE4799FDb46B49aD81cD771665E2dF7',
privateKey: '0x38544e1555a3553829219281253d2400fa20ebbd922fdh3918a7s2b53b9e1358',
signTransaction: [Function: signTransaction],
sign: [Function: sign],
encrypt: [Function: encrypt]
}
Ensure that the address that you are providing is valid. You can get the address from either online providers like Infura or local setup like Ganache.
If still an issue persists, then try to use the following code.
web3.utils.toChecksumAddress(address)
I also encountered this problem in the project, but in my case, I also used Web3 service and same test network at the same time. Stop another service and back to normal now.