# EthGlobal Bangkok

## What is Venn

Venn stops exploit transactions before they even hit the blockchain, securing every transaction in real-time through a decentralized and modular network of security operators.

Hi and welcome to the Venn Challenge for DC7SEA 👋

* Learn more at: [Venn Site](https://www.venn.build/) | [Venn Playground](https://playground.venn.build/)

### Venn Prize - $1,000

### Instructions

In this challenge, you'll deploy a new Venn Firewall and integrate it into your smart contracts to enhance your project's security.

Once completed, you'll also need to integrate Venn DApp SDK to your DApp's Frontend so that transactions get approved before being sent onchain.

Ready ? Let's go 💪

### Step 1: Clone Venn challenge repo

1. Clone the repo and install dependencies:

```
git clone https://github.com/ironblocks/DC7-SEA
cd DC7-SEA
npm ci
```

2. Setup your private key and hardhat network configuration

```
cp .env.example .env
```

```
PRIVATE_KEY=...
RPC_URL=...
```

3. Compile

```
npm run firewall:compile  # the warning are a feature, not a bug 😅
```

4. Deploy a new Firewall

Venn Firewall is an onchain solution that can surgically prevent malicious transactions from going through, only allowing approved transactions to be executed.

```
npm run firewall:deploy -- --network <network>
```

5. Note the new `venn.config.json` file that was created with the Firewall address in it. We'll use this later in **Step 4**.

### Step 2: In Your Smart Contracts Repo

Now that the Firewall is deployed, you'll use various Venn SDKs to integrate Venn with your project.

1. Install the CLI:

```
npm i -g @vennbuild/cli
```

2. Run the CLI to add the Firewall to your smart contracts:

```
venn fw integ -r -d contracts
```

**Before**

```solidity
pragma solidity ^0.8;

contract MyContract {
    
    myMethod() {
        ...
    }
}
```

**After**

```solidity
pragma solidity ^0.8;

import {VennFirewallConsumer} from "@ironblocks/firewall-consumer/contracts/consumers/VennFirewallConsumer.sol";

contract MyContract is VennFirewallConsumer {

    myMethod() firewallProtected {
        ...
    }
}
```

Now that your smart contracts include the Firewall SDK, deploy them as you normally would onto any network.

3. Deploy your contracts as you normally would:

```
hardhat run scripts/deploy.js   # your deployment script
```

## Step 3: Back In The Challenge Repo

Now that your smart contracts have integration with Venn, you'll need to send a setup transaction to enable the Firewall.

1. Remember `venn.config.json` ? time to use it. Open this file and add your contracts addresses:

```json
{
    "networks": {
        "holesky": {
            "firewall": "0x123...",

            "contracts": {
                "MyContract1": "0x11111...",
                "MyContract2": "0x22222..."
            }
        }
    }
}
```

2. Run the setup script. This script will send setup transactions from the `PRIVATE_KEY` you've configured in the `.env` file to turn on the Firewall on each of your contracts:

```
npm run firewall:setup -- --network <network>
```

## Step 4: Your Repo Again (last time i promise!)

With the Venn Firewall enabled on your smart contracts, transactions need to be approved via Venn Network before they can be submitted on chain.

To do this, you'll add our Venn DApp SDK to your DApp's Frontend.

1. Install the SDK

```
npm i @vennbuild/venn-dapp-sdk
```

2. Create a new instance of the SDK Client

```javascript
import { VennClient } from '@vennbuild/venn-dapp-sdk';

const vennURL           = "https://dc7sea.venn.build/sign";
const vennPolicyAddress = YOUR FIREWALL ADDRESS;

const vennClient = new VennClient({ vennURL, vennPolicyAddress });
```

3. Update your DApp to approve transactions before submitting them onchain:

```javascript
// You probably have something like this:
const tx = { to, from, data, value };
const receipt = await wallet.sendTransaction(approvedTransaction);


// But now you need this:
const tx = { to, from, data, value };
const approvedTransaction = await vennClient.approve(tx);
const receipt = await wallet.sendTransaction(approvedTransaction);
```

### Kinto Prize - $500

See here \[[link](https://docs.kinto.xyz/kinto-the-safe-l2/building-on-kinto/tools/firewall-venn)] for projects building on Kinto to learn more.

<br>


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.venn.build/venn-network/getting-started/protocols-and-developers/ethglobal-bangkok.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
