Skip to content

Commit

Permalink
fix hex of odd length for eth_getStorageAt call when forking arbitrum
Browse files Browse the repository at this point in the history
  • Loading branch information
DZariusz committed Sep 22, 2021
1 parent fe38c5d commit 8dfe5cf
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 3 deletions.
5 changes: 5 additions & 0 deletions .changeset/neat-cars-explain.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"hardhat": patch
---

fix hex of odd length for eth_getStorageAt call when forking arbitrum
Original file line number Diff line number Diff line change
Expand Up @@ -80,12 +80,20 @@ export function rpcQuantityToBN(quantity: string): BN {
}

export function numberToRpcQuantity(n: number | BN): string {
return numberToRpcQuantityWithLeadingZeros(n, false);
}

export function numberToRpcQuantityWithLeadingZeros(
n: number | BN,
leadingZeros: boolean
): string {
assertHardhatInvariant(
typeof n === "number" || BN.isBN(n),
"Expected number"
);

return `0x${n.toString(16)}`;
const s = n.toString(16);
return leadingZeros ? `0x${s.length % 2 ? "0" : ""}${s}` : `0x${s}`;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ import * as t from "io-ts";
import path from "path";

import {
numberToRpcQuantity,
numberToRpcQuantity,
numberToRpcQuantityWithLeadingZeros,
rpcData,
rpcQuantity,
} from "../../core/jsonrpc/types/base-types";
Expand Down Expand Up @@ -56,7 +57,7 @@ export class JsonRpcClient {
"eth_getStorageAt",
[
address.toString(),
numberToRpcQuantity(position),
numberToRpcQuantityWithLeadingZeros(position, true),
numberToRpcQuantity(blockNumber),
],
rpcData,
Expand Down

0 comments on commit 8dfe5cf

Please sign in to comment.