Skip to content

Commit

Permalink
fix: improve ABI resolution fallback
Browse files Browse the repository at this point in the history
  • Loading branch information
joaquim-verges committed Sep 23, 2024
1 parent d936d4e commit fb5324a
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
5 changes: 5 additions & 0 deletions .changeset/loud-beds-pull.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"thirdweb": patch
---

Fix abi resolution fallback
12 changes: 8 additions & 4 deletions packages/thirdweb/src/contract/actions/resolve-abi.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
import { type Abi, formatAbi, parseAbi } from "abitype";
import { getInstalledModules } from "../../extensions/modules/__generated__/IModularCore/read/getInstalledModules.js";
import { download } from "../../storage/download.js";
import { extractIPFSUri } from "../../utils/bytecode/extractIPFS.js";
import { getClientFetch } from "../../utils/fetch.js";
import type { ThirdwebContract } from "../contract.js";
import { getBytecode } from "./get-bytecode.js";

const ABI_RESOLUTION_CACHE = new WeakMap<ThirdwebContract<Abi>, Promise<Abi>>();

Expand Down Expand Up @@ -117,7 +114,11 @@ export async function resolveAbiFromBytecode(
// biome-ignore lint/suspicious/noExplicitAny: library function that accepts any contract type
contract: ThirdwebContract<any>,
): Promise<Abi> {
const bytecode = await getBytecode(contract);
const [{ resolveImplementation }, { extractIPFSUri }] = await Promise.all([
import("../../utils/bytecode/resolveImplementation.js"),
import("../../utils/bytecode/extractIPFS.js"),
]);
const { bytecode } = await resolveImplementation(contract);
if (bytecode === "0x") {
const { id, name } = contract.chain;
throw new Error(
Expand Down Expand Up @@ -366,6 +367,9 @@ async function resolveModularModuleAddresses(
contract: ThirdwebContract,
): Promise<string[]> {
try {
const { getInstalledModules } = await import(
"../../extensions/modules/__generated__/IModularCore/read/getInstalledModules.js"
);
const modules = await getInstalledModules({ contract });
// if there are no plugins, return the root ABI
if (!modules.length) {
Expand Down

0 comments on commit fb5324a

Please sign in to comment.