简体   繁体   English

如何只允许智能合约 erc-721 空投来自一个地址

[英]How to only allow smart contract erc-721 airdrops to be from one address

Here is my testnet contract: https://rinkeby.etherscan.io/address/0xa63a032185452a2ab7da24a26ca9342e78e799a7这是我的测试网合约: https ://rinkeby.etherscan.io/address/0xa63a032185452a2ab7da24a26ca9342e78e799a7

All i need is to understand what to do to enable 50 airdrops to be done but only from my wallet address.我所需要的只是了解如何才能完成 50 次空投,但仅限于我的钱包地址。

(Just need to make sure no one else can go to 'write contract' on etherscan and send an airdrop) (只需要确保没有其他人可以在etherscan上“写合同”并发送空投)

You can add a condition verifying that the msg.sender is your address.您可以添加一个条件来验证msg.sender是您的地址。 I see that you're already using the ownable pattern (probably the OpenZeppelin implementation), so you can use this.我看到您已经在使用ownable模式(可能是 OpenZeppelin 实现),因此您可以使用它。

When you deployed the contract, the constructor assigned your address to the _owner variable.当您部署合约时,构造函数将您的地址分配给_owner变量。 There's also the onlyOwner() modifier that throws an exception (effectively reverting the transaction) if the transaction was not sent from the _owner address.如果交易不是从_owner地址发送的,还有一个onlyOwner()修饰符会抛出异常(有效地恢复交易)。

So you can update your airdrop() function to use the onlyOwner() modifier.所以,你可以更新您的airdrop()函数使用onlyOwner()修改。

function airdrop(bytes memory code) public onlyOwner() {

Then you'll be able to execute the airdrop() function only from the address that deployed the token (or became a new owner through the transferOwnership() function) .然后,您将只能从部署令牌的地址(或通过transferOwnership()函数成为新所有者airdrop()执行airdrop()函数。

If you execute the function from any other address, it will revert.如果您从任何其他地址执行该函数,它将恢复。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM