# Deployment

Please read the code comments in the files below. Examples are taken from our [Example Contract ](https://github.com/Trac-Systems/trac-contract-example/)Github repo. We assume the example contract will be executed and the below helps you to get a better understanding.

Below is a typical configuration file that goes wit your app package. In the example below, there is no need to setup a custom Main Settlement Bus as we provided one already as a kind of testnet (gasless).

The configurable part consists of the Peer and Feature options.

### Setup

```javascript
import {getStorePath} from './src/functions.js';
import {App} from './src/app.js';
export * from 'trac-peer/src/functions.js'
import {default as SampleProtocol} from "./contract/protocol";
import {default as SampleContract} from "./contract/contract";
import {Timer} from "./features/timer/index.js";

console.log('Storage path:', getStorePath());

///// MSB SETUP
// To run this example, you don't need to create your own MSB
// Instead go with the options as-is. The below bootstrap is an MSB testnet (gasless).
const msb_opts = {};
msb_opts.bootstrap = 'cdcb126766cb2673bc14f3e91be61150504d0f97e5055bbc430193091fe96bba';
msb_opts.channel = '0000000000000000000000examplemsb';
msb_opts.store_name = getStorePath() + '/msb';

///// SAMPLE CONTRACT SETUP
// The sample contract needs to be deployed first.
// See the README.md for further information.
const peer_opts = {};
peer_opts.protocol = SampleProtocol;
peer_opts.contract = SampleContract;
peer_opts.bootstrap = '0000000000000000000000000000000000000000000000000000000000000000';
peer_opts.channel = '0000000000000000000000000example';
peer_opts.store_name = getStorePath() + '/example';
peer_opts.api_tx_exposed = true;
peer_opts.api_msg_exposed = true;

///// FEATURES
// Pass multiple features (aka oracles) to the peer and inject data into
// your contract. Can also go the other way, depending on how you need it.
// You may add as many Features as you wish.
// In /src/app.js, the Features are being executed by the admin (usually the Peer Bootstrap)
const timer_opts = {};
timer_opts.update_interval = 10_000;

export const app = new App(msb_opts, peer_opts, [
    {
        name : 'timer',
        class : Timer,
        opts : timer_opts
    }
]);
await app.start();
```

### Install

```
git clone git@github.com:Trac-Systems/trac-contract-example.git
```

While the Trac apps support native node-js, it is encouraged to use Pear:

```
cd trac-contract-example
npm install -g pear
npm install
pear run . store1
```

### Deployment

**Deploy Bootstrap (admin):**

* Start your app the first time and choose option 1)
* Copy and backup the seedphrase
* Copy the "Peer Writer" key from the Peer section (basically the contract address)
* With a text editor, open the file index.js in document root
* Replace the bootstrap address in the example section (not the MSB) with the copied writer address
* Choose a channel name (exactly 32 characters)
* Type /exit and hit enter, then run again: pear run . store1
* After the options appear, type "/add\_admin --address YourPeerWriterKey" and hit enter
* Your instance is now the Bootstrap and admin peer of your contract network.
* Keep your bootstrap node running
* For production contracts, it is strongly recommended to add a couple of indexers. See below.

**Running indexers (admin)**

* Install on different machines than the Bootstrap's (ideally different data centers) with the exact setup in index.js
* Upon start ("pear run . store1") copy the "Peer Writer" key
* In the Bootstrap node screen, add the indexer: "/add\_indexer --key TheIndexerWriterKey."
* You should see a success confirmation
* Usually 2 indexers on different locations are enough, we recommend 2 to max. 4 in addition to the Bootstrap

**Enable others to join and to transact:**

* By default, people cannot auto-join the contract network. The network admin (the Bootstrap in this case) can enable auto-join
* To enable auto-join, in the screen of the Bootstrap enter "/set\_auto\_add\_writers --enabled 1"
* Any other Peer joining with the exact same setup can join the network and execute contract functions and transactions.
* Users may join using the exact same setup in index.js and start using "pear run . store1"
* For more features, play around with the available system and chat options.
