SFS - Registering a contract with Remix
How to register a smart contract on Mode’s SFS register contract.
Last updated
Was this helpful?
How to register a smart contract on Mode’s SFS register contract.
Last updated
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.
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.
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.
For this tutorial, we will be using Remix to deploy and interact with the contracts, but you can deploy with any tools you prefer.
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.
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 👋