在 Remix Injected Web 3 环境中避免在智能合约中输入以太值

Avoiding entering value of ether in smart contract in Remix Injected Web 3 environment

我正在编写一个智能合约,以便 metamask 钱包可以将一定价值的 eth 发送到智能合约。然而,我每次测试智能合约时,都必须手动输入一个整数。有什么办法可以解决这个问题吗?

不,发送 eth 它不是 tx 数据的一部分,但它在 tx 详细信息中,如果你 运行 直接在 IDE REMIX 或 etherscan 上运行,你必须插入它手动

无论如何,如果您打算使用 web3js 为您的合约创建一个界面,您可以在发送 tx 之前手动添加 tx 详细信息:

const transaction = {
 'to': '0x31B98D14007bDEe637298086988A0bBd31184523', //contract address 
 'value': 1, //1 eth
 'gas': 30000,
 'maxFeePerGas': 1000000108,
 'nonce': nonce,
};

所以用户不需要手动编写