Provided Address is invalid, the capitalization checksum test failed
Asked Answered
O

4

7

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 });
Overriding answered 17/8, 2021 at 20:6 Comment(0)
R
9

Petr 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

Roldan answered 17/8, 2021 at 21:1 Comment(4)
Thanks for the answers. I tried both but I'm now getting the error The method eth_sendTransaction does not exist/is not available. I'm not really that sure how to use web3 in the current configuration. I used to use Truffle wallet provider and I'd just pass my mnemonic and then pass the provider object into web3 (new Web3(provider)). But I need to refactor the code to not use it. I never passed my account mnemonic or private key to web3. Are these credentials not needed for web3 to be able to interact with the contract?Overriding
First. Did you initialize the contract object with ABI and Contract Address?. Second with Web3. you need to make a transaction object first. Transaction object contains information about from, to, data and gas field etc. Then you either send a transaction with the unlocked Account or sign a transaction first with your unlocked account and then send the signed transaction to the network. Read how to make transactions and send transactions here: web3js.readthedocs.io/en/v1.2.11/web3-eth.html#sendtransactionRoldan
The contract side of the application works fine, I can interact with it and call functions but can't transact them. When I was using Truffle wallet provider, I would pass my mnemonic to the wallet provider and then pass that when creating the web3 instance. I would then be able to call web3.eth.getAccounts to get the accounts. Is there a way I can pass either my mnemonic or private key to web3 for me to be able to retrieve that account using the getAccounts() method? I think that would solve the problemOverriding
You can take a hint on how to sign and send a transaction: ethereum.stackexchange.com/questions/68911/…. You are already fetching the account from dummy privateKey. You can see from Petr's answer on how that object looks like. It has a signTransaction function which you need to do with that account. It will create a rawTransaction which is then sent by sendSignedTransaction. Read details in Web3 docs. Your account needs to be unlocked which you can also see from Web3 documentation. I know it seems confusing at first hence you need to readRoldan
R
6

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]
}
Raddy answered 17/8, 2021 at 21:6 Comment(0)
T
1

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)
Tankoos answered 10/1, 2022 at 7:26 Comment(0)
C
0

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.

Crankpin answered 24/6, 2022 at 16:49 Comment(1)
As it’s currently written, your answer is unclear. Please edit to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers in the help center.Putman

© 2022 - 2024 — McMap. All rights reserved.