我们正在编写一些合约来使用以太坊上的帐户抽象(ERC-4337)功能。特别是,我们正在编写一份合同,该合同将兼作账户工厂和付款人。这是与我的问题相关的重要部分
contract AccountFactory is IPaymaster, Ownable
{
address private Entrypoint;
constructor(address _entrypoint)
{
Entrypoint = _entrypoint;
}
receive() external payable {}
fallback() external payable {}
}
由于合约也将成为付款人,并在必要时向入口点添加权益,因此它需要能够持有 ETH,这就是我们添加接收和后备功能的原因。
问题是将 ETH 转入合约失败。
我们正在使用 Nethereum 和以下内容:
var transaction = await web3.Eth.GetEtherTransferService()
.TransferEtherAndWaitForReceiptAsync(address, value);
所以,它确实是最基本的。
这适用于 EOA 地址,但一旦我们传递 AccountFactory 合约的部署地址,它就会失败。奇怪的是,原木花只是 0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 0000000000000000
有什么想法为什么合约无法收到转账吗?
确保您可以使用 Metamask 之类的工具将 ETH 发送到合约(我认为它可以查看您的合约)。如果这可以正常工作,请尝试这个(我知道这对我来说对于类似的合同来说效果很好)
var account = new Account(pk);
var client = new Web3(account, endpointAddress, null, null);
var transferHandler = client.Eth.GetEtherTransferService();
var gas = await transferHandler.EstimateGasAsync(toAddress, amount);
var transactionInput = new TransactionInput()
{
From = fromAddress,
Gas = new HexBigInteger(gas),
To = toAddress,
Value = new HexBigInteger(Web3.Convert.ToWei(amount)),
GasPrice = new HexBigInteger(new BigInteger(1000000000) * new BigInteger(gasPrice)),
};
var txHash = await client.Eth.TransactionManager.SendTransactionAsync(transactionInput);