可更改应付金额
Payable amount can be changed
快速向您提问。是否可以从智能合约中隐藏“应付金额”?因为人们可以从智能合约中铸造并设置他们想要的任何值。从 Polygonscan 添加的屏幕截图。任何人都可以输入任何数量,这将允许铸币。
提前致谢!
[1]: https://i.stack.imgur.com/wQ8J4.png
function mint(uint256 _mintAmount) public payable {
require(!paused, "the contract is paused");
uint256 supply = totalSupply();
require(_mintAmount > 0, "need to mint at least 1 NFT");
require(_mintAmount <= maxMintAmount, "max mint amount per session exceeded");
require(supply + _mintAmount <= maxSupply, "max NFT limit exceeded");
if (msg.sender != owner()) {
if(onlyWhitelisted == true) {
require(isWhitelisted(msg.sender), "user is not whitelisted");
uint256 ownerMintedCount = addressMintedBalance[msg.sender];
require(ownerMintedCount + _mintAmount <= nftPerAddressLimit, "max NFT per address exceeded");
}
require(msg.value >= cost * _mintAmount, "insufficient funds");
}
for (uint256 i = 1; i <= _mintAmount; i++) {
addressMintedBalance[msg.sender]++;
_safeMint(msg.sender, supply + i);
}
}
Polygonscan 和其他区块链浏览器显示带有 payable
修饰符的所有 Solidity 函数的 payableAmount
字段。
但是,您可以验证合约中收到的值并在该值意外时恢复交易。
function mint() public payable {
require(msg.value == 1e18);
}
注意:msg.value
是一个read-only全局变量,返回收到的金额wei。所以“1e18 wei”是“1 MATIC”(在 Polygon 上)。
快速向您提问。是否可以从智能合约中隐藏“应付金额”?因为人们可以从智能合约中铸造并设置他们想要的任何值。从 Polygonscan 添加的屏幕截图。任何人都可以输入任何数量,这将允许铸币。
提前致谢! [1]: https://i.stack.imgur.com/wQ8J4.png
function mint(uint256 _mintAmount) public payable {
require(!paused, "the contract is paused");
uint256 supply = totalSupply();
require(_mintAmount > 0, "need to mint at least 1 NFT");
require(_mintAmount <= maxMintAmount, "max mint amount per session exceeded");
require(supply + _mintAmount <= maxSupply, "max NFT limit exceeded");
if (msg.sender != owner()) {
if(onlyWhitelisted == true) {
require(isWhitelisted(msg.sender), "user is not whitelisted");
uint256 ownerMintedCount = addressMintedBalance[msg.sender];
require(ownerMintedCount + _mintAmount <= nftPerAddressLimit, "max NFT per address exceeded");
}
require(msg.value >= cost * _mintAmount, "insufficient funds");
}
for (uint256 i = 1; i <= _mintAmount; i++) {
addressMintedBalance[msg.sender]++;
_safeMint(msg.sender, supply + i);
}
}
Polygonscan 和其他区块链浏览器显示带有 payable
修饰符的所有 Solidity 函数的 payableAmount
字段。
但是,您可以验证合约中收到的值并在该值意外时恢复交易。
function mint() public payable {
require(msg.value == 1e18);
}
注意:msg.value
是一个read-only全局变量,返回收到的金额wei。所以“1e18 wei”是“1 MATIC”(在 Polygon 上)。