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