🏫Registering a contract with Remix

Let's register using remix

This tutorial will teach you about the SFS (Sequencer Fee Sharing) contract and how to register a newly deployed contract.

Introducing SFS (Sequencer Fee Sharing)

Developers can earn a portion of the network sequencer fees by registering their contracts with the Fee Sharing Contract, deployed at 0x1c2B979174310B071A88Aa06b0563571D637AAF7 on the Camp Network testnet. Transaction fees from all interactions involving their smart contracts will accumulate in this Fee Sharing Contract.

To register a contract, the registry contract issues an NFT to the specified recipient during the registration process. This NFT represents the claim to the earned fees. Therefore, your smart contract must call the SFS contract to register. The NFT is transferable and can be used to claim fees from multiple contracts.

An off-chain component processes transactions for each registered smart contract to calculate its share of the fees and distributes them accordingly. Note that there may be a lockup period of up to two weeks for withdrawing distributed funds. You can view the SFS contract code here. If you are familiar with Solidity, we recommend reviewing the "register" function, which we will cover later in this tutorial.

Now that we know what the SFS registry is, let’s register a sample smart contract to start earning fees.

SFS register function review

Let’s examine the SFS contract, focusing on the register function. There are two key points to note about this function. First, the parameter it receives (address _recipient) specifies the address that will receive the earned fees. Second, the SFS contract determines which smart contract is being registered by checking the msg.sender. This is why the register function must be called from the contract you want to register. Note that each contract can only be registered once.

    /// @notice Mints ownership NFT that allows the owner to collect fees earned by the smart contract.
    ///         `msg.sender` is assumed to be a smart contract that earns fees. Only smart contract itself
    ///         can register a fee receipient.
    /// @param _recipient recipient of the ownership NFT
    /// @return tokenId of the ownership NFT that collects fees
    function register(address _recipient) public onlyUnregistered returns (uint256 tokenId) {
        address smartContract = msg.sender;

        if (_recipient == address(0)) revert InvalidRecipient();

        tokenId = _tokenIdTracker.current();
        _mint(_recipient, tokenId);
        _tokenIdTracker.increment();

        emit Register(smartContract, _recipient, tokenId);

        feeRecipient[smartContract] = NftData({
            tokenId: tokenId,
            registered: true,
            balanceUpdatedBlock: block.number
        });
    }

For this tutorial, we will be using Remix to deploy and interact with the contracts, but you can deploy with any tools you prefer.

Sample smart contract

This is a basic ERC-20 token using the OpenZepellin contract. In the example code snippet below, you will find a Register contract with the signature of the register function following the SFS contract.

We will be using the testnet SFS address.

To register your smart contract in the SFS, it is essential to include a call to the register function within your smart contract. This call must be executed from your contract.

// SPDX-License-Identifier: GPL-3.0

pragma solidity ^0.8.20;

import "https://github.com/OpenZeppelin/openzeppelin-contracts/blob/v5.0.0/contracts/token/ERC20/ERC20.sol";


interface ISFS {
    function register(address _recipient) external returns (uint256 tokenId);
}

contract SampleToken is ERC20 {

    address feeReceiver = msg.sender;
    
    constructor() ERC20("SampleToken", "SMPL") {
        _mint(msg.sender, 1000 * 10 ** 18); //Example amount to mint our ERC20
        feeReceiver = msg.sender; //The deployer of the contract will get the NFTto widthraw the earned fees
        ISFS sfsContract = ISFS(0x1c2B979174310B071A88Aa06b0563571D637AAF7); // This address is the address of the SFS contract
        sfsContract.register(msg.sender); //Registers this contract and assigns the NFT to the owner of this contract
    }
}

In this scenario, our constructor() initializes an instance of the Register contract using the SFS contract address provided as an argument and then calls the register function in the SFS contract, passing msg.sender as the parameter.

That's all we need to add to our smart contract for registration! The contract will register itself upon deployment, so let's proceed with that.

Deploying and registering the contract

We will be using Remix for this process. Navigate to the deploy tab and select “Injected Provider - Metamask” to connect Metamask and deploy your contract.

When using Remix, ensure you are connected to the correct network. In this case, we are using Camp's testnet, but the same process applies for the Mainnet.

After deploying and confirming the transaction in Metamask, your contract should be registered, and your wallet should receive the SFS NFT. This NFT enables you to claim your rewards.

Last updated