I know this is basic information, but for anyone who is having a hard time creating a simple mint button to deploy a ERC1155 or 721 contract, here is a straight forward mint.js file that will open metamask and mint whatever contract you plug in. Just add your moralis server url and id, change the contract address to your remix abi then boom! I hope this helps.
Moralis.initialize("YOUR MORALIS ID");
Moralis.serverURL = "YOUR MORALIS URL";
const contAdd = "0x24b94a42ed8f1432e6f81d7685fb3262c11bd6e2";
//Async Minting Function
async function mint(){
//Web3 User Account
let web3 = await Moralis.Web3.enable();
let account = await web3.eth.getAccounts();
//Mint Inputs
let tokenId = 1;
let address = account[0];
let amount = 1;
//Contract Deploy
const contract = new web3.eth.Contract(abi, contAdd);
contract.methods.mint(address, tokenId, amount).send({from: address, value: 0})
}
Set your HTML button to call the mint() onclick.
<html>
<!-- Moralis SDK code -->
<script src="https://cdn.jsdelivr.net/npm/web3@latest/dist/web3.min.js"></script>
<script src="https://unpkg.com/moralis/dist/moralis.js"></script>
<!-- Mint Button -->
<button onclick="mint()">Mint Me</button>
<!-- Script Imports -->
<script src="abi.js"></script>
<script src="mint.js"></script>
</html>
Donât forget to put your contract abi in a abi.js file and add it to your HTML. You can copy the abi directly from remix to copy and paste after "const abi = "
const abi = [
{
"inputs": [],
"stateMutability": "nonpayable",
"type": "constructor"
},
{
"anonymous": false,
"inputs": [
{ and so on and so on.................
Now try it!