LogoLogo
  • Introduction
  • Testnet
    • 0G-Labs
      • Network Overview
      • Installation
        • Storage Node
        • Data Availability Node
        • Data Availability Client
    • Aztec
      • Installation
      • Register as Validator
    • Coretensor
      • Installation
    • Cysic
      • Installation
    • Dill
      • Network Overview
      • Installation
    • Drosera
      • Installation
        • Operator
        • Add Second Operator
        • Trapper
    • Farcaster
      • Installation
    • Warden
      • Network Overview
      • Installation
      • Snapshot & State Sync
      • Validator Setup
  • Mainnet
    • Humanode
      • Installation
    • Initverse
      • Installation
  • Archieve
    • Privasea
      • Installation
  • Services
  • My Contact
Powered by GitBook
On this page
  • Prerequisites
  • Deployment
  • Verify Trap can respond
  • Restart Operator nodes
  • View the List of submitted Discord Names

Was this helpful?

  1. Testnet
  2. Drosera
  3. Installation

Trapper

PreviousAdd Second OperatorNextFarcaster

Last updated 5 days ago

Was this helpful?

Prerequisites

You must run the first

Deployment

Move to your trap directory

cd my-drosera-trap

Create a new Trap.sol file

nano src/Trap.sol

Paste the following contract code in it:

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;

import {ITrap} from "drosera-contracts/interfaces/ITrap.sol";

interface IMockResponse {
    function isActive() external view returns (bool);
}

contract Trap is ITrap {
    address public constant RESPONSE_CONTRACT = 0x4608Afa7f277C8E0BE232232265850d1cDeB600E;
    string constant discordName = "DISCORD_USERNAME"; // add your discord name here

    function collect() external view returns (bytes memory) {
        bool active = IMockResponse(RESPONSE_CONTRACT).isActive();
        return abi.encode(active, discordName);
    }

    function shouldRespond(bytes[] calldata data) external pure returns (bool, bytes memory) {
        // take the latest block data from collect
        (bool active, string memory name) = abi.decode(data[0], (bool, string));
        // will not run if the contract is not active or the discord name is not set
        if (!active || bytes(name).length == 0) {
            return (false, bytes(""));
        }

        return (true, abi.encode(name));
    }
}

Replace DISCORD_USERNAME with your discord username.

Edit drosera.toml config

nano drosera.toml

Modify the values of the specified variables as follows:

Variable
Value

path

"out/Trap.sol/Trap.json"

response_contract

"0x4608Afa7f277C8E0BE232232265850d1cDeB600E"

response_function

"respondWithDiscordName(string)"

Compile your Trap's Contract:

source /root/.bashrc
forge build

Test the trap before deploying:

drosera dryrun

Apply and Deploy the Trap:

DROSERA_PRIVATE_KEY=xxx drosera apply --eth-rpc-url your-rpc
  • Replace xxx with your EVM wallet privatekey (Ensure it's funded with Holesky ETH)

Verify Trap can respond

After the trap is deployed, we can check if the user has responded by calling the isResponder function on the response contract.

source /root/.bashrc
cast call 0x4608Afa7f277C8E0BE232232265850d1cDeB600E "isResponder(address)(bool)" OWNER_ADDRESS --rpc-url https://ethereum-holesky-rpc.publicnode.com
  • Replace OWNER_ADDRESS with your Trap's owner address. (Your main address that has deployed the Trap's contract)

  • If you receive true as a response, it means you have successfully completed all the steps.

Restart Operator nodes

cd ~
cd Drosera-Network
docker compose up -d

View the List of submitted Discord Names

source /root/.bashrc
cast call 0x4608Afa7f277C8E0BE232232265850d1cDeB600E "getDiscordNamesBatch(uint256,uint256)(string[])" 0 2000 --rpc-url https://ethereum-holesky-rpc.publicnode.com/

Replace your-rpc with your Holesky ETH RPC, you can get it from for free

Operator
Alchemy