You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hi Everyone,
I want to use GetStorageRanges in Snap Protocol https://github.com/ethereum/devp2p/blob/master/caps/snap.md#getstorageranges-0x02 for get balance of ERC20 token from Peer (i do not want to use RCP).
Based on my understanding, balance of ERC20 token is stored in storage slots
I check with USDT token: 0xdAC17F958D2ee523a2206206994597C13D831ec7
My account holder: 0xC0fcFAd6a5db86F566102B8a7115823068a93c50
Current my USDT balance on Metamask is: 7.45433 USDT
I checked on this tool: https://github.com/vocdoni/storage-proofs-eth-go/blob/master/examples/verify-top-50-erc20/main.go with USDT token and my account above
=>The result: my USDT balance was stored in slot 2, slot hash is: 0xc83ac632ddd978600e673c3064377a289fc7b6beba2050e1c1b0c5905a89fb9e
Based on above result, my code is:
......
func GetMapSlot(holder common.Address, position int) [32]byte {
return crypto.Keccak256Hash(
common.LeftPadBytes(holder[:], 32),
common.LeftPadBytes(big.NewInt(int64(position)).Bytes(), 32),
)
}
func main(){
token_addr:=common.HexToAddress("0xdAC17F958D2ee523a2206206994597C13D831ec7") //USDT
token_hash:=crypto.Keccak256Hash(token_addr[:])
fmt.Println("1. USDT Token hash: ",token_hash)
account_addr:=common.HexToAddress("0xC0fcFAd6a5db86F566102B8a7115823068a93c50") //holder address
start_slot_hash:=GetMapSlot(account_addr,2)
fmt.Println("2. Start slot hash: ",common.Hash(start_slot_hash).Hex())
end_slot_hash:=start_slot_hash
//StateRoot: just pick a latest block on etherscan.io
root_hash:=common.HexToHash("0xe87f3c92bbeadc3963c747fd039e390d4f3e0f0f9e6491302b96d20b284db0a0")
/*
.....
create a peer connection as this example: https://github.com/ethereum/go-ethereum/blob/master/cmd/devp2p/internal/ethtest/conn.go
*/
// write request
req := &snap.GetStorageRangesPacket{
ID: uint64(rand.Int63()),
Root: root_hash,
Accounts: []common.Hash{token_hash},
Origin: start_slot_hash[:],
Limit: end_slot_hash[:],
Bytes: 4000,
}
msg, err := conn.snapRequest(snap.GetStorageRangesMsg, req)
if err != nil {
return
}
res, ok := msg.(*snap.StorageRangesPacket)
if !ok {
return
}
for _, slots := range res.Slots {
for j := 0; j < len(slots); j++ {
slot_hash:=slots[j].Hash
balance:=new(big.Int).SetBytes(slots[j].Body)
fmt.Println("3. Slot hash from Peer: ",slot_hash)
fmt.Println("4. Balance from Peer: ",balance)
}
}
}
Hi Everyone,
I want to use GetStorageRanges in Snap Protocol https://github.com/ethereum/devp2p/blob/master/caps/snap.md#getstorageranges-0x02 for get balance of ERC20 token from Peer (i do not want to use RCP).
Based on my understanding, balance of ERC20 token is stored in storage slots
I check with USDT token:
0xdAC17F958D2ee523a2206206994597C13D831ec7
My account holder:
0xC0fcFAd6a5db86F566102B8a7115823068a93c50
Current my USDT balance on Metamask is: 7.45433 USDT
I checked on this tool: https://github.com/vocdoni/storage-proofs-eth-go/blob/master/examples/verify-top-50-erc20/main.go with USDT token and my account above
=>The result: my USDT balance was stored in slot 2, slot hash is:
0xc83ac632ddd978600e673c3064377a289fc7b6beba2050e1c1b0c5905a89fb9e
Based on above result, my code is:
After i excuted above code, the result is:
Slot hash (3) return from Peer is difference with (2) and blance (4) from Peer also difference with my current USDT balance. What is wrong in my code?
The text was updated successfully, but these errors were encountered: