This Quickstart is a work in progress. If you see this message, there are a few engineering details we are cleaning up before you’ll be able to follow it.

This Quickstart includes a repository with everything you need to get an example rule up and running quickly and easily.

Get Started

Create a copy of this template repository in your own github account by navigating here: https://github.com/thrackle-io/fre-quickstart and clicking the “Use this template” button on GitHub.

Next, clone the freshly created repository to your local machine:

git clone https://github.com/<YOUR_GITHUB_USERNAME>/fre-quickstart

Install Dependencies

cd fre-quickstart
npm install
forge install

Start Local Anvil Chain

Use the provided anvil state file to get a local anvil chain running with the rules engine deployed.

anvil --load-state anvilState.json

Environment File

Add a file named .env to the repository and set the following values:

.env
# local anvil RPC, change this if you're deploying to a network
RPC_URL=http://127.0.0.1:8545
# local anvil account private key, change to your deployer wallet key when using a live network
PRIV_KEY=0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80
# base-sepolia address of the rules engine
RULES_ENGINE_ADDRESS=0x0165878A594ca255338adfa4d48449f69242Eb8F

With your .env file ready you can make the values available to your command line shell with the following command:

source .env

Add Demo Policy

The fre-quickstart repo includes a demo policy to get started quickly. Deploy it by running the following provided script:

npx tsx index.ts

Deploy Example Contract

The repository you cloned includes an example smart contract with the necessary modifier included. Deploy this contract using the provided script with this command:

forge script script/ExampleContract.s.sol --ffi --broadcast -vvv --non-interactive --rpc-url=$RPC_URL --private-key $PRIV_KEY

Note the contract address, add it to your .env file and re-run the source command:

CONTRACT_ADDRESS=0xYourContractAddress
source .env

Now, you need to set the rules engine address for the contract you just deployed. This enables the contract to hook into the protocol for rules evaluations.

cast send $CONTRACT_ADDRESS "setRulesEngineAddress(address)" $RULES_ENGINE_ADDRESS --rpc-url $RPC_URL --private-key $PRIV_KEY

If you deployed to a testnet then you’ll need to replace the first address (0x68B...) in that above command to match that of your deployed contract address.

Apply the Policy

Now it’s time to apply a premade policy to the transfer function of the sample contract. A script is provided to make this very easy, simply run the following command:

npx tsx index.ts apply 1 $CONTRACT_ADDRESS

This will apply a policy that requires transfer amounts be greater than 10,000.

Test Success Condition

cast send $CONTRACT_ADDRESS "transfer(address,uint256)" 0x70997970C51812dc3A010C7d01b50e0d17dc79C8 10001 --rpc-url $RPC_URL --private-key $PRIV_KEY

You should receive a revert with the text “Passed Test”

Test Failure Condition

cast send $CONTRACT_ADDRESS "transfer(address,uint256)" 0x70997970C51812dc3A010C7d01b50e0d17dc79C8 9999 --rpc-url $RPC_URL --private-key $PRIV_KEY

You should receive a revert with the text “Failed Test”

Conclusion

That wraps up the quickstart! In a few short minutes you were able to see the rules engine in action. Continue through the guides to learn how to apply the power of rules in your own projects.