Skip to content

Instantly share code, notes, and snippets.

@dievardump
Last active March 1, 2023 14:08
Show Gist options
  • Select an option

  • Save dievardump/9b66434912d88020708ab388f73c2eb4 to your computer and use it in GitHub Desktop.

Select an option

Save dievardump/9b66434912d88020708ab388f73c2eb4 to your computer and use it in GitHub Desktop.

Revisions

  1. dievardump revised this gist Mar 1, 2023. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions Efficient721Airdrop.sol
    Original file line number Diff line number Diff line change
    @@ -13,12 +13,12 @@ contract ERC721 {
    address to;

    for (uint256 i; i < length;) {
    tokenId++
    to = recipients[i];
    to = recipients[i];
    unchecked {
    // _airdrop should only be used at the very start of the contract
    // so to should not have any balance
    _balances[to] = 1;
    ++tokenId;
    ++i;
    }

  2. dievardump revised this gist Mar 1, 2023. 1 changed file with 2 additions and 1 deletion.
    3 changes: 2 additions & 1 deletion Efficient721Airdrop.sol
    Original file line number Diff line number Diff line change
    @@ -12,13 +12,14 @@ contract ERC721 {
    uint256 tokenId = _lastTokenId;
    address to;

    for (uint256 i; i < length; i++) {
    for (uint256 i; i < length;) {
    tokenId++
    to = recipients[i];
    unchecked {
    // _airdrop should only be used at the very start of the contract
    // so to should not have any balance
    _balances[to] = 1;
    ++i;
    }

    _owners[tokenId] = to;
  3. dievardump revised this gist Mar 1, 2023. 1 changed file with 5 additions and 0 deletions.
    5 changes: 5 additions & 0 deletions Efficient721Airdrop.sol
    Original file line number Diff line number Diff line change
    @@ -2,6 +2,9 @@ contract ERC721 {
    // take OpenZeppelin contract and add this at the end:

    uint256 private _lastTokenId;

    // uncomment next line if you need totalSupply
    // uint256 public totalSupply;

    /// @dev be careful this function expects recipients to all be unique and not be address(0)
    function _airdrop(address[] calldata recipients) internal virtual {
    @@ -23,5 +26,7 @@ contract ERC721 {
    }

    _lastTokenId = tokenId;
    // uncomment next line if you need totalSupply
    // totalSupply += length;
    }
    }
  4. dievardump revised this gist Mar 1, 2023. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion Efficient721Airdrop.sol
    Original file line number Diff line number Diff line change
    @@ -1,7 +1,7 @@
    contract ERC721 {
    // take OpenZeppelin contract and add this at the end:

    uint256 _lastTokenId;
    uint256 private _lastTokenId;

    /// @dev be careful this function expects recipients to all be unique and not be address(0)
    function _airdrop(address[] calldata recipients) internal virtual {
  5. dievardump revised this gist Mar 1, 2023. 1 changed file with 0 additions and 1 deletion.
    1 change: 0 additions & 1 deletion Efficient721Airdrop.sol
    Original file line number Diff line number Diff line change
    @@ -20,7 +20,6 @@ contract ERC721 {

    _owners[tokenId] = to;
    emit Transfer(address(0), to, tokenId);
    ;
    }

    _lastTokenId = tokenId;
  6. dievardump revised this gist Mar 1, 2023. No changes.
  7. dievardump revised this gist Mar 1, 2023. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion Efficient721Airdrop.sol
    Original file line number Diff line number Diff line change
    @@ -10,7 +10,7 @@ contract ERC721 {
    address to;

    for (uint256 i; i < length; i++) {
    tokenId++
    tokenId++
    to = recipients[i];
    unchecked {
    // _airdrop should only be used at the very start of the contract
  8. dievardump created this gist Mar 1, 2023.
    28 changes: 28 additions & 0 deletions Efficient721Airdrop.sol
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,28 @@
    contract ERC721 {
    // take OpenZeppelin contract and add this at the end:

    uint256 _lastTokenId;

    /// @dev be careful this function expects recipients to all be unique and not be address(0)
    function _airdrop(address[] calldata recipients) internal virtual {
    uint256 length = recipients.length;
    uint256 tokenId = _lastTokenId;
    address to;

    for (uint256 i; i < length; i++) {
    tokenId++
    to = recipients[i];
    unchecked {
    // _airdrop should only be used at the very start of the contract
    // so to should not have any balance
    _balances[to] = 1;
    }

    _owners[tokenId] = to;
    emit Transfer(address(0), to, tokenId);
    ;
    }

    _lastTokenId = tokenId;
    }
    }