1

I am using the following code to set a slot to a value on hardhat network:

  public async setStorageAt(addr: EthAddress, slot: string, value: string): Promise<any> {
    const result = await this.provider.request({
      method: 'hardhat_setStorageAt',
      params: [addr.toString(), slot, value],
    });
    return result;
  }

And when I try to set the value of a slot

0x0c0c87e2d76a59631866640201b73cd5494944ef1f6c0605583699b7d52d4e8d,

I get the following error in the logs of hardhat network node:

hardhat_setStorageAt

  Errors encountered in param 1: Invalid value "0x0c0c87e2d76a59631866640201b73cd5494944ef1f6c0605583699b7d52d4e8d" supplied to : QUANTITY

Why am I receiving this error given that the value is smaller than the max storage slot index (2 ** 256)?

The contract I am interacting with is on mainnet and has the following address:

0xEd279fDD11cA84bEef15AF5D39BB4d4bEE23F0cA

Thank you

4
  • Can you also add the contract?
    – Julissa DC
    Jun 6, 2022 at 13:15
  • Just added it to the question. Thank you
    – Jan Beneš
    Jun 6, 2022 at 13:21
  • On which network is that address? On mainnet it leads to a very big contract
    – Julissa DC
    Jun 6, 2022 at 13:29
  • The contract is on mainnet. It is a Curve pool contract and I would like to mint the LP tokens in tests.
    – Jan Beneš
    Jun 6, 2022 at 13:55

1 Answer 1

1

The issue was that the node doesn't expect there to be leading zeros. When I replaced this:

0x0c0c87e2d76a59631866640201b73cd5494944ef1f6c0605583699b7d52d4e8d

with:

0xc0c87e2d76a59631866640201b73cd5494944ef1f6c0605583699b7d52d4e8d

Everything worked.

I've used ethers.utils.hexStripZeros to achieve that:

const userBalanceSlot = utils.hexStripZeros(utils.keccak256(utils.defaultAbiCoder.encode(['address', 'uint'], [randomAddress, i])));

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.