尽管使用了receive()函数,但我的合同在Remix中没有收到付款



我正在用solid编写Remix智能合约。该合约的目的是允许用户以1 ETH的价格铸造NFT。目前,用户能够铸币,合同接受付款(即。用户的余额被适当地减去)。但是当我用accountBalance()函数检查合约的address(this).balance时,函数返回0。我已经按照Solidity文档包含了receive()函数:

event Received(address, uint);
receive() external payable {
emit Received(msg.sender, msg.value);
}
谁能解释一下为什么会发生这种情况,我需要修改我的合同吗?这是我的合同:
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.4;
// imports
import '@openzeppelin/contracts/token/ERC721/ERC721.sol';
import '@openzeppelin/contracts/access/Ownable.sol';
import '@openzeppelin/contracts/security/PullPayment.sol';
// contract
contract RobocopPoster is ERC721, Ownable, PullPayment {
// constants
uint256 public mintPrice;
uint256 public totalSupply;
uint256 public maxSupply;
uint256 public maxPerWallet;
bool public mintEnabled;
mapping (address => uint256) public walletMints;
// constructor
// initialize variables
constructor() payable ERC721('RobocopPoster', 'SFFPC') {
mintPrice = 1 ether;
totalSupply = 0;
maxSupply = 1000;
maxPerWallet = 3;
}
event Received(address, uint);
receive() external payable {
emit Received(msg.sender, msg.value);
}
// functions
function setMintEnabled(bool mintEnabled_) external onlyOwner {
mintEnabled = mintEnabled_;
}
function withdrawPayments(address payable payee) public override onlyOwner virtual {
super.withdrawPayments(payee);
}
function accountBalance() public view returns (uint256) {
return (address(this).balance);
}
function mint(uint256 quantity_) public payable {
require(mintEnabled, 'Minting not enabled.');
require(msg.value == quantity_ * mintPrice, 'wrong mint value');
require(totalSupply + quantity_ <= maxSupply, 'sold out');
require(walletMints[msg.sender] + quantity_ <= maxPerWallet, 'exceed max wallet');
walletMints[msg.sender] += quantity_;
_asyncTransfer(address(this), msg.value);
for (uint i = 0; i < quantity_; i++) {
uint256 newTokenId = totalSupply + 1;
totalSupply++;
_safeMint(msg.sender, newTokenId);
}
}
}

您需要调用withdrawPayments来接收资金,因为在您的合约挖矿中,来自PullPayment的_asyncTransfer将资金发送到托管合同。这就是为什么你在ERC721合约中看到零余额。

相关内容

  • 没有找到相关文章

最新更新