Skip to content

Setting up local development environment

eezcjkr edited this page Aug 1, 2018 · 13 revisions

This is a quick guide on how to setup a local development environment for working with the parsec codebase.

To begin with, create a directory called something like ParsecLabsRepos somewhere on your file system:

mkdir ParsecLabsRepos
cd ParsecLabsRepos

Deploying smart contracts

First we will deploy the required smart contracts in our local truffle network. Start by cloning parsec-contracts and building it:

git clone -b migrations https://github.com/parsec-labs/parsec-contracts.git
cd parsec-contracts/
npm install

Now run:

truffle develop

You should see something like this:

truffle

This starts a local ethereum network on localhost:9545. Also note the mnemonic on the bottom, you can use it to import the generated accounts into metamask. Now in the truffle console run:

migrate --reset

You should see something like this:

The above command will also generate a node_config.json configuration file which we will use later for running the parsec node.

Launching the node

Leave the truffle console running, open a new terminal tab and cd into ParsecLabsRepos. Now run:

git clone https://github.com/parsec-labs/parsec-node.git
cd parsec-node/
yarn

Now start the node with:

DEBUG=parsec,parsec:tx,parsec:period node index.js --config=../parsec-contracts/node_config.json

Should look something like this:

Now you need to buy a slot to become a validator on your chain. This means we have to interact with the bridge contract. You can do this in remix or you can use the web-ui.

Setting up remix

First install remixd, which will allow remix to access your local files. Then run this in your parsec-contracts folder:

remixd -s .

Now go to remix. In the upper left corner you will see a button like this:

Click this to connect remix to your contracts folder. Then in the left-most column, navigate to /localhost/contracts/ParsecBridge.sol. Now remix should compile your contract. Then in the upper right, click run and under environment select Web3 Provider. In the popup enter http://localhost:9545. Now you can load the ParsecBridge at address given by the truffle console when we ran migrations and can call functions on the contract.

Web-UI

For supporting functions, the easiest way to interact with your contract is with the parsec-bridge-ui. In the ParsecLabsRepos folder, clone the web-ui repo:

git clone https://github.com/parsec-labs/parsec-bridge-ui.git
cd parsec-bridge-ui/
npm install

Now find your bridge address in the truffle console output and run this command:

NETWORK_ID=4447 BRIDGE_ADDR={your bridge address} yarn run start

You should now be able to visit the web-ui at http://localhost:1234. Now in metamask, select Costum RPC for the network provider and connect to http://localhost:9545. Then restore accounts from the seed given by the truffle console earlier. You should see some ether on this account.

Now to become a validator, notice the message left by the node when we started it. There you can see the parameters you need to register your node as a validator. Fill the form on the web-ui with this data, mine looks like this:

Then submit the transaction and you should be a validator now. Now go back to the node and restart it, the validator warning should be gone now.

Populating the blockchain

We now have a basic setup, but it would be nice to have some transactions in our blockchain. This is what we will do next.

Clone this wiki locally