Closed abrel closed 2 years ago
Wonderfully formatted issue!
So a few things:
arrayPositionInStore
is 2, however, in order to use keccak256
, we need to pass it the unpacked version of 2 (yes, I also think ethers should be smart enough to convert it correctly!)Running:
console.log(ethers.utils.hexlify(2))
Will return:
0x02
But you want:
0x0000000000000000000000000000000000000000000000000000000000000002
You could use something like hexZeroPad to get this.
Or just do:
const arraySlot = ethers.utils.keccak256("0x0000000000000000000000000000000000000000000000000000000000000002");
Which should be location: 0x405787fa12a823e0f2b7631cc41b3ba8828b3321ca811111fa75cd3aa3bb5ace
Same issue as array stuff. You'll be looking for location: 0x3617319a054d772f909f7c479a2cebe5066e836a939412e32403c99029b92eff
In the future, you can actually "trace" all transactions and see the storage updates yourself with something like this:
const trace = await network.provider.send("debug_traceTransaction", [
funWithStorage.transactionHash,
])
for (structLog in trace.structLogs) {
if (trace.structLogs[structLog].op == "SSTORE") {
console.log(trace.structLogs[structLog])
}
}
This will print out every time the SSTORE
opcode is called, and you'll be able to see what storage looks like!
Many thanks :) It works perfectly after adding the padding ! The debug_traceTransaction is super helpful.
Hi,
First of all many thanks for this great course on hardhat & solidity. I am following lesson 7: Hardhat fund me but I cannot figure how to find slots and value for mappings & arrays cf : comments from deploy script
0. Solidity Code
1. Array stuff
To retrieve slots for uint256[] myArray (position = 2 ; cf: Solidity code)
I am using the following code :
However arrayValue is :
While I am expecting 222 here.
2. Mapping stuff
To retrieve slots for uint256[] myArray (position = 3 ; cf: Solidity code)
I am using the following code :
However mappingValue is :
while I am expecting 1 (true).
Could you please give me some pointers regarding what I am doing wrong ?