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