Smart Contract Examples
Specific examples and general principles for integrating DelegateRegistry into your Solidity smart contract
/**
* @notice For example, bored ape holders minting their mutant apes
* @param originalTokenIds The ids of tokens being used to mint something new
*/
function tokengatedMint(uint256[] calldata originalTokenIds) external {
for (uint256 i = 0; i < originalTokenIds.length; ++i) {
uint256 tokenId = originalTokenIds[i];
address tokenOwner = ORIGINAL_CONTRACT.ownerOf(tokenId);
// Mint if tokenOwner is msg.sender or tokenOwner delegated to msg.sender
if (msg.sender == tokenOwner ||
IDelegateRegistry(DELEGATE_REGISTRY).checkDelegateForERC721(
msg.sender,
tokenOwner,
address(ORIGINAL_CONTRACT),
tokenId,
""
)
) {
// Can mint to either the vaulted wallet or msg.sender, project's choice
// Can also use an `address recipient` function parameter for flexibility
_mint(tokenOwner, tokenId);
}
}
}General Principles
(line 1) Passing an optional _cold address variable into the contraction.
_cold address variable into the contraction.(line 2) Using a new requester variable
requester variable(line 4-8) Checking the DelegateRegistry for the valid pairings
Last updated