我正在使用醚和反应为我的dApp。我使用的智能合同有存款功能和提款功能。我的取款函数是从前端开始工作的,但是存款函数需要两个参数:地址和应付金额。我可以与孟买多边形扫描的智能合同进行交互,而不会有任何问题。
如何使用户在输入字段中输入金额,单击“投资”-button,然后需要在MetaMask中接受已存入的金额,然后调用invest()?
我被困在这里很久了。任何帮助都是非常感谢的。
下面是我试图与之交互的实体函数:
function invest(address _ref) public payable{
if (_invest(msg.sender, _ref, msg.value)) {
emit OnInvest(msg.sender, msg.value);
}
}
以下是我在Next.js中为不接受参数的提取函数编写的工作代码:
async function executeWithdraw() {
if (typeof window.ethereum !== "undefined") {
const contractAddress = "paste contract address here";
const abi = [ paste abi here ];
const contract = new ethers.Contract(contractAddress, abi, signer);
try {
await contract.withdraw();
} catch (error) {
console.log(error);
}
} else {
console.log("Please install MetaMask");
}
}
发布于 2022-03-23 20:52:27
更新:我拿到了!
const transaction = await contract.deposit(address, { value: ethers.utils.parseEther("0.1") })
//发送0.1ETH等待transaction.wait()
https://ethereum.stackexchange.com/questions/124543
复制相似问题