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