> For the complete documentation index, see [llms.txt](https://developer.opzeknd.xyz/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://developer.opzeknd.xyz/solidity-and-evm/truffle-dappchain-example.md). Agents can also search and read this documentation through its [MCP server](https://developer.opzeknd.xyz/~gitbook/mcp).

# Truffle DappChain Example

This simple example shows how you can use `Truffle` and the zeknd Truffle Provider to build a simple Web UI that interacts with the Basechain.

\
**#Requirements**

Make sure the following requirements are met and then follow the steps in the next section:

```
Node >= 8
yarn or npm
```

### #Install <a href="#install" id="install"></a>

First, let's clone this repository. Open a terminal, `cd` into the directory where you store your projects, and run the following command:

```
git clone https://github.com/zekndnetwork/truffle-dappchain-example
```

Next, `cd` into `truffle-dappchain-example`:

```
cd truffle-dappchain-example
```

and run:

```
yarn install
```

### #Run against Extdev Testnet <a href="#run-against-extdev-testnet" id="run-against-extdev-testnet"></a>

#### #Generate the zeknd private key <a href="#generate-the-loom-private-key" id="generate-the-loom-private-key"></a>

The following command will download the zeknd binary and generate the private key for you:

```
yarn gen:extdev-key
```

> The zeknd private key will be saved into a file called `extdev_private_key`.

#### #Deploy to Extdev Testnet <a href="#deploy-to-extdev-testnet" id="deploy-to-extdev-testnet"></a>

As an example, we will deploy and run our application against Extdev.

Run the following command:

```
yarn deploy:extdev
```

> The above command will **compile and then deploy** our smart contract to Extdev

#### #Test <a href="#test" id="test"></a>

Run this command below to send transactions to the smart contract deployed to Extdev:

```
yarn test:extdev
```

If everything looks good, let's spin up a web server and interact with our smart contract.

#### #Start the web interface <a href="#start-the-web-interface" id="start-the-web-interface"></a>

The web interface is built with React and Webpack. Open a new terminal and run the following command:

```
yarn serve:extdev
```

> The web interface is available on <http://localhost:8080>.

### #Run against local zeknd chain <a href="#run-against-local-loom-chain" id="run-against-local-loom-chain"></a>

First, you have to generate a private key using:

```
yarn gen:extdev-key
```

#### #Spin up zeknd Chain <a href="#spin-up-loom-chain" id="spin-up-loom-chain"></a>

In a new terminal, run:

```
yarn zeknd-init
```

#### #Deploy the smart contract <a href="#deploy-the-smart-contract" id="deploy-the-smart-contract"></a>

To deploy, run the following command:

```
yarn deploy
```

You will see something like this:

```
Starting migrations...
======================
> Network name:    'zeknd_dapp_chain'
> Network id:      13654820909954
> Block gas limit: 0
```

Copy the `Network id` paste it into a text file. We'll use it later.

#### #Test <a href="#test-2" id="test-2"></a>

```
yarn test
```

### #Web interface <a href="#web-interface" id="web-interface"></a>

Open the `src/contract.js` file in your text editor of choice and go to line 87.

Now, say your `Network id` is `13654820909954`. Replace

```
return Promise.resolve('default')
```

with

```
return Promise.resolve('13654820909954')
```

We're ready to start the web server. In a new terminal, run:

```
yarn serve
```

### #Useful information <a href="#useful-information" id="useful-information"></a>

1. In order to correctly redeploy the contracts, there's a command `yarn deploy:reset`.
2. Also is possible to call truffle command directly with `yarn truffle`.
3. We're not versioning the build directory for this particular example, although is recommended to versioning, the limitation can be removed by editing the `.gitignore` file.

### #Current limitations <a href="#current-limitations" id="current-limitations"></a>

* Events declared on smart contracts should have an named parameter like `NewValueSet(uint _value)` in the contract `SimpleStore.sol`. Also, it helps in dealing with events.

### #zeknd Network <a href="#loom-network" id="loom-network"></a>

<https://zeknd.xyz>

### #License <a href="#license" id="license"></a>

BSD 3-Clause License
