Web3 advice? Hashlips? lol

Hello, first time up in here! Seen some great helpful stuff so far.

Trying to go further down into the code rabbit hole and was wondering if some kind soul could spare a few minutes ripping apart my efforts so far?

I’m no expert in this stuff so thought about reaching out. :smiley:

const ABI = [XYZ];
const contAdd = "XYZ";

//Async Minting Function 
async function mint(){

	//Web3 User Account 
	let web3 = new Web3(provider);
	let account = await web3.eth.getAccounts();

	//Mint Inputs
	let useraddress = account[0];
	let mintAmount = 1;  // soon to be variable from document.getElementById('#mint-qty');
	
	//Contract Deploy
	let contract = new web3.eth.Contract(abi, contAdd);

	let cost = 50000000000000000;
	let gasLimit = 285000;
	let totalCostWei = String(cost * mintAmount);
	let totalGasLimit = String(gasLimit * mintAmount);

	console.log("Cost: ", totalCostWei);
	console.log("Gas limit: ", totalGasLimit);

	await contract.methods.mint(useraddress,mintAmount)
		.send({gasLimit: String(totalGasLimit), to: contAdd, from: useraddress, value: totalCostWei, gasPrice:2500000001})
		.once("error", (err) => {
			console.log(err);
		})
		.then((receipt) => {
			console.log(receipt);
		});

}

I’m basically trying to adapt to mint like what’s in here:- https://github.com/HashLips/hashlips_nft_minting_dapp

Can get metamask to popup, but the data in the transaction is bigger than it should be.

My data in transaction DATA:-

Parameters:
[
  {
    "type": "address"
  },
  {
    "type": "uint256"
  }
]

What it should be:

Parameters:
[
  {
    "type": "uint256"
  }
]

I can see in that react code that there’s only “.mint(mintAmount)”

So I guess my question is what am I missing in the code snip above to mint, the demo only takes ‘mintAmount’ but mine is ‘useraddress,mintAmount’. Any work around, don’t mind sounding dumb in the aid of learning.

ABI =

{
    "inputs": [
      {
        "internalType": "address",
        "name": "_to",
        "type": "address"
      },
      {
        "internalType": "uint256",
        "name": "_mintAmount",
        "type": "uint256"
      }
    ],
    "name": "mint",
    "outputs": [],
    "stateMutability": "payable",
    "type": "function"
  }

This is going to make someone lol for sure.

Cheers in advance
CTF

I guess that you can change the abi to:

{
    "inputs": [
      {
        "internalType": "uint256",
        "name": "_mintAmount",
        "type": "uint256"
      }
    ],
    "name": "mint",
    "outputs": [],
    "stateMutability": "payable",
    "type": "function"
  }

and only send a parameter to that function

=> await contract.methods.mint(mintAmount)

If I understood what you want to do

1 Like

Yep understood, solved and minted. Now to continue on.

So I don’t need to include the whole ABI (from when contract deployed), just the parts I want to push/read via web3? I thought it had to match! Always the one part I never thought I could change.

Cheers bro!!!

yes, you don’t have to include all the smart contract abi, and you can also change/adapt it to your needs.