Skip to main content

Integrate Delegate.xyz into smart contract

Overview

This guide explains how to integrate Delegate.xyz into your smart contract.

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)
}

Delegate registry contract

The Delegate registry contract is a standalone immutable registry that stores delegated permissions from one address to another. It allows users to delegate permissions for their entire wallet, specific contracts, ERC-721 tokens, ERC-20 tokens, and ERC-1155 tokens. The contract provides a set of functions to delegate and revoke permissions, as well as to check the permissions granted to a delegate.

Contract address

Delegate registry contract address is the same on both the Ronin mainnet and Saigon testnet.

NetworkAddress
Ronin mainnet0x00000000000000447e69651d841bd8d104bed493
Saigon testnet0x00000000000000447e69651d841bd8d104bed493

Contract interface

See IDelegateRegistry.sol.

Example

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.

This example shows how to integrate Delegate.xyz into a Solidity contract for handling delegations when claiming NFTs.

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");

// Ensuring 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 their own behalf

// Additional validation checks (not implemented)
// 1. Check if `requester` is allowed to claim
// 2. Check if `requester` has already claimed

// Claim logic using `requester`
_claim(`requester`)
}

See also

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