Trapper
Prerequisites
You must run the Operator first
Deployment
Move to your trap directory
cd my-drosera-trapCreate a new Trap.sol file
nano src/Trap.solPaste 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.tomlModify the values of the specified variables as follows:
path
"out/Trap.sol/Trap.json"
response_contract
"0x4608Afa7f277C8E0BE232232265850d1cDeB600E"
response_function
"respondWithDiscordName(string)"
Compile your Trap's Contract:
source /root/.bashrc
forge buildTest the trap before deploying:
drosera dryrunApply and Deploy the Trap:
DROSERA_PRIVATE_KEY=xxx drosera apply --eth-rpc-url your-rpcReplace
xxxwith your EVM wallet privatekey (Ensure it's funded with Holesky ETH)Replace
your-rpcwith your Holesky ETH RPC, you can get it from Alchemy for free
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.comReplace
OWNER_ADDRESSwith your Trap's owner address. (Your main address that has deployed the Trap's contract)If you receive
trueas a response, it means you have successfully completed all the steps.
Restart Operator nodes
cd ~
cd Drosera-Network
docker compose up -dView 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/Last updated