Can I make Ethers Wallet Addresses pass RSK Testnet case checksum test?

187 Views Asked by At

On RSK public testnet, I create my RSK wallet with ethers like this:

const wallet = await ethers.Wallet.createRandom()

Then the address is: 0x68C06960f0Cd2bB0318673F157243Ad545AbbE2A

When I send an amount to it, and explore the transaction on RSK testnet explorer, the actual destination address of the transaction has a difference in case (EIP-1191) 0x68C06960f0CD2bB0318673f157243aD545AbBE2a

How can I make ethers generate the address in the right checksum case right away? Does it really matter at the end? Ideally, I would like to be enforce the chainId in the transaction request so that I am sure that my transaction will not occur on any other chain than RSK.

Thanks

1

There are 1 best solutions below

2
Jesse Clark On

As the comment above mentions, ethers doesn't accept the chainId as a property, however, the @rsksmart/rsk-util library does. Specifically, the toChecksumAddress() method.

It would be like this:

import { toChecksumAddress } from 'rskjs-util'

const address = "0x3Dd03d7d6c3137f1Eb7582Ba5957b8A2e26f304A"
const chainId = 30 // RSK Mainnet, 31 is RSK Testnet

const checksum = toChecksumAddress(address, chainId)

console.log(checksum) // 0x3DD03d7d6c3137f1EB7582bA5957b8A2e26F304A

If you pass a RSK checksummed address to Ethers it will throw an error that the checksum is incorrect. This is because Ethers only checks for the Ethereum version. So, before sending an address back to Ethers, convert it to lowercase.

The checksum should be used when you are displaying it to the end user. It won't prevent an address being used on multiple networks, but it is an indication/caution to the user that perhaps the address they typed/pasted in might be for a different network.

About a year ago I wrote a blog post about this, Checksums are for humans, not computers.