Cookie Consent by Free Privacy Policy Generator Update cookies preferences 📌 How to Register a Smart Contract to Mode SFS with Thirdweb

🏠 Team IT Security News

TSecurity.de ist eine Online-Plattform, die sich auf die Bereitstellung von Informationen,alle 15 Minuten neuste Nachrichten, Bildungsressourcen und Dienstleistungen rund um das Thema IT-Sicherheit spezialisiert hat.
Ob es sich um aktuelle Nachrichten, Fachartikel, Blogbeiträge, Webinare, Tutorials, oder Tipps & Tricks handelt, TSecurity.de bietet seinen Nutzern einen umfassenden Überblick über die wichtigsten Aspekte der IT-Sicherheit in einer sich ständig verändernden digitalen Welt.

16.12.2023 - TIP: Wer den Cookie Consent Banner akzeptiert, kann z.B. von Englisch nach Deutsch übersetzen, erst Englisch auswählen dann wieder Deutsch!

Google Android Playstore Download Button für Team IT Security



📚 How to Register a Smart Contract to Mode SFS with Thirdweb


💡 Newskategorie: Programmierung
🔗 Quelle: dev.to

Thirdweb is a web3 platform that provides developers with tools to build, deploy, launch, and manage their applications and games. Some of these tools include pre-built smart contracts, SDKs, and APIs.

In this tutorial, you will learn how to register a smart contract to Mode Network’s SFS (Sequencer Fee Sharing) Contract while deploying with Thirdweb.

Prerequisites

Before you continue with this tutorial you should:

  • Create a thirdweb account.

  • Have a basic understanding of Solidity.

  • Bridge Sepolia Eth with Mode Network.

  • Have Node and Yarn installed with a recent version.

What is Sequencer Fee Sharing (SFS)?

Picture this! When you deploy your smart contract to Mode Network, you will be able to receive a percentage of the transaction fees associated with your smart contract. In other words, you get a share of the transaction fees when transactions are made on your contract, rewarding your contribution to the network and incentivizing further innovation and usage of your smart contract.

But, how does this work?

You must register your contract with Mode Network's Registry/SFS contract. When you register, the Registry contract issues you an NFT as a claim to earned fees. The call to register your contract must come from your contract.

Also, an off-chain component is responsible for processing transactions and calculating your share of fees from each transaction. Your minted NFT allows you to claim your fees accumulated in the SFS contract. One thing to keep in mind is that there would be a two-week time for the fees to accumulate before being transferred to the SFS contract. When this is done you can withdraw your rewards..

How does the SFS Register function work?

We mentioned earlier that the call to register to the SFS needs to come directly from the smart contract you want to register. To understand how this all works, let’s look at the register function.

Note that this is only a portion of the SFS contract, check here to see the complete code.

function register(address _recipient) public onlyUnregistered returns (uint256 tokenId) {
   address smartContract = msg.sender;


// Check if the recipient address is valid; revert if it's null
   if (_recipient == address(0)) revert InvalidRecipient();

// Generate a unique tokenId, mint an NFT to the recipient with it, and update         //the tracker
   tokenId = _tokenIdTracker.current();
   _mint(_recipient, tokenId);
   _tokenIdTracker.increment();


   emit Register(smartContract, _recipient, tokenId);


// Update the fee recipient mapping for the smart contract, associating it with //the tokenId and registration details
   feeRecipient[smartContract] = NftData({
       tokenId: tokenId,
       registered: true,
       balanceUpdatedBlock: block.number
   });
}

This is a function that receives "_recipient" as an input and then mints an NFT to this recipient once your smart contract is registered.

Then, the msg. sender is picked up as the contract to register in the SFS updating the mapping with relevant information.

Here are a few things to note;

  • The Function is specified public meaning an external smart contract can call it.

  • The msg.sender is assumed to be a smart contract address, ensuring that a smart contract can register a fee recipient.

  • The Function mints an ownership NFT that allows the owner to claim fees earned by the recipient smart contract.

The Register Function in Practice

Let's take a look at an example to solidify our understanding;

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
import "@thirdweb-dev/contracts/base/ERC20Vote.sol";


contract Register {
   function register(address _recipient) public returns (uint256 tokenId) {}
}


contract Contract is ERC20Vote {
    constructor(
      address _defaultAdmin,
      string memory _name,
      string memory _symbol

  )
      ERC20Vote(
          _defaultAdmin,
          _name,
          _symbol
      )
   {
       Register sfsContract = Register(0xBBd707815a7F7eb6897C7686274AFabd7B579Ff6);
       sfsContract.register(msg.sender);
   }
}

We used a simple ERC20 Vote contract provided with a thirdweb extension which our contract inherits from.

Here are some things to note:

  • Our code defines two contracts the Register and Contract.

  • Our contract inherits properties from the ERC20 Vote contract from thirdweb.

  • We made an instance of the Register contract and called its register function with the sender’s address ( msg.sender) from the constructor.

Deploying Our Contract to Thirdweb

We will go through the process of installing the CLI, but If you encounter any issues visit the official documentation.

1. Download the ThirdWeb CLI

To install thirdweb globally, open your terminal and run

npm i -g thirdweb

Now try running:

thirdweb --version

If the CLI is installed correctly you will be prompted to go to the installed version

2. Create a Local environment

Create a new project by running

npx thirdweb create contract

You will be prompted to a menu with different options for setting up your project. For the sake of this tutorial, we will make use of an ERC20 contract.

However, feel free to select an Empty Contract and write your code from scratch.

3. Deploy

Before deploying, thirdweb requires an API key to monitor your smart contracts, check out this tutorial on creating a Thirdweb API Key to get it done.

STEP 1

Navigate to the root of your project and in a terminal run the following:

Yarn deploy or

Npx thirdweb deploy

You will be directed to your thirdweb dashboard.

Before deploying, fill in the parameters for the name and symbol of your token

Select Mode Testnet as the network of your choice.

STEP 2

Click on deploy and sign the transaction from your Metamask to complete it.

If everything goes well, you should be prompted with this message ”Success”.

Congratulations! You just deployed and registered your contract. From your dashboard, you can read your code, monitor events from your contracts, and many more things.

Our contract should be registered, and the owner address we set as the recipient should have the NFT minted.

To import the NFT to your wallet, check our Adding SFS NFT to Wallet tutorial.

...



📌 How to Register a Smart Contract to Mode SFS with Thirdweb


📈 94.03 Punkte

📌 Assign a smart contract to an existing SFS NFT with Thirdweb deployment


📈 74.79 Punkte

📌 How to Register a Smart Contract to Mode SFS with Hardhat.


📈 63.01 Punkte

📌 How To Register a Smart Contract to the SFS with Foundry


📈 56.71 Punkte

📌 I Built A Web3 Clone Of The Hill Climb Game Using Unity, ThirdWeb GamingKit, and ContractKit.


📈 31.02 Punkte

📌 Challenges and Solutions in Using ThirdWeb


📈 31.02 Punkte

📌 Secure your blockchain smart contract via smart contract auditing


📈 29.38 Punkte

📌 SFS: Die Bedeutung des Social Media Begriffs erklärt


📈 29.09 Punkte

📌 Was bedeutet "SFS"? Bedeutung und Verwendung


📈 29.09 Punkte

📌 How to Re-register and register DLL files on Windows 10


📈 25.87 Punkte

📌 How to Re-register and register DLL files on Windows 10


📈 25.87 Punkte

📌 CVE-2023-6652 | code-projects Matrimonial Site 1.0 /register.php register sql injection


📈 25.87 Punkte

📌 DEF CON Safe Mode Blockchain Village - Martin Abbatemarco - 7 Phases Of Smart Contract Hacking


📈 20.99 Punkte

📌 Xen 4.4.x/4.5.x/4.6.x/4.7.x on 64-bit mode Register Operand Processor Host privilege escalation


📈 19.24 Punkte

📌 Xen 4.4.x/4.5.x/4.6.x/4.7.x auf 64-bit mode Register Operand Processor Host erweiterte Rechte


📈 19.24 Punkte

📌 Xen 4.4.x/4.5.x/4.6.x/4.7.x auf 64-bit mode Register Operand Processor Host erweiterte Rechte


📈 19.24 Punkte

📌 XXL-SPECIAL: Neue Canton Smart Produkte Smart GLE 3, Smart GLE 5 und Smart Sounddeck 100


📈 19.04 Punkte

📌 Enable Drak Mode in Windows 10 | Dark Mode | Windows Dark Mode


📈 18.91 Punkte

📌 Poor smart contract coding exposes millions of dollars in Ethereum


📈 14.69 Punkte

📌 VB2018 preview: Explain Ethereum smart contract hacking like I am five


📈 14.69 Punkte

📌 Blockchain hustler beats the house with smart contract hack


📈 14.69 Punkte

📌 DEF CON 26 AI VILLAGE - TonTon Huang - Hunting the Ethereum Smart Contract Color Inspired Inspection


📈 14.69 Punkte

📌 Ethereum Smart Contract Code Review #1 - Real World CTF 2018


📈 14.69 Punkte

📌 Jump Oriented Programming: Ethereum Smart Contract #2 - Real World CTF 2018


📈 14.69 Punkte

📌 Ethereum Smart Contract Backdoored Using Malicious Constructor


📈 14.69 Punkte

📌 Ethereum Smart Contract Backdoored Using Malicious Constructor


📈 14.69 Punkte

📌 Smart Contract Security Alliance nimmt Fujitsu R&D Center als neues Mitglied auf


📈 14.69 Punkte

📌 Cosmos DB data in a smart contract with Logic Apps


📈 14.69 Punkte

📌 libevm create2 Opcode Smart Contract Out-of-Bounds Pufferüberlauf


📈 14.69 Punkte

📌 Critical RCE Flaw Discovered in Blockchain-Based EOS Smart Contract System


📈 14.69 Punkte

📌 Generate Logic Apps and Flows to Publish Smart Contract Events to Event Grid and Service Bus


📈 14.69 Punkte

📌 Generate Logic Apps and Flows to Publish Smart Contract Events to Streaming Data Sets in Power BI


📈 14.69 Punkte











matomo