0

I am trying to distribute ERC-1155 NFT copies (not the token ID 1 but the copies of token ID 1) to multiple wallets. I am calling the _safeTransferFrom in a for loop. Would it cost gas in each for loop or only once since I am calling it within another function in a single transaction? The code is below. The _safeTransferFrom is here

  function distributeNFTs(
    address _from,
    address[] calldata _recipients,
    uint256 _tokenId
  ) external {
    require(_from == _msgSender() || isApprovedForAll(_from, _msgSender()), "CryptoStamp: caller is not owner nor approved");
    for (uint256 i = 0; i < _recipients.length; i++) {
      _safeTransferFrom(_from, _recipients[i], _tokenId, 1, "");
    }
  }
1
  • Every action costs something. Try it in remix. Feb 12, 2022 at 11:11

1 Answer 1

0

You can understand gas as a quantity of computational units. The more complex the method you are going to execute, the more gas you will spend. However, between calling the method once with multiple transfers, than calling the same method many times, it is better to call the method only once. Either way, you can use Remix to see how much gas your method will require.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.