我在goerli
测试网上部署了一个合同,但我不明白为什么在创建nft后合同余额没有增加。
goerli合同:https://goerli.etherscan.io/address/0x41c13FF48Edc715612763394Ac8D36C4d11b5856
成功的薄荷交易:https://goerli.etherscan.io/tx/0x4a0248639a427b2a824433dce5712d1d86bf85d8a7658d0215aff8cdc9448ea9
uint256 public constant TOTAL_SUPPLY = 100;
uint256 public constant MINT_PRICE = 0.02 ether;
uint256 public constant MAX_PUBLIC_MINT = 10;
function mintTo(address recipient, uint256 count) public payable {
uint256 tokenId = currentTokenId.current();
require(tokenId < TOTAL_SUPPLY, "Max supply reached");
require(
count > 0 && count <= MAX_PUBLIC_MINT,
"Max mint supply reached"
);
require(
msg.value == MINT_PRICE * count,
"Transaction value did not equal the mint price"
);
for (uint256 i = 0; i < count; i++) {
currentTokenId.increment();
uint256 newItemId = currentTokenId.current();
_safeMint(recipient, newItemId);
}
bool success = false;
(success, ) = owner().call{value: msg.value}("");
require(success, "Failed to send to owner");
}
我试着用安全帽铸造:
task("mint", "Mints from the NFT contract")
.addParam("address", "The address to receive a token")
.setAction(async function (taskArguments, hre) {
const contract = await getContract("NftGame", hre);
const transactionResponse = await contract.mintTo(taskArguments.address, 1, {
gasLimit: 500_000,
value: ethers.utils.parseEther(String(0.02 * 1))
});
console.log(`Transaction Hash: ${transactionResponse.hash}`);
});
应该增加什么余额?给我们看整个合同。
- 如果您的意思是铸造到某个地址的NFT的余额,请检查
balanceOf(address)
方法 - 但我认为;铸造nft后合同余额不会增加;您的意思是,调用
mintTo
后,合同的以太余额不会增加。这背后的原因可以在(success, ) = owner().call{value: msg.value}("");
行中找到。调用mintTo
时带有tx的以太发送被发送给合同的所有者。因此,合同的以太余额没有增加,但合同所有者的以太余额应增加msg.value
。看看你提供的tx,上面写着"传输0。02以太从0x41c13ff48edc715612763394ac8d36c4d11b5856到0x6c3455607f5592612e9e3754ba37c63123d68722";其中0x41c13ff48edc715612763394ac8d36c4d11b5856
是合同的地址,0x6c3455607f5592612e9e3754ba37c63123d68722
是合同所有者的地址