Skip to content

Commit caa900e

Browse files
committed
chore: cleanup contract references in auth-server and nft-quest
1 parent 94087ad commit caa900e

File tree

35 files changed

+538
-134
lines changed

35 files changed

+538
-134
lines changed

examples/nft-quest-contracts/deploy/deploy.ts

Lines changed: 1 addition & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,8 @@
11
import { formatEther, parseEther } from "ethers";
2-
import fs from "fs";
3-
import { HardhatRuntimeEnvironment } from "hardhat/types";
4-
import path from "path";
52

63
import { deployContract, getProvider, getWallet } from "./utils";
74

8-
export default async function (hre: HardhatRuntimeEnvironment) {
5+
export default async function () {
96
const provider = getProvider();
107

118
const baseTokenURI = "https://nft.zksync.dev/nft/metadata.json";
@@ -16,24 +13,6 @@ export default async function (hre: HardhatRuntimeEnvironment) {
1613
console.log("NFT CONTRACT: ", await nftContract.getAddress());
1714
console.log("PAYMASTER CONTRACT: ", await paymasterContract.getAddress());
1815

19-
if (hre.network.config.ethNetwork.includes("localhost")) {
20-
// Update the .env.local file with the contract addresses for NFT Quest app
21-
const envFilePath = path.join(__dirname, "../../nft-quest/.env.local");
22-
23-
// Check if the .env.local file exists, if not, create it
24-
if (!fs.existsSync(envFilePath)) {
25-
fs.writeFileSync(envFilePath, "", { encoding: "utf8" });
26-
console.log(`.env.local file has been created at ${envFilePath}`);
27-
}
28-
const nftContractAddress = await nftContract.getAddress();
29-
const paymasterContractAddress = await paymasterContract.getAddress();
30-
31-
const envContent = `NUXT_PUBLIC_CONTRACTS_NFT=${nftContractAddress}\nNUXT_PUBLIC_CONTRACTS_PAYMASTER=${paymasterContractAddress}\n`;
32-
33-
fs.writeFileSync(envFilePath, envContent, { encoding: "utf8" });
34-
console.log(`.env.local file has been updated at ${envFilePath}`);
35-
}
36-
3716
// fund the paymaster contract with enough ETH to pay for transactions
3817
const wallet = getWallet();
3918
await (

examples/nft-quest/README.md

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,9 @@ pnpm nx deploy contracts
1515
pnpm nx deploy:local nft-quest-contracts
1616
```
1717

18-
The contract addresses for the NFT Quest app will be set in `.env.local`. This
19-
.env file will override the values set in the `runtimeConfig` in
20-
`nuxt.config.ts`.
21-
22-
You may also need to update the contract addresses for the Auth Server in
23-
`/packages/auth-server/stores/client.ts` under the
24-
`contractsByChain[zksyncInMemoryNode.id]`
18+
Contract addresses are defined in the `/packages/auth-server/abi` directory.
19+
For local development using In Memory Node,
20+
edit the contracts' `addressByChain` for `260`.
2521

2622
```sh
2723
# Start the website and Auth Server

examples/nft-quest/abi/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
export * as Nft from "./nft";
2+
export * as Paymaster from "./paymaster";
Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,11 @@
1-
export const ZeekNftQuestAbi = [
1+
import type { AddressByChain } from "./types";
2+
3+
export const addressByChain: AddressByChain = {
4+
300: "0x4D533d3B20b50b57268f189F93bFaf8B39c36AB6",
5+
260: "0x111C3E89Ce80e62EE88318C2804920D4c96f92bb",
6+
};
7+
8+
export const Abi = [
29
{
310
inputs: [
411
{
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import type { AddressByChain } from "./types";
2+
3+
export const addressByChain: AddressByChain = {
4+
300: "0x60eef092977DF2738480a6986e2aCD10236b1FA7",
5+
260: "0x4B5DF730c2e6b28E17013A1485E5d9BC41Efe021",
6+
};

examples/nft-quest/abi/types.d.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import type { Address } from "viem";
2+
3+
export type AddressByChain = {
4+
[k in SupportedChainId]: Address;
5+
};

examples/nft-quest/composables/useMintNft.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,25 @@ import { waitForTransactionReceipt, writeContract } from "@wagmi/core";
22
import type { Address } from "viem";
33
import { getGeneralPaymasterInput } from "viem/zksync";
44

5+
import { Nft, Paymaster } from "~/abi";
6+
import type { SupportedChainId } from "~/stores/connector";
7+
58
export const useMintNft = async (_address: MaybeRef<Address>) => {
69
const address = toRef(_address);
710

811
return await useAsyncData("mintZeek", async () => {
912
const runtimeConfig = useRuntimeConfig();
1013
const { wagmiConfig } = storeToRefs(useConnectorStore());
14+
const chainId = runtimeConfig.public.defaultChainId as SupportedChainId;
1115

1216
const mintingForAddress = address.value;
17+
1318
const transactionHash = await writeContract(wagmiConfig.value, {
14-
address: runtimeConfig.public.contracts.nft as Address,
15-
abi: nftAbi,
19+
address: Nft.addressByChain[chainId] as Address,
20+
abi: Nft.Abi,
1621
functionName: "mint",
1722
args: [mintingForAddress],
18-
paymaster: runtimeConfig.public.contracts.paymaster as Address,
23+
paymaster: Paymaster.addressByChain[chainId] as Address,
1924
paymasterInput: getGeneralPaymasterInput({ innerInput: "0x" }),
2025
});
2126

examples/nft-quest/index.d.ts

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,6 @@
1-
import type { Chain } from "viem";
2-
31
declare module "nuxt/schema" {
42
interface PublicRuntimeConfig {
5-
chain: Chain;
6-
contracts: {
7-
nft: `0x${string}`;
8-
paymaster: `0x${string}`;
9-
};
3+
defaultChainId: number;
104
baseUrl: string;
115
authServerUrl: string;
126
explorerUrl: string;

examples/nft-quest/nuxt.config.ts

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,7 @@ export default defineNuxtConfig({
1919
$production: {
2020
runtimeConfig: {
2121
public: {
22-
chain: zksyncSepoliaTestnet,
23-
contracts: {
24-
nft: "0x4D533d3B20b50b57268f189F93bFaf8B39c36AB6",
25-
paymaster: "0x60eef092977DF2738480a6986e2aCD10236b1FA7",
26-
},
22+
defaultChainId: zksyncSepoliaTestnet.id,
2723
baseUrl: "https://nft.zksync.dev",
2824
authServerUrl: "https://auth-test.zksync.dev/confirm",
2925
explorerUrl: "https://sepolia.explorer.zksync.io",
@@ -57,11 +53,7 @@ export default defineNuxtConfig({
5753
},
5854
runtimeConfig: {
5955
public: {
60-
chain: zksyncInMemoryNode,
61-
contracts: {
62-
nft: "0x111C3E89Ce80e62EE88318C2804920D4c96f92bb",
63-
paymaster: "0x4B5DF730c2e6b28E17013A1485E5d9BC41Efe021",
64-
},
56+
defaultChainId: zksyncInMemoryNode.id,
6557
baseUrl: "http://localhost:3006",
6658
authServerUrl: "http://localhost:3002/confirm",
6759
explorerUrl: "http://localhost:3010",

examples/nft-quest/stores/connector.ts

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,24 @@
11
import { connect, createConfig, type CreateConnectorFn, disconnect, getAccount, http, reconnect, watchAccount } from "@wagmi/core";
2-
import { zksyncInMemoryNode, zksyncLocalNode, zksyncSepoliaTestnet } from "@wagmi/core/chains";
3-
import { type Address, type Hash, parseEther } from "viem";
2+
import { zksyncInMemoryNode, zksyncSepoliaTestnet } from "@wagmi/core/chains";
3+
import { type Address, parseEther } from "viem";
44
import { callPolicy, zksyncSsoConnector } from "zksync-sso/connector";
55

6-
import { ZeekNftQuestAbi } from "@/abi/ZeekNFTQuest";
6+
import { Nft } from "~/abi";
7+
8+
export type SupportedChainId = (typeof supportedChains)[number]["id"];
9+
10+
const supportedChains = [
11+
zksyncSepoliaTestnet,
12+
zksyncInMemoryNode,
13+
] as const;
714

815
export const useConnectorStore = defineStore("connector", () => {
916
const runtimeConfig = useRuntimeConfig();
10-
const supportedChains = [
11-
zksyncSepoliaTestnet,
12-
zksyncInMemoryNode,
13-
zksyncLocalNode,
14-
] as const;
15-
const chain = supportedChains.filter((x) => x.id == runtimeConfig.public.chain.id)[0];
17+
18+
const chainId = runtimeConfig.public.defaultChainId;
19+
const chain = supportedChains.filter((x) => x.id == chainId)[0];
1620
type SupportedChainId = (typeof supportedChains)[number]["id"];
17-
if (!chain) throw new Error(`Chain with id ${runtimeConfig.public.chain.id} was not found in supported chains list`);
21+
if (!chain) throw new Error(`Chain with id ${chainId} was not found in supported chains list`);
1822

1923
const connector = zksyncSsoConnector({
2024
metadata: {
@@ -25,8 +29,8 @@ export const useConnectorStore = defineStore("connector", () => {
2529
feeLimit: parseEther("0.001"),
2630
contractCalls: [
2731
callPolicy({
28-
address: runtimeConfig.public.contracts.nft as Hash,
29-
abi: ZeekNftQuestAbi,
32+
address: Nft.addressByChain[chainId],
33+
abi: Nft.Abi,
3034
functionName: "mint",
3135
}),
3236
],

0 commit comments

Comments
 (0)