opensea-creatures
opensea-creatures copied to clipboard
What does the `fireTransferEvents` function do?
Hi
I was exploring the contracts and came to the CreatureFactory
contract which in its constructor
the fireTransferEvents
function is called. This function emits Transfer
events n times which n is equal to number of minting options. I couldn't understand:
- Why the
Transfer
event is emitted inconstructor
when no token is minted yet? - Why the
Transfer
event is emitted n times? What is the relevance ofNUM_OPTIONS
here?
The codes:
constructor(address _proxyRegistryAddress, address _nftAddress) {
proxyRegistryAddress = _proxyRegistryAddress;
nftAddress = _nftAddress;
lootBoxNftAddress = address(
new CreatureLootBox(_proxyRegistryAddress, address(this))
);
fireTransferEvents(address(0), owner());
}
...
function fireTransferEvents(address _from, address _to) private {
for (uint256 i = 0; i < NUM_OPTIONS; i++) {
emit Transfer(_from, _to, i);
}
}
Hi @dfinzer @rheaplex @alexanderatallah @TheMaxKim @DJViau @joshuawu @Beasta @Lynaj , Would you please help us with this question as we are working with this repo, we would appreciate your input on this matter.
Thank you all in advance
Hi I was exploring the contracts and came to the
CreatureFactory
contract which in itsconstructor
thefireTransferEvents
function is called. This function emitsTransfer
events n times which n is equal to number of minting options. I couldn't understand:
- Why the
Transfer
event is emitted inconstructor
when no token is minted yet?- Why the
Transfer
event is emitted n times? What is the relevance ofNUM_OPTIONS
here? The codes:constructor(address _proxyRegistryAddress, address _nftAddress) { proxyRegistryAddress = _proxyRegistryAddress; nftAddress = _nftAddress; lootBoxNftAddress = address( new CreatureLootBox(_proxyRegistryAddress, address(this)) ); fireTransferEvents(address(0), owner()); } ... function fireTransferEvents(address _from, address _to) private { for (uint256 i = 0; i < NUM_OPTIONS; i++) { emit Transfer(_from, _to, i); } }
- as I know emit
Transfer
event is called to mint factory item to address 0 and transfer from address 0 to you - factory will mint factory item (on this repo is lootbox) for owner after deployed total as NUM_OPTIONS
@samanshahmohamadi Basically using fire events you are emitting events for your interaction with the blockchain and you can listen to that specific event on your front end and can change data accordingly or can show data dynamically.
2. factory will mint factory item (on this repo is lootbox) for owner after deployed total as NUM_OPTIONS
could you please clarify what do you mean? Does the factory contract need to be deployed NUM_OPTIONS times? or?
In the factory contract of OpenSea (CreaturesFactory.sol) there are three options
0: Mint one random NFT 1: Mint NUM_NFTS_IN_MULTIPLE_NFT_OPTION random NFTs 2: Mint one LootBox
For options 0 and 1 the NFT contract Creature is called for each NFT to be minted
For option 2 the lootbox NFT contract CreatureLootBox is called for creating a lootbox NFT (the lootbox NFT represents the right to mint 3 random NFTs)
If you display the factory contract in OpenSea you do not see any NFTs but only these three options. And the contract creator ist the owner of these three options. From OpenSea the three options are handled like NFTs in the real NFT contracts, but there are no NFTs minted for the three options.
For what the event for each option is needed I don't know. Maybe OpenSea uses them? Can somebody answer this question? I would appreciate a answer