Pro Girl
Pro Girl

Reputation: 952

How to input data to a solidity smart contract function from Javascript?

I have deployed smart contract on the Rinkeby test network with this address:

0x5e9C4F23d85c28fAD0E7B117B3E0fc94A2da07b0

I am succesfully connect to the contract and able to use other functions, like setPaused, etc. I am trying to use the mint function of this smart contract, but getting error when trying to mint.

This is my html code:

<!DOCTYPE html>
<html>
  <head>
    <title>Basic Template</title>
    <script src="https://cdn.jsdelivr.net/npm/web3@latest/dist/web3.min.js"></script>
  </head>

  <body>
    <button id="btn-login" onclick="login();">Connect Metamask</button>
    <button id="mint">mint</button>
    <script type="text/javascript" src="./abi.js"></script>
    <script type="text/javascript" src="./mint.js"></script>
  </body>
</html>

This is my javascript function mint:

async function mint() {
  const accounts = await web3.eth.getAccounts();
  const contract = new web3.eth.Contract(contractAbi, nft_contract_address);
  contract.methods.mint(1).send({from: accounts[0], value: 10000000000000000})
}

document.getElementById("mint").onclick = mint;

This is my solidity function:

  function mint(uint256 _mintAmount) public payable mintCompliance(_mintAmount) {
    require(!paused, "The contract is paused!");
    require(msg.value >= cost * _mintAmount, "Insufficient funds!");

When I push the mint button, the metamask opens but it says that the transaction will likely fail and does not let me proceed.

Any idea why?

Upvotes: 0

Views: 1409

Answers (1)

Pro Girl
Pro Girl

Reputation: 952

The contract was set as "pause" = "true", hence the transaction was not going trough.

Upvotes: 1

Related Questions