Skip to content

Commit 75145e7

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

File tree

32 files changed

+526
-105
lines changed

32 files changed

+526
-105
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: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,10 @@
1-
export const ZeekNftQuestAbi = [
1+
export const addressByChain = {
2+
324: "0x",
3+
300: "0x4D533d3B20b50b57268f189F93bFaf8B39c36AB6",
4+
260: "0x111C3E89Ce80e62EE88318C2804920D4c96f92bb",
5+
};
6+
7+
export const Abi = [
28
{
39
inputs: [
410
{
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
export const addressByChain = {
2+
324: "0x",
3+
300: "0x60eef092977DF2738480a6986e2aCD10236b1FA7",
4+
260: "0x4B5DF730c2e6b28E17013A1485E5d9BC41Efe021",
5+
};

examples/nft-quest/composables/useMintNft.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,23 @@ 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+
57
export const useMintNft = async (_address: MaybeRef<Address>) => {
68
const address = toRef(_address);
79

810
return await useAsyncData("mintZeek", async () => {
911
const runtimeConfig = useRuntimeConfig();
1012
const { wagmiConfig } = storeToRefs(useConnectorStore());
13+
const chainId = runtimeConfig.public.defaultChainId;
1114

1215
const mintingForAddress = address.value;
1316
const transactionHash = await writeContract(wagmiConfig.value, {
14-
address: runtimeConfig.public.contracts.nft as Address,
17+
address: Nft.addressByChain[chainId],
1518
abi: nftAbi,
1619
functionName: "mint",
1720
args: [mintingForAddress],
18-
paymaster: runtimeConfig.public.contracts.paymaster as Address,
21+
paymaster: Paymaster.addressByChain[chainId],
1922
paymasterInput: getGeneralPaymasterInput({ innerInput: "0x" }),
2023
});
2124

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: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import { connect, createConfig, type CreateConnectorFn, disconnect, getAccount, http, reconnect, watchAccount } from "@wagmi/core";
22
import { zksyncInMemoryNode, zksyncLocalNode, zksyncSepoliaTestnet } from "@wagmi/core/chains";
3-
import { type Address, type Hash, parseEther } from "viem";
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";
77

88
export const useConnectorStore = defineStore("connector", () => {
99
const runtimeConfig = useRuntimeConfig();
@@ -12,9 +12,10 @@ export const useConnectorStore = defineStore("connector", () => {
1212
zksyncInMemoryNode,
1313
zksyncLocalNode,
1414
] as const;
15-
const chain = supportedChains.filter((x) => x.id == runtimeConfig.public.chain.id)[0];
15+
const chainId = runtimeConfig.public.defaultChainId;
16+
const chain = supportedChains.filter((x) => x.id == chainId)[0];
1617
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`);
18+
if (!chain) throw new Error(`Chain with id ${chainId} was not found in supported chains list`);
1819

1920
const connector = zksyncSsoConnector({
2021
metadata: {
@@ -25,8 +26,8 @@ export const useConnectorStore = defineStore("connector", () => {
2526
feeLimit: parseEther("0.001"),
2627
contractCalls: [
2728
callPolicy({
28-
address: runtimeConfig.public.contracts.nft as Hash,
29-
abi: ZeekNftQuestAbi,
29+
address: Nft.addressByChain[chainId],
30+
abi: Nft.Abi,
3031
functionName: "mint",
3132
}),
3233
],

packages/auth-server/abi/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
export * as NFTQuest from "./nft-quest";
2+
export * as SSO from "./sso";

0 commit comments

Comments
 (0)