Intro: What is Easy Trigger & How to Get Started
Easy Trigger provides you with a webhook that will trigger a specific smart contract function when called. It can be integrated directly into new contracts or added to existing contracts.
Note that Easy Trigger is a tool still in Alpha and may be subject to frequent changes. If you have any features to request or bugs to report you can let us know on our Discord.
Any breaking changes especially security relevant ones will be announced on both our Discord & Twitter.
Smart Contract Integration (using foundry
)
1. Installation
Note you can omit the --no-commit
flag if you're installing the lib into a folder that isn't a git
repo.
forge install dereg-io/ez-trigger --no-commit
2. Obtain your UserID
Login or SignUp at app.dereg.io.
After logging in, at the top right of the page you will find your UserID. Add it to your smart contract code (see 3.), this ensure only you can create an Easy Trigger for your smart contract.
3. Add to Smart Contract
To implement the actual logic that'll get executed for your trigger you can start by importing and
inheriting from the base Triggerable
mixin and replace the example UserID with your UserId
(see 2.).
You then define the _onTrigger
method which will be executed when your trigger webhook is called.
It's safe to share your UserID and have it be part of your public smart contract code. The UserID is necessary for us to be able to associate contracts to their respective user accounts and prevent different users from triggering each other's contracts.
// Add Easy Trigger import, can be shortened if remappings.txt configured.
import { Triggerable } from "ez-trigger/src/Triggerable.sol";
// Add `Triggerable` to parent contracts (contracts you're inheriting from)
contract YourContract is Pausable, Triggerable("1234567b-fbe1-1234-1234-12abcde123a1") {
function _onTrigger() internal override {
_pause();
}
}
Outside of pausing your contract you can customize the functionality of your trigger by defining
different logic in your _onTrigger
internal method.
Trigger logic is limited to ~165k gas for now to mitigate potential spam. If your _onTrigger
callback attempts to utilize more than approx. 165,000 gas the call as a whole will revert.