简体   繁体   中英

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

All i need is to understand what to do to enable 50 airdrops to be done but only from my wallet address.

(Just need to make sure no one else can go to 'write contract' on etherscan and send an airdrop)

You can add a condition verifying that the msg.sender is your address. I see that you're already using the ownable pattern (probably the OpenZeppelin implementation), so you can use this.

When you deployed the contract, the constructor assigned your address to the _owner variable. There's also the onlyOwner() modifier that throws an exception (effectively reverting the transaction) if the transaction was not sent from the _owner address.

So you can update your airdrop() function to use the onlyOwner() modifier.

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) .

If you execute the function from any other address, it will revert.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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