Skip to content

Commit

Permalink
refactor(pods): provide fallback in case of error getting latest tokenId
Browse files Browse the repository at this point in the history
  • Loading branch information
mmackz committed Jun 11, 2024
1 parent d220aca commit 92af08a
Showing 1 changed file with 18 additions and 12 deletions.
30 changes: 18 additions & 12 deletions packages/pods/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,23 @@ export async function getLatestTokenId(
chainId: number,
_client?: PublicClient,
): Promise<number> {
const client =
_client ??
createPublicClient({
chain: chainIdToViemChain(chainId),
transport: http(),
})
try {
const client =
_client ??
createPublicClient({
chain: chainIdToViemChain(chainId),
transport: http(),
})

const result = (await client.readContract({
address: contractAddress,
abi: ZORA_MINTER_ABI_1155,
functionName: 'nextTokenId',
})) as bigint
return Number(result) - 1
const result = (await client.readContract({
address: contractAddress,
abi: ZORA_MINTER_ABI_1155,
functionName: 'nextTokenId',
})) as bigint

return Number(result) - 1
} catch {
// fallback in case of error
return 1
}
}

0 comments on commit 92af08a

Please sign in to comment.