1

If suppose there is a main contract A that is linked to an external library L, would it be safe to move all the fund transfer and NFT transfer calls from the main contract into the library to reduce the size of contract A. The sendFundsAndToken function is made nonReentrant.

contract without using a library:

contract A{
 function sendFundsAndToken(address collectionAddress, uint256 tokenId) external nonReentrant{
  payable(msg.sender).call{ value: 1 ether }("");
  ERC721(collectionAddress).safeTransferFrom(address(this), msg.sender, tokenId);
 }
}

contract using a library:

contract A{
 function sendFundsAndToken(address collectionAddress, uint256 tokenId) external nonReentrant{
  L.executeSend(collectionAddress, tokenId);
 }
}

library L{
 function executeSend(address collectionAddress, uint256 tokenId) external{
  payable(msg.sender).call{ value: 1 ether }("");
  ERC721(collectionAddress).safeTransferFrom(address(this), msg.sender, tokenId);
 }
}

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy