|
| 1 | +#!/bin/bash |
| 2 | +set -e |
| 3 | + |
| 4 | +# Colors for output |
| 5 | +RED='\033[0;31m' |
| 6 | +GREEN='\033[0;32m' |
| 7 | +YELLOW='\033[1;33m' |
| 8 | +NC='\033[0m' # No Color |
| 9 | + |
| 10 | +SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" |
| 11 | +PROJECT_ROOT="$(cd "$SCRIPT_DIR/../../.." && pwd)" |
| 12 | +CONTRACTS_DIR="$(cd "$SCRIPT_DIR/.." && pwd)" |
| 13 | + |
| 14 | +echo -e "${GREEN}Deploying NFT Quest contract only...${NC}" |
| 15 | + |
| 16 | +# Configuration |
| 17 | +RPC_URL="http://127.0.0.1:8545" |
| 18 | +ANVIL_ACCOUNT_0_KEY="0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80" |
| 19 | + |
| 20 | +# Check if demo-app contracts exist |
| 21 | +DEMO_APP_CONTRACTS="$PROJECT_ROOT/examples/demo-app/contracts-anvil.json" |
| 22 | +if [ ! -f "$DEMO_APP_CONTRACTS" ]; then |
| 23 | + echo -e "${RED}Error: Demo-app contracts not found at $DEMO_APP_CONTRACTS${NC}" |
| 24 | + echo -e "${YELLOW}Please deploy ERC-4337 infrastructure first:${NC}" |
| 25 | + echo -e " pnpm nx deploy-msa-factory demo-app" |
| 26 | + echo -e "${YELLOW}Or run auth-server dev which deploys it automatically:${NC}" |
| 27 | + echo -e " pnpm nx dev auth-server" |
| 28 | + exit 1 |
| 29 | +fi |
| 30 | + |
| 31 | +echo -e "${GREEN}Found demo-app contracts at $DEMO_APP_CONTRACTS${NC}" |
| 32 | + |
| 33 | +# Deploy NFT Contract |
| 34 | +echo -e "${GREEN}Deploying ZeekNFTQuest...${NC}" |
| 35 | +BASE_TOKEN_URI="https://nft.zksync.dev/nft/metadata.json" |
| 36 | + |
| 37 | +cd "$CONTRACTS_DIR" |
| 38 | + |
| 39 | +DEPLOY_OUTPUT=$(forge create \ |
| 40 | + --rpc-url "$RPC_URL" \ |
| 41 | + --private-key "$ANVIL_ACCOUNT_0_KEY" \ |
| 42 | + --broadcast \ |
| 43 | + contracts/ZeekNFTQuest.sol:ZeekNFTQuest \ |
| 44 | + --constructor-args "$BASE_TOKEN_URI" 2>&1) |
| 45 | + |
| 46 | +NFT_ADDRESS=$(echo "$DEPLOY_OUTPUT" | grep "Deployed to:" | awk '{print $3}') |
| 47 | + |
| 48 | +echo -e "${GREEN}NFT Contract deployed at: $NFT_ADDRESS${NC}" |
| 49 | + |
| 50 | +# Read shared infrastructure from demo-app |
| 51 | +PAYMASTER=$(jq -r '.mockPaymaster // .testPaymaster' "$DEMO_APP_CONTRACTS") |
| 52 | +SESSION_VALIDATOR=$(jq -r '.sessionValidator' "$DEMO_APP_CONTRACTS") |
| 53 | +WEBAUTHN_VALIDATOR=$(jq -r '.webauthnValidator' "$DEMO_APP_CONTRACTS") |
| 54 | +ENTRY_POINT=$(jq -r '.entryPoint' "$DEMO_APP_CONTRACTS") |
| 55 | +BUNDLER_URL=$(jq -r '.bundlerUrl // "http://localhost:4337"' "$DEMO_APP_CONTRACTS") |
| 56 | +FACTORY=$(jq -r '.factory' "$DEMO_APP_CONTRACTS") |
| 57 | +EOA_VALIDATOR=$(jq -r '.eoaValidator' "$DEMO_APP_CONTRACTS") |
| 58 | +GUARDIAN_EXECUTOR=$(jq -r '.guardianExecutor' "$DEMO_APP_CONTRACTS") |
| 59 | + |
| 60 | +echo -e "${GREEN}Using shared ERC-4337 infrastructure from demo-app:${NC}" |
| 61 | +echo -e " Paymaster: $PAYMASTER" |
| 62 | +echo -e " Session Validator: $SESSION_VALIDATOR" |
| 63 | +echo -e " Webauthn Validator: $WEBAUTHN_VALIDATOR" |
| 64 | +echo -e " Entry Point: $ENTRY_POINT" |
| 65 | +echo -e " Bundler URL: $BUNDLER_URL" |
| 66 | + |
| 67 | +# Write .env.local for Nuxt runtime config |
| 68 | +ENV_FILE="$PROJECT_ROOT/examples/nft-quest/.env.local" |
| 69 | +cat > "$ENV_FILE" << EOF |
| 70 | +NUXT_PUBLIC_CONTRACTS_NFT=$NFT_ADDRESS |
| 71 | +NUXT_PUBLIC_CONTRACTS_PAYMASTER=$PAYMASTER |
| 72 | +EOF |
| 73 | + |
| 74 | +echo -e "${GREEN}.env.local written to $ENV_FILE${NC}" |
| 75 | + |
| 76 | +# Write public/contracts.json for runtime access |
| 77 | +PUBLIC_DIR="$PROJECT_ROOT/examples/nft-quest/public" |
| 78 | +mkdir -p "$PUBLIC_DIR" |
| 79 | +CONTRACTS_JSON="$PUBLIC_DIR/contracts.json" |
| 80 | + |
| 81 | +cat > "$CONTRACTS_JSON" << EOF |
| 82 | +{ |
| 83 | + "rpcUrl": "$RPC_URL", |
| 84 | + "chainId": 1337, |
| 85 | + "entryPoint": "$ENTRY_POINT", |
| 86 | + "bundlerUrl": "$BUNDLER_URL", |
| 87 | + "factory": "$FACTORY", |
| 88 | + "eoaValidator": "$EOA_VALIDATOR", |
| 89 | + "sessionValidator": "$SESSION_VALIDATOR", |
| 90 | + "webauthnValidator": "$WEBAUTHN_VALIDATOR", |
| 91 | + "guardianExecutor": "$GUARDIAN_EXECUTOR", |
| 92 | + "testPaymaster": "$PAYMASTER", |
| 93 | + "mockPaymaster": "$PAYMASTER", |
| 94 | + "nftContract": "$NFT_ADDRESS" |
| 95 | +} |
| 96 | +EOF |
| 97 | + |
| 98 | +echo -e "${GREEN}contracts.json written to $CONTRACTS_JSON${NC}" |
| 99 | + |
| 100 | +echo -e "${GREEN}✅ NFT-Quest contract deployment complete!${NC}" |
| 101 | +echo -e " - NFT Contract: $NFT_ADDRESS" |
| 102 | +echo -e " - Paymaster (shared): $PAYMASTER" |
| 103 | +echo -e " - Session Validator (shared): $SESSION_VALIDATOR" |
0 commit comments