deployContractsBase.js
1 // Import the ethers library 2 const { ethers } = require("hardhat"); 3 const provider = new ethers.JsonRpcProvider(process.env.ALCHEMY_URL_BASE) 4 const { TokenboundClient } = require("@tokenbound/sdk"); 5 const { createWalletClient, http } = require('viem') 6 const { privateKeyToAccount } = require('viem/accounts') 7 const { baseGoerli } = require('viem/chains') 8 const registryContractAddress = "0xae470391D4dee2ca9CA33192e1865b45F47F3527" 9 const accountContractAddress = "0xF4df15ED8002BDB96F263702CeeB94f5FCB28aBc" 10 11 const account = privateKeyToAccount(`0x` + process.env.PRIVATE_KEY) 12 13 const walletClient = createWalletClient({ 14 account, 15 chain: baseGoerli, 16 transport: http(process.env.ALCHEMY_URL_BASE) 17 }) 18 19 async function Main() { 20 21 const network = await provider.getNetwork() 22 const chainId = network.chainId 23 console.log(chainId) 24 // Get the signers from ethers 25 const wallet = new ethers.Wallet(process.env.PRIVATE_KEY, provider) 26 console.log(`SERVER_WALLET_PRIVATE_KEY=${process.env.PRIVATE_KEY}`) 27 console.log(`SERVER_WALLET_ADDRESS=${wallet.address}`) 28 29 // Deploy NPC contract 30 const NPCContract = await ethers.getContractFactory("CosmicCowboys"); 31 const npcContract = await NPCContract.deploy(wallet.address); 32 const npcContractAddress = await npcContract.getAddress() 33 console.log(`NPC_CONTRACT_ADDRESS=${npcContractAddress}`); 34 35 // Deploy ERC-20 Contract 36 const CurrencyContract = await ethers.getContractFactory("GoldenCorn"); 37 const currencyContract = await CurrencyContract.deploy(wallet.address); 38 const currencyContractAddress = await currencyContract.getAddress() 39 console.log(`CURRENCY_CONTRACT_ADDRESS=${currencyContractAddress}`) 40 41 // Deploy 1155 Contracts 42 const FoodContract = await ethers.getContractFactory("SpaceSlop"); 43 const foodContract = await FoodContract.deploy(wallet.address); 44 const foodContractAddress = await foodContract.getAddress() 45 console.log(`FOOD_CONTRACT_ADDRESS=${foodContractAddress}`); 46 47 const SupplyContract = await ethers.getContractFactory("JupiterJunk"); 48 const supplyContract = await SupplyContract.deploy(wallet.address); 49 const supplyContractAddress = await supplyContract.getAddress() 50 console.log(`SUPPLY_CONTRACT_ADDRESS=${supplyContractAddress}`); 51 52 /* // Deploy ERC6551 53 const RegistryContract = await ethers.getContractFactory("ERC6551Registry"); 54 const registryContract = await RegistryContract.deploy(); 55 const registryContractAddress = await registryContract.getAddress() 56 console.log("Registry Contract deployed to address:", registryContractAddress); 57 58 const AccountContract = await ethers.getContractFactory("ERC6551Account"); 59 const accountContract = await AccountContract.deploy(); 60 const accountContractAddress = await accountContract.getAddress() 61 console.log("Account Contract deployed to address:", accountContractAddress); */ 62 63 // Deploy Operator Contract 64 const OperatorContract = await ethers.getContractFactory("Operator"); 65 const operatorContract = await OperatorContract.deploy(wallet.address, npcContractAddress, currencyContractAddress, foodContractAddress, supplyContractAddress) 66 const operatorContractAddress = await operatorContract.getAddress() 67 console.log(`OPERATOR_CONTRACT_ADDRESS=${operatorContractAddress}`) 68 69 // Transfer NPC contract to Operator 70 await npcContract.transferOwnership(operatorContractAddress); 71 await currencyContract.transferOwnership(operatorContractAddress); 72 await foodContract.transferOwnership(operatorContractAddress); 73 await supplyContract.transferOwnership(operatorContractAddress); 74 75 const tokenboundClient = new TokenboundClient({ 76 walletClient: walletClient, 77 chain: baseGoerli, 78 implementationAddress: accountContractAddress, 79 registryAddress: registryContractAddress, 80 }) 81 82 for (let i = 0; i < 20; i++) { 83 // create NPC 84 const npcTx = await operatorContract.createNPC(wallet.address, `ipfs://QmQbwCMwDETHHZ1g8YaSHqLBwCRgVHqFuRNRfiGyNqCcXj/${i}.json`) 85 const npcTxReceipt = await npcTx.wait() 86 console.log("NPC Created") 87 88 // After the NPC is created 89 const latestTokenId = await operatorContract.getLatestTokenId(); 90 91 // create TBA for NPC 92 const tba = await tokenboundClient.createAccount({ 93 tokenContract: npcContractAddress, 94 tokenId: latestTokenId, 95 }) 96 console.log("TBA:", tba) 97 98 // equip NPC via TBA 99 const fundNpcTx = await operatorContract.fundNPC(tba, 20) 100 const fundNpxTxReceipt = await fundNpcTx.wait() 101 console.log("NPC Funded") 102 103 const feedNpcTx = await operatorContract.feedNPC(tba, 5) 104 const feedNpcTxReceipt = await feedNpcTx.wait() 105 console.log("NPC Fed") 106 107 const supplyNpcTx = await operatorContract.supplyNPC(tba, 5) 108 const supplyNpcTxReceipt = await supplyNpcTx.wait() 109 console.log("NPC Supplied") 110 111 } 112 } 113 114 Main()