Cookie Consent by Free Privacy Policy Generator 📌 How to Register a Smart Contract to Mode SFS with Hardhat.


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


💡 Newskategorie: Programmierung
🔗 Quelle: dev.to

Hardhat is an Ethereum development framework for creating, testing and deploying smart contracts. It includes a suite of tools that aid in developing smart contracts and managing the complete development process, allowing developers to write scripts, compile, test, and deploy efficiently.

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

Prerequisites

Before you continue with this tutorial, you should:

  1. Have npm and node.js installed with the recommended versions.

  2. Have an Ethereum wallet, preferably Metamask installed.

  3. Have a basic understanding of Solidity.

  4. Bridge Sepolia Eth with Mode Network.

What is Sequencer Fee Sharing (SFS)?

The SFS contract allows developers to earn a portion of the transaction fees from transactions running on their contract when deployed and registered on Mode Network. The SFS contract implements this functionality and permits other contracts to register and earn.

To register, your smart contract has to make a call to the SFS contract; after this is done successfully, you will be issued an NFT (non-fungible token). This NFT allows you to claim your fees accumulated in the SFS contract.

How does the SFS Register function work?

Let’s look at the SFS contract's register function to understand how the registration works.

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 
   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 function receives "_recipient" as 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.

Now that we’ve understood how the register function works, let’s set up our project.

1. Setting Up Our Project

Open your terminal to create a new directory for your project.

mkdir hardhat

Navigate into your project

cd hardhat

Initialize an npm project - This creates your package.json file.

npm init -y

Install hardhat

npm install --save-dev hardhat

To create your project run

npx hardhat init

When prompted make these selections:

  • Choose "Create a TypeScript project".

  • For the .gitignore prompt, select "Yes" (or y).

  • Select "Yes" (or y) to install the project's dependencies

2. Writing our smart contract

Head to the contracts folder of your project, for the sake of this tutorial we will be using the contract provided by Hardhat.

Rename the file named lock.sol to any name of your choice then add the register contract to your file and the register function to your constructor.

// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.9;
// Add this
contract Register {
   function register(address _recipient) public returns (uint256 tokenId) {}
}
contract Lock {
   uint public unlockTime;
   address payable public owner;
   event Withdrawal(uint amount, uint when);

   constructor(uint _unlockTime) payable {
       require(
           block.timestamp < _unlockTime,
           "Unlock time should be in the future"
       );
       unlockTime = _unlockTime;
       owner = payable(msg.sender);
    //Add this
       Register sfsContract = Register(0xBBd707815a7F7eb6897C7686274AFabd7B579Ff6);
       sfsContract.register(msg.sender); //
   }

   function withdraw() public {
       require(block.timestamp >= unlockTime, "You can't withdraw yet");
       require(msg.sender == owner, "You aren't the owner");

       emit Withdrawal(address(this).balance, block.timestamp);

       owner.transfer(address(this).balance);
   }
}

3. Configuring Hardhat for Mode

Head to the hardhat.config.ts file and replace it with this code to set Mode Network Testnet.

import { HardhatUserConfig } from "hardhat/config";
import "@nomicfoundation/hardhat-toolbox";

const config: HardhatUserConfig = {
 networks: {
   mode: {
     url: "https://sepolia.mode.network",
     chainId: 919,
     accounts: ["YOUR_METAMASK_PRIVATE_KEY_HERE"] //DO NOT PUSH THIS TO GITHUB
   }
 },
 solidity: "0.8.9",
};

export default config;

4. Compiling our contract

To compile the smart contract run

npx hardhat compile

It would return;

Successfully generated 8 typings!

Compiled 1 Solidity file successfully (evm target: london).

5. Deploying

To deploy we will make use of the deploy.ts file in the scripts folder, we won’t be changing anything because we didn’t change our smart contract.

To deploy the smart contract to Mode Testnet run

npx hardhat run scripts/deploy.ts --network mode

It returns

Lock with 0.001ETH and unlock timestamp 1702421602 deployed to 0x6900A6158C1BD0C61F1E6a191B1f822EA000E2e8

Congratulations! You just deployed and registered your contract with Hardhat and Typescript.

Check the Explorer

To view your transaction head to Mode Testnet and paste the contract address.

Your contract should be registered and your NFT minted.

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

To learn more about mode and how to turn your code into a business join our Discord and say hi.

To learn more about mode and how to turn your code into a business join our Discord and say hi.

...

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


📈 93.71 Punkte

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


📈 63.51 Punkte

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


📈 57.13 Punkte

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


📈 44.09 Punkte

✅ How to Verify Smart Contracts on BlockScout with Hardhat


📈 35 Punkte

✅ How to Verify Smart Contracts on BlockScout with Hardhat


📈 35 Punkte

✅ Ethereum Development: Foundry or Hardhat


📈 30.2 Punkte

✅ EIP 712: A simple example using Ethers.js & Hardhat


📈 30.2 Punkte

✅ Secure your blockchain smart contract via smart contract auditing


📈 29.52 Punkte

✅ Was bedeutet &quot;SFS&quot;? Bedeutung und Verwendung


📈 29.33 Punkte

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


📈 29.33 Punkte

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


📈 26.08 Punkte

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


📈 26.08 Punkte

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


📈 26.08 Punkte

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


📈 21.14 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.42 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.42 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.42 Punkte

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


📈 19.23 Punkte

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


📈 19.14 Punkte

✅ Help hack new lisp-like smart contract language, Clarity


📈 14.76 Punkte

✅ Providence Crypto Casino mintToken Smart Contract privilege escalation


📈 14.76 Punkte

✅ ESH mintToken Smart Contract privilege escalation


📈 14.76 Punkte

✅ YLCToken mintToken Smart Contract privilege escalation


📈 14.76 Punkte

✅ Building an Escrow Smart Contract


📈 14.76 Punkte

✅ Reimburse Token mintToken Smart Contract privilege escalation


📈 14.76 Punkte

✅ Block 18 Ethereum ERC20 Token approveAndCallcode Smart Contract privilege escalation


📈 14.76 Punkte

✅ Easticoin mintToken Smart Contract privilege escalation


📈 14.76 Punkte

✅ HYIPToken mint Smart Contract privilege escalation


📈 14.76 Punkte

✅ Cosmos DB data in a smart contract with Logic Apps | Block Talk


📈 14.76 Punkte

✅ Enterprise Token Ecosystem mintToken Smart Contract erweiterte Rechte


📈 14.76 Punkte

✅ RajTestICO mintToken Smart Contract privilege escalation


📈 14.76 Punkte











matomo

Datei nicht gefunden!