Welcome, fellow builder!
This repo serves as a "Hello World" to get you up & running with Venn like a pro in 10m or less! 🏆
Table of Contents
- Your Demo dApp - A Safe Vault
- Prerequisits
- Step By Step
Our contract is a (very) simple SafeVault.sol with the following interface:
-
deposits
a mapping between a user's address and how much ETH they have -
deposit()
a method for users to deposit ETH to the vault -
withdraw()
a method for users to withdraw previously deposited ETH
- A wallet with some at Holesky ETH in it
Let's make sure everything works as-is before we start to tinker with this project:
-
Clone the Repo 🖥️
git clone https://github.com/ironblocks/hello-venn.git cd hello-venn
-
Install Dependencies 📦
npm ci
-
Setup Environment Variables 🔑
Copy the.env.example
file to.env
and set the values:cp .env.example .env
Make sure to set the following environment variables:
-
PRIVATE_KEY
the key you will use for deploying this contract -
HOLESKY_RPC_URL
the RPC URL to connect to Holesky -
VENN_PRIVATE_KEY
used by thevenn-cli
to send Venn setup transactions. Usually, this would be the same as yourPRIVATE_KEY
-
-
Run Tests 🧪
npm test
All tests pass, and we can continue to the next step.
We're going to use the venn-cli
to integrate Venn into our smart contracts. This will update our smart contracts, making them Venn Ready
, without changing their existing behavior until we actually enable Venn in Step 2 / From Venn Ready
To Venn Enabled
below.
-
Install Venn CLI 📦
npm i -g @vennbuild/cli
-
Run the CLI on our contracts 🛠️
venn fw integ -d contracts
Note: On the first run, this will also install the
@ironblocks/firewall-consumer
SDK package
-
Review Changes to
SafeVault.sol
🔎- An import for
VennFirewallConsumer
was added - The contract now inherits the
VennFirewallConsumer
- External methods are now
firewallProtected
- An import for
-
Verify Tests Still Pass 🧪
npm test
-
Deploy 🚀
npm run step:1:deploy
-
End 2 End Tests ☘️
npm run step:1:deposit npm run step:1:withdraw
Now that our contracts are
Venn Ready
, let's move on to making themVenn Enabled
.
We'll use the venn-cli
to enable Venn's security features on our smart contracts:
-
Enable Venn 🛡️
venn enable --network holesky
Our
SafeVault
is now protected by Venn.
-
Venn Policy Address 📌
The CLI also prints out the address of our new
Venn Policy
We'll need it in the next step, so go ahead and copy it into thevenn.config.json
file as follows:{ "networks": { "holesky": { "contracts": { "SafeVault": "..." }, "policyAddress": "PASTE YOUR POLICY ADDRESS HERE" } } }
-
But Now Everything's Broken 😱
If we now try to deposit or withdraw, our transactions will fail
npm run step:2:deposit npm run step:2:withdraw
This is because Venn only allows approved transactions to go through.
So, how do we get our transactions approved by Venn?TIP: See these
Firewall Reverted
transactions on the Venn Explorer
Let's use the Venn DApp SDK so that we can get our transactions approved:
-
Install The SDK 📦
npm i @vennbuild/venn-dapp-sdk
-
Review The SDK Code 🖥️
For the purpose of this guide, we took the liberty of preparing all the code in advance, so you don't have to.
Checkout the integration code in the file step-3/deposit.ts:
const vennClient = new VennClient({ vennURL: VENN_SIGNER_URL, vennPolicyAddress: VENN_POLICY_ADDRESS }); ... const approvedTx = await vennClient.approve({ from: owner.address, to: SAFE_VAULT_ADDRESS, value: hre.ethers.parseEther("0.0001").toString(), data: safeVault.interface.encodeFunctionData("deposit") });
-
Run Approved Transactions 📦
With the Venn DApp SDK installed, our updated
deposit
andwithdraw
scripts are now working again:npm run step:3:deposit npm run step:3:withdraw
TIP: See these transactions on the Venn Explorer
-
Checkout Venn Playground for a live version of the
SafeVault
Hello Venn DApp -
Use the Venn Explorer to ... well, explore :)