Skip to main content

Integrate Delegate.xyz into smart contract

Overview

This guide explains how to integrate the DelegateRegistry into a Solidity smart contract.

General principle

Typically, a mint or claim function looks like this:

function claim() public returns (uint256 tokenId) {
// 1. Check if `msg.sender` is allowed to claim
// Use merkle tree, for example

// 2. Check if `msg.sender` has already claimed

// 3. Your claim code below using `msg.sender`
_claim(msg.sender)
}

To integrate Delegate.xyz into your Solidity contract, add a small code block to the preceding step, and pass an optional _vault address into the claim function.

address constant public NFT_CONTRACT = 0x0000000000000000000000000000000000000001;

function claim(address _vault) public returns (uint256 tokenId) {
address requester = msg.sender;

// Check if `msg.sender` is a permitted delegate of the `_vault` address
if (_vault != address(0) && _vault != requester) {
bool isDelegateValid = REGISTRY.checkDelegateForContract(msg.sender, _vault, NFT_CONTRACT, "");
require(isDelegateValid, "delegation does not exist");

// With the below line, we're making sure the NFT will be minted to the `_vault` address
// By removing this line, contract engineers can also decide
// to mint the NFT to the delegate `msg.sender`
requester = _vault;
}
// If `_vault` address equals 0x0 or is the same address as `requester`
// Then ignore the block above, as `requester` is minting on his own behalf

// 1. Check if `requester` is allowed to claim
// Maybe using merkle tree, etc

// 2. Check if `requester` has already claimed

// 3. Your claim code below using `requester`
_claim(`requester`)
}

See also

For more examples, see the official Delegate.xyz documentation.

Was this helpful?
Happy React is loading...