Mode Docs
  • Introduction
    • 🟡Introducing Mode
    • ✅AI Agent Dev Roadmap
  • AI AGENTS
    • Mode AI Terminal
    • 🤷What are AI Agents?
    • 🏗️Building your first agent
    • Tutorials
      • Quickstart
    • 🛠️AI Tooling
      • AI Audits
      • AI APIs
      • Frameworks
  • Tools
    • 🖥️RPC
    • 🪶Multisig wallets
    • 🔁Bridge
    • 🚰Testnet Faucets
    • 🕵️Block Explorers
    • 🗂️Data Indexers
    • 🧙‍♂️Oracles
    • ⛓️Interoperability
    • ⁉️Randomness
    • 🌎General Tooling
  • Tutorials
    • Interacting with Smart Contracts using ethers.js
    • Deploying a Smart Contract
      • Using Hardhat
      • Using Thirdweb
      • Using Foundry
      • Using Remix
    • Verifying your smart contract
      • Using Hardhat
      • Using Foundry
  • User Guides
    • ℹ️Network Details
    • 🦊Add Mode
    • 🏡Contract Addresses
      • Tokens
      • L1/L2 Mainnet Contracts
      • Testnet Contracts
    • 🌉Bridge
      • ➡️Bridge to Mode
      • ⬅️Bridge from Mode
      • 🏗️Bridging to Testnet
    • 📤Move to/from CEX
  • $MODE
    • 🟡MODE Tokenonomics
    • 1️⃣Season 1 (ended)
    • 2️⃣Season 2 (ended)
    • 3️⃣Governance Season 3 (ended)
      • Governance Contract Addresses
    • 4️⃣Mode Governance Season 4
    • 5️⃣Season 5
  • Other Docs
    • 🔓General Security
      • 🔓Mode L2 Security Model
      • ⛑️Optimism Bug Bounty
      • Security Upgrades
        • 01/08/2024 Bridge Upgrade Fund Rescue
        • 06/08/2024 Mode Mainnet Key Handover
      • 🔐Audits
    • 🔗Official Links
    • 🤘Branding Guidelines
    • ⌨️Node Operators
Powered by GitBook
On this page
  • Introducing SFS (Sequencer Fee Sharing)
  • SFS register function review
  • Sample smart contract
  • Deploying and registering the contract

Was this helpful?

Edit on GitHub
  1. Tutorials
  2. SFS - Sequencer Fee Sharing
  3. Register a Smart Contract

SFS - Registering a contract with Remix

How to register a smart contract on Mode’s SFS register contract.

Last updated 1 year ago

Was this helpful?

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

if you want to go straight to the code examples go to Sample smart contract.

Introducing SFS (Sequencer Fee Sharing)

Developers can earn a share of the network Sequencer fees by registering their contracts in the Fee Sharing Contract (based on Canto's Turnstile.sol) deployed at on Mode testnet. A portion of transaction fees of all transactions involving their smart contract will accumulate in the Fee Sharing Contract.

When registering your contract, the registry contract issues an NFT as a claim to the earned fees by the recipient specified in the call to register the smart contract. This means your smart contract needs to make the call to the SFS contract in order to register. The minted NFT is transferable and can be used to claim fees for multiple contracts.

An offchain component will process the transactions for each smart contract to calculate it's share of fees. This component will also distribute the fees to registered smart contracts in the SFS contract. Note that there may be a lockup period on withdrawal of distributed funds for up to 2 weeks. You can see the code of the SFS contract . If you are a little bit familiar solidity, we would recommend you to take a look at the “register” function. We'll go over it 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 take a quick look at the SFS contract. More specifically, the register function. There are 2 interesting things to note from this function. The first one is that the parameter the function receives (address _recipient) is the address of the recipient of the earned fees. The second one is that, to know what smart contract is being registered, the SFS contract looks at the msg.sender. This is why you need to call this register function from the contract you want to register. You can only register your contract 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

IMPORTANT: In order to register your smart contract in the SFS, it’s mandatory to have a call to the register function in your smart contract. This call needs to be made 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 ModeToken is ERC20 {

    address feeReceiver = msg.sender;
    
    constructor() ERC20("ModeTokenSFSTest", "SFST2") {
        _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(0xBBd707815a7F7eb6897C7686274AFabd7B579Ff6); // 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 case, our constructor() creates an instance of the Register contract using the SFS contract address passed as an argument and then calls the register function in the SFS contract, passing the msg.sender as parameter.

That’s all we need to add to our smart contract to register it! The contract will register itself on deployment, so let's go do that.

Deploying and registering the contract

We will be using Remix, so we'll go to the deploy tab and use the “Injected Provider - Metamask” to connect Metamask and deploy our contract. Please make sure in the compiler’s tab that the EVM version is set to london or else you'll get a PUSH0 error message.

With Remix, is important that you pay attention to which network you are connected. In this case we are using Mode's testnet but the same process applies for Mainnet.

After deploying and confirming the transaction in Metamask that’s it! If the transaction was successful, your contract should be registered and your wallet should have the SFS NFT minted. This NFT is the one that allows you to claim your rewards.

This is a basic token using the 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 tesnet SFS address, but if you want to register a contract on Mainnet, you should change the address on line 19. Mainnet SFS Address: Testnet SFS Address:

To validate if the registration was done correctly check our Check the SFS registry tutorial. To learn more about Mode and how to turn your code into a business, join our and say hello 👋

0xBBd707815a7F7eb6897C7686274AFabd7B579Ff6
here
ERC-20
OpenZepellin
0x8680CEaBcb9b56913c519c069Add6Bc3494B7020
0xBBd707815a7F7eb6897C7686274AFabd7B579Ff6
Discord