触发事件后,metamask 提示,转账不能成功,但在remix和etherscan均能正常执行。请问如何解决?
This transaction is expected to fail. Trying to execute it is expected to be expensive but fail, and is not recommended.
React代码
async function payWithMetamask() {
let ethereum = window.ethereum;
// Request account access if needed
await ethereum.enable();
let provider = new ethers.providers.Web3Provider(ethereum);
// Acccounts now exposed
const tx = [{
from: walletAddress,
to: contractAddress,
value: ethers.utils.parseUnits('1000000', 'gwei').toHexString(),
}];
const transactionHash = await provider.send('eth_sendTransaction', tx)
console.log('transactionHash is ' + transactionHash);
}
合约代码
function buy() public payable{
uint256 amount = msg.value;
address buyer = msg.sender;
require(amount > 1000, 'money not enjoy.');
acl.push(buyer);
}