# Installation

***

## Overview

### To protect your protocols with Venn you will need to:

1. Integrate the **Firewall SDK** into your smart contracts.&#x20;
2. **Register** your smart contracts on-chain with Venn.
3. Install the **dApp SDK** on your frontend.

{% hint style="info" %}
Before you start the installation, take some time to familiarize yourself with the Venn stack using the tools designed specifically for developers:\
\
[**Venn Playground:**](https://explorer.venn.build/playground)\
A demo dApp that enables you to try Venn integrations, helping you understand how Venn works. <br>

[**Hello Venn:**<br>](https://github.com/ironblocks/hello-venn)A “Hello World” repository designed to gain hands-on experience with the integration process and explore Venn's capabilities in a local controlled environment.
{% endhint %}

***

## Step 1 - Integrate the **Firewall SDK**

### Install the Venn CLI

Start by installing the Venn CLI. This will allow you to add the Firewall SDK to your smart contracts and register them on the chain.

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

*This command installs the CLI globally, making the* <kbd>**venn**</kbd> *command available in your terminal.*

### Integrate the Firewall SDK

The Firewall SDK adds the[ security modifiers](https://docs.venn.build/venn-network/getting-started/protocols-and-developers/how-it-works) to your smart contracts. Run this command from the root folder of your project to integrate the SDK:

```sh
venn fw integ -d contracts
```

*This command scans all smart contracts in the* <kbd>**contracts**</kbd> *folder and automatically adds the required import* <kbd>**VennFirewallConsumer**</kbd> *to the external functions.*

#### Example:

Before Integration:

```solidity
pragma solidity ^0.8;

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

After Integration:

```solidity
pragma solidity ^0.8;

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

contract MyContract is VennFirewallConsumer {

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

{% hint style="success" %}
Now that your smart contracts include the Firewall SDK, deploy them as you normally would on any network - this will enable you to register them on-chain to Venn, in the next step.
{% endhint %}

***

## Step 2 - **Register** your smart contracts with Venn.

{% hint style="info" %}
This step connects your Firewall-protected smart contracts to the Venn Network on-chain by sending setup transactions.
{% endhint %}

### **Before You Begin**

* Complete step 1: Firewall SDK integration on your smart contracts.&#x20;
* Ensure your smart contracts are deployed on-chain.
* Have your deployment private key ready (this must be the same key used for deployment).

### **Configuration**

1. Create a configuration file named **`venn.config.json`** in your project’s root directory.
2. Update the file with your deployed contract addresses. Example:

```json
{
    "networks": {
        "holesky": {
            "contracts": {
                "MyContract1": "0x1234abcd1234abcd1234abcd1234abcd1234abcd",
                "MyContract2": "0x1234abcd1234abcd1234abcd1234abcd1234abcd",
            }
        }
    }
}
```

* Each key in the `contracts` object is the **Name** of the contract
* Each value in the `contracts` object is the **Address** of the contract

3. Create an environment variable called <kbd>**VENN\_PRIVATE\_KEY**</kbd> with the private key that deployed your smart contracts.

{% hint style="warning" %}
**IMPORTANT:** This key **must** be the same key that deployed the smart contracts
{% endhint %}

### **Connect To Venn**

Run this command to register your Firewall-protected smart contracts with Venn:

```bash
venn enable --network holesky
```

### **Your Venn Policy**

After a successful connection to Venn, a new Venn Security Policy is created for you. The policy address is automatically saved in your <kbd>**venn.config.json**</kbd> file, for example:

```json
{
    "networks": {
        "holesky": {
            "contracts": {
                "MyContract1": "0x1234abcd1234abcd1234abcd1234abcd1234abcd",
                "MyContract2": "0x1234abcd1234abcd1234abcd1234abcd1234abcd",
            },

            // YOUR VENN POLICY ADDRESS
            "policyAddress": "0x123..."
        }
    }
}
```

{% hint style="info" %}
You will use the<kbd>**policyAddress**</kbd> in the next step, when setting up your dApp frontend.
{% endhint %}

***

## Step 3 - Set Up the **dApp SDK** on your frontend.

Now that your smart contracts are secured, only approved transactions will be executed on-chain. To also approve transactions that go through your dApp frontend, you will need to install Venn-SDK in your dApp.&#x20;

### **Install the SDK**

In your dApp frontend project, open a new terminal and install the SDK.

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

### Initialize **a New** VennClient **Instance**

Import the VennClient and create a new instance by providing the Venn node URL and your Venn policy address from step 2:

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

const vennURL           = process.env.VENN_NODE_URL;          // URL of your Venn node operator
const vennPolicyAddress = process.env.VENN_POLICY_ADDRESS;      // Your Venn policy address

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

```

* <kbd>**vennURL**</kbd>, a URL pointing to a Venn node operator:

{% code title="Venn node operator:" %}

```
https://signer2.testnet.venn.build/api/17000/sign
```

{% endcode %}

* <kbd>**vennPolicyAddress**</kbd>: the <kbd>**policyAddress**</kbd> You got from "Register With Venn" in step 2.

### Approving Transactions

Use the SDK to validate transactions before sending them on-chain:

```typescript
const approvedTransaction = await vennClient.approve({
    from,
    to,
    data,
    value
});

// You can now send the approvedTransaction as you normally would
const receipt = await wallet.sendTransaction(approvedTransaction);
```

{% hint style="success" %}
That's it! Welcome to Venn. :tada:  You can now view your activity on Venn in the [Explorer](https://explorer.venn.build/transactions).
{% endhint %}

***

## Reference Documentation

* [Venn CLI](https://www.npmjs.com/package/@vennbuild/cli)
* [Venn DApp SDK](https://www.npmjs.com/package/@vennbuild/venn-dapp-sdk)
