Mint button for my NFT contract

Hey @63MoneyT

Please create a new topic for your issue. Also please provide us more info (the best solution is to share your github repo)

1 Like

Ok sorry about that but i think it may be that my server was maxed out, im new to moralis. I didnt know exactly what i would name the topic i andbin my confusion i just chose this thread. I was coding along and i try not to look at the repositories before i at least try on my own

I have it set up to mint like this can you tell me if it does not look right? For some reason i keep getting fund not defined in the console log. Im new to JS so bare with me and thank you for alll you help to this point.

    <script>
        async function fund(){
            amount = document.getElementById("100000000000000000").value;
            window.web3 = await Moralis.Web3.enable();
            let FootieStars = new web3.eth.Contract(('mintStars(uint256)', '1');, 0x9c90Ae0d3D6A29D58Bd57DF06494Ce985496a2fe);
            await FootieStars.methods.mintStars(_count).send({ value: amount, from: ethereum.selectedAddress });
        }

      
      document.getElementById("btn-mint").onclick = fund;
    
            
    </script>

this compiles:

async function fund(){
            amount = document.getElementById("100000000000000000").value;
            window.web3 = await Moralis.Web3.enable();
            let FootieStars = new web3.eth.Contract(('mintStars(uint256)', '1'), 0x9c90Ae0d3D6A29D58Bd57DF06494Ce985496a2fe);
            await FootieStars.methods.mintStars(_count).send({ value: amount, from: ethereum.selectedAddress });
        }

im getting this error in the console now.

“Uncaught (in promise) TypeError: Cannot read properties of null (reading ‘value’)”

It looks like it doesn’t find a html element with that particular id.

that is the html element calling the function sorry my post was not in the right context. i got almost every error out its just when i try to call the mint function from the front end its not reading the value of .1 ether

I am having a similar problem but with next JS. I am following the tutorial above however this is using html and JS not a JS framework like Next JS


async function init (){

    let currentUser = Moralis.User.current();

    if(!currentUser){

      window.location.pathname="/index.js"

    }

    web3 = await Moralis.Web3.enable();

    let accounts = await web3.eth.getAccounts();

    console.log(accounts);

    const urlParams = new URLSearchParams(window.location.search);

    const nftId = urlParams.get("nftId");

    document.getElementById("token_id").value = nftId;

  }

  async function mint(){

    let tokenId = parseInt(document.getElementById("token_id"));

    let address = document.getElementById("address_input");

    let amount = parseInt(document.getElementById("amount_input"));

  }

  init();

I used the code above and it says moralis is not defined I then added the code below but to no avail. At first i thought it was not needed as the moralis is initialised in the <MoralisProvider> tag in the _app.js.

 Moralis.initialize("XEu7NpoUqsIKwOFPI1xnm5RuwCckn8QFDusfIbaA");
  Moralis.serverURL = "https://e2s7tswf4xf4.moralishost.com:2053/server";

I am just tryig to call a funciton from my smart contract which would allow the user to mint an nft which allready exists on chain in the contract

You first have to find a way to import/use Moralis sdk in your framework, then you may have to use Moralis.start instead of Moralis.initialize.

So I am using the import { useMoralis } from "react-moralis"; which I then call the useMoralis() method from

I use the useMoralis() function to set up the wallet interaction

You may be able to import it as a normal node module too

This works in node js: Moralis in Nodejs import

for the mint function?

Looking at the code and it says getTokenPrice is there a mint command which I can put the contract address in instead of the mint address

I am looking at the api docs to see if there is something there link below

https://deep-index.moralis.io/api-docs/

That was only an example to use Moralis sdk, not a mint function, you can make a mint function directly only with web3 too if you want. You only have to call a smart contract function.

I am a noob at solidity, I have the contract function but just struggling to call it from a DOM object

I am guessing I add the method to the button like

<div className={styles.button1} id="mint"><a>Mint</a></div>

Then call it with an onclick function which is connected to the contract please tell me if this is wrong

That would be the idea, but you need to write more code that would call that mint function on click.

I am using this so will see how it goes…

https://docs.alchemy.com/alchemy/tutorials/how-to-create-an-nft/how-to-mint-a-nft