From 47b8084e19eeb95d8f0d40728075c5c33d70e7f3 Mon Sep 17 00:00:00 2001 From: weiihann Date: Mon, 4 Nov 2024 21:45:06 +0800 Subject: [PATCH] Fixes getStorageAt undeployed contract response fix Revert "Fixes getStorageAt undeployed contract response" This reverts commit bd44ef2d79ace6abe9358c053ea3b640dc389bb0. fix --- rpc/contract.go | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/rpc/contract.go b/rpc/contract.go index e0eb3b7c2a..a770bb284c 100644 --- a/rpc/contract.go +++ b/rpc/contract.go @@ -39,6 +39,13 @@ func (h *Handler) StorageAt(address, key felt.Felt, id BlockID) (*felt.Felt, *js } defer h.callAndLogErr(stateCloser, "Error closing state reader in getStorageAt") + // This checks if the contract exists because if a key doesn't exist in contract storage, + // the returned value is always zero and error is nil. + _, err := stateReader.ContractNonce(&address) + if err != nil { + return nil, ErrContractNotFound + } + value, err := stateReader.ContractStorage(&address, &key) if err != nil { return nil, ErrContractNotFound