在Remix Injected Web 3环境下,使用以下代码来防止输入以太币值到智能合约中:
pragma solidity ^0.6.0;
contract NoEther {
receive() external payable {
revert("Ether is not accepted");
}
}
上述代码中,receive()
函数用于接收以太币,我们在函数中通过revert()
函数指定输入以太币时的错误提示信息。这样一来,在Remix Injected Web 3环境下,当用户尝试输入以太币时,智能合约会抛出错误,禁止用户向合约中发送以太币。