在我的薄荷合同中,它说内部类型是uint256,而令牌薄荷价格是0.01ETH,所以我不知道如何在前面将它转换为uint256?
{
"inputs": [
{ "internalType": "uint256", "name": "_mintAmount", "type": "uint256" }
],
"name": "mint",
"outputs": [],
"stateMutability": "payable",
"type": "function"
},我使用ethers.js与契约交互,以unit256的形式传递值的最佳方法是什么?
下面是我得到的错误:
MetaMask - RPC Error: execution reverted: Invalid mint amount!以下是我对前线的呼唤
const mintContract = async () => {
if (contract) {
try {
const tx = contract.mint(utils.parseUnits("0.01"));
tx.wait();
} catch (error) {
await setError(true);
}
}
};发布于 2022-02-06 19:49:23
问题是,您没有与事务一起发送0.01以太。你是在告诉合同是0.01 .
试试这个,确保你有乙醚。
const mintContract = async () => {
if (contract) {
try {
const numberOfTokenToMint = 1;
const options = {value: utils.parseUnits("0.01")}
const tx = await contract.mint(numberOfTokenToMint, options);
await tx.wait();
} catch (error) {
await setError(true);
}
}
};https://ethereum.stackexchange.com/questions/120970
复制相似问题