Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does web3.js reject a valid RSK smart contract address?

I'm trying to interact with smart contracts on the RSK Mainnet, and I'm getting this error...

Provided address "0xAb2d290b7a600f5eA8d5B933f6F15c867Fd7e60e" is invalid,
the capitalization checksum test failed, 
or its an indirect IBAN address which can't be converted.

The address is obtained from RSK Explorer itself, so I'm not sure why web3.js has this error.

Please, could someone help me?

Thanks in advance!

like image 358
Solange Gueiros Avatar asked Jan 20 '21 13:01

Solange Gueiros


People also ask

Is web3 a smart contract?

Web3 contracts, also known as smart contracts, are crucial in today's blockchain ecosystem. They enable users to interact online via the blockchain and the many dapps in the Web3 realm. Further, they set the conditions for decentralized transactions without needing a centralized third-party authority for verification.

How do I deploy a contract in web3?

Step 1: Create web3 object and connect it with the Ganache. Before that check, Ganache is installed in the system. If Ganache is already installed then one would be able to see an HTTP URL that Ganache provides i.e. Step 3: Ganache can be controlled with the help of web3.


1 Answers

As per RSKIP-60, RSK network has its own checksum validation following EIP1191.

However, some tools and libraries still don't support EIP-1191.

Most Ethereum tools and libraries support EIP-155 only. web3.js is one of them, and it checks the checksum expecting an EIP-155 checksum.

Workarounds

(1) Convert the smart contract address to an all-lowercase string:

return new web3.eth.Contract(coinBackAbi, tokenObj.address.toString().toLowerCase());

Note that both EIP-155 and EIP-1191 define that all-lowercase addresses are to be treated as "skip checksum".

(2) Another approach is to use @rsksmart/rsk-utils, using this to convert the address to use the appropriate checksum:

// Ethereum --> use this for web3.js
toChecksumAddress ("0xAb2d290b7a600f5eA8d5B933f6F15c867Fd7e60e", null)
// RSK Mainnet
toChecksumAddress ("0xAb2d290b7a600f5eA8d5B933f6F15c867Fd7e60e", 30)
like image 93
Jesse Clark Avatar answered Dec 05 '22 21:12

Jesse Clark