1

I'm using this repo and following the instructions in the README. I've done the deployment bit. I've only deployed Creature.sol. The deployed contract is here

Now I'm trying to mint and exported the necessary env variables including the NFT contract address I got from deploying the creature.sol contract.

I ran the node scripts/mint.js, and I didn't hit the console log line:

 console.log("Minted creature. Transaction: " + result.transactionHash);

I did enter the loop as I printed the first number in the loop: 0.

Here's my code for mint.js. As I've only set the NFT_CONTRACT_ADDRESS, only the else if block runs:

const HDWalletProvider = require("truffle-hdwallet-provider");
const web3 = require("web3");
const MNEMONIC = process.env.MNEMONIC;
const NODE_API_KEY = process.env.INFURA_KEY || process.env.ALCHEMY_KEY;
const isInfura = !!process.env.INFURA_KEY;
const FACTORY_CONTRACT_ADDRESS = process.env.FACTORY_CONTRACT_ADDRESS;
const NFT_CONTRACT_ADDRESS = process.env.NFT_CONTRACT_ADDRESS;
const OWNER_ADDRESS = process.env.OWNER_ADDRESS;
const NETWORK = process.env.NETWORK;
const NUM_CREATURES = 10;
const NUM_LOOTBOXES = 4;
const DEFAULT_OPTION_ID = 0;
const LOOTBOX_OPTION_ID = 2;
console.log(!MNEMONIC, !NODE_API_KEY,  !OWNER_ADDRESS, !NETWORK)

if (!MNEMONIC || !NODE_API_KEY || !OWNER_ADDRESS || !NETWORK) {
  console.error(
    "Please set a mnemonic, Alchemy/Infura key, owner, network, and contract address."
  );
  return;
}

const NFT_ABI = [
  {
    constant: false,
    inputs: [
      {
        name: "_to",
        type: "address",
      },
    ],
    name: "mintTo",
    outputs: [],
    payable: false,
    stateMutability: "nonpayable",
    type: "function",
  },
];

const FACTORY_ABI = [
  {
    constant: false,
    inputs: [
      {
        name: "_optionId",
        type: "uint256",
      },
      {
        name: "_toAddress",
        type: "address",
      },
    ],
    name: "mint",
    outputs: [],
    payable: false,
    stateMutability: "nonpayable",
    type: "function",
  },
];

async function main() {
  const network =
    NETWORK === "mainnet" || NETWORK === "live" ? "mainnet" : "rinkeby";
  const provider = new HDWalletProvider(
    MNEMONIC,
    isInfura
      ? "https://" + network + ".infura.io/v3/" + NODE_API_KEY
      : "https://eth-" + network + ".alchemyapi.io/v2/" + NODE_API_KEY
  );
  const web3Instance = new web3(provider);

  console.log(network)
  console.log(isInfura)
  console.log(1)

  if (FACTORY_CONTRACT_ADDRESS) {
    const factoryContract = new web3Instance.eth.Contract(
      FACTORY_ABI,
      FACTORY_CONTRACT_ADDRESS,
      { gasLimit: "1000000" }
    );

    // Creatures issued directly to the owner.
    for (var i = 0; i < NUM_CREATURES; i++) {
      const result = await factoryContract.methods
        .mint(DEFAULT_OPTION_ID, OWNER_ADDRESS)
        .send({ from: OWNER_ADDRESS });
      console.log("Minted creature. Transaction: " + result.transactionHash);
    }

    // Lootboxes issued directly to the owner.
    for (var i = 0; i < NUM_LOOTBOXES; i++) {
      const result = await factoryContract.methods
        .mint(LOOTBOX_OPTION_ID, OWNER_ADDRESS)
        .send({ from: OWNER_ADDRESS });
      console.log("Minted lootbox. Transaction: " + result.transactionHash);
    }
  } else if (NFT_CONTRACT_ADDRESS) {
    console.log(2)

    const nftContract = new web3Instance.eth.Contract(
      NFT_ABI,
      NFT_CONTRACT_ADDRESS,
      { gasLimit: "1000000" }
    );

    console.log(nftContract)

    // Creatures issued directly to the owner.
    for (var i = 0; i < NUM_CREATURES; i++) {
      console.log(i) // <-- PRINTS 0
      const result = await nftContract.methods
        .mintTo(OWNER_ADDRESS)
        .send({ from: OWNER_ADDRESS });
      console.log('result is: ', result) // <-- DOESNT GET TO HERE 
      console.log("Minted creature. Transaction: " + result.transactionHash);
    }
  } else {
    console.error(
      "Add NFT_CONTRACT_ADDRESS or FACTORY_CONTRACT_ADDRESS to the environment variables"
    );
  }
}

console.log('before main')
main();

Here's my Creature.sol:

// SPDX-License-Identifier: MIT

pragma solidity ^0.8.0;

import "./ERC721Tradable.sol";

/**
 * @title Creature
 * Creature - a contract for my non-fungible creatures.
 */
contract Creature is ERC721Tradable {
    constructor(address _proxyRegistryAddress)
        ERC721Tradable("Curious Cats", "CC", _proxyRegistryAddress)
    {}

    function baseTokenURI() override public pure returns (string memory) {
        return "https://ayudh37.pythonanywhere.com/curious_cats/";
    }

    function contractURI() public pure returns (string memory) {
        return "https://creatures-api.opensea.io/contract/opensea-creatures";
    }
}

How do I mint?

1 Answer 1

1

I have encountered with the same error: enter image description here

Here is what's happening through 2_deploy_contract.js:

if (DEPLOY_CREATURES) {
console.log("deploy creature")
await deployer.deploy(Creature, proxyRegistryAddress, {gas: 5000000});

}

if (DEPLOY_CREATURES_SALE) {
    await deployer.deploy(CreatureFactory, proxyRegistryAddress, Creature.address, {gas: 5000000});
    const creature = await Creature.deployed();
    await creature.transferOwnership(CreatureFactory.address);
  }. 

In my case I have 'DEPLOY_CREATURES' and 'DEPLOY_CREATURES_SALE' defined. Once the 'Creature' contract is deployed, the code start deploying 'CreatureFactory' which upon successful deployment, 'Creature' contract will be transferred to 'CreatureFactory.address'. So your creator address for 'Creature' contract is no longer the owner. Instead, 'Creaturefactory' owns the contract as you can see from the following transaction:
enter image description here where '0x980219cdf0360e83a5bc6dc8092639fc266b18d0' is the Creature contract, '0x9d0d5a104a1039ba176c8e3812b71bd46da09b4b' is the CreatureFactory contract, the creator address is: '0xc3f6af7ba5ac45beda6ad3fc07985bfca218f069'. It shows the transfer of ownership in the transaction clearly!
You can still meant Creature through the factory contract by defining the factory contract address in process.env as:

FACTORY_CONTRACT_ADDRESS="0x9d0d5A104A1039ba176C8e3812B71bD46da09B4b"

Hope this explain it. It was not clearly explained in the original OpenSea guide.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.