Skip to content

Commit c4447b1

Browse files
karooolisfrolic
andauthored
fix(explorer): read system functions (#3783)
Co-authored-by: Kevin Ingersoll <kingersoll@gmail.com>
1 parent a8c404b commit c4447b1

2 files changed

Lines changed: 34 additions & 7 deletions

File tree

.changeset/nice-wombats-destroy.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@latticexyz/explorer": patch
3+
---
4+
5+
Fixed calls to system view functions.

packages/explorer/src/app/(explorer)/[chainName]/worlds/[worldAddress]/interact/content/FunctionField.tsx

Lines changed: 29 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -148,15 +148,37 @@ export function FunctionField({ systemId, worldAbi, functionAbi, useSearchParams
148148

149149
try {
150150
if (operationType === FunctionType.READ) {
151-
const { data: result } = await publicClient.call({
152-
account: account.address,
153-
data: encodeFunctionData({
154-
abi: [...worldAbi, functionAbi],
151+
let result;
152+
if (systemId) {
153+
const encoded = encodeSystemCall({
154+
abi: [functionAbi],
155155
functionName: functionAbi.name,
156156
args: encodeFunctionArgs(resolvedInputs, functionAbi),
157-
}),
158-
to: worldAddress as Address,
159-
});
157+
systemId,
158+
});
159+
160+
const { data } = await publicClient.call({
161+
account: account.address,
162+
data: encodeFunctionData({
163+
abi: [...worldAbi, functionAbi],
164+
functionName: "call",
165+
args: encoded,
166+
}),
167+
to: worldAddress as Address,
168+
});
169+
result = data;
170+
} else {
171+
const { data } = await publicClient.call({
172+
account: account.address,
173+
data: encodeFunctionData({
174+
abi: [...worldAbi, functionAbi],
175+
functionName: functionAbi.name,
176+
args: encodeFunctionArgs(resolvedInputs, functionAbi),
177+
}),
178+
to: worldAddress as Address,
179+
});
180+
result = data;
181+
}
160182

161183
setResult(stringify(result, null, 2).replace(/^"|"$/g, ""));
162184
} else {

0 commit comments

Comments
 (0)