How to set up Obyte devnet for rapid development

in #obyte5 years ago (edited)

Obyte devnet is a simplified and sped up version of the Obyte cryptocurrency network ideal for developing Autonomous Agents and bots. This tutorial focuses on setting up devnet on a local machine for developing Autonomous Agents

obyte-devnet.png

Developing cryptocurrency applications and smart contracts is typically time consuming task due to the long confirmation times of transactions posted on testnets or mainnets. Obyte is among the fastest cryptocurrencies when it comes to the time required for global consensus, it's about 10 minutes at the time of writing this article, still when you have to develop a program that posts transactions on the ledger, waiting for confirmations every time you want to test a single transaction is really only for very very patient people.

Obyte devnet

Obyte devnet started as a separate project but some of its concepts has been integrated into the Obyte core libraries since the addition of the Autonomous Agents. The main idea is to be able to run a complete Obyte network on a single development machine with fast confirmation times. To achieve that, the devnet has only one witness instead of 12 and one hub to which wallets can connect to. The witness posts every minute and since there is only one, it immediately makes earlier transaction stable.

Let's jump right into it how to set it up.

We are going to install the followings:

  • Obyte devnet
  • Oscript backend
  • Oscript frontend
  • Obyte devnet GUI wallet

System requirements:

  • git - to fetch devnet and Oscript source code
  • npm - to run devnet
  • yarn - to run Oscript backend and frontend
  • Linux - the devnet init script is a simple bash script but it should be fairly easy to manually execute the steps on other operating systems.
  • docker - if you chose to run the GUI wallet in docker

Installing devnet

First get the source code and check out the aa branch. The aa branch contains the latest features for autonomous agent development.

git clone https://github.com/pmiklos/obyte-devnet.git
cd obyte-devnet
git checkout aa

Next, install and configure devnet. Start with fetching nodejs dependencies:

npm install

Then run the init script which copies the pre-generated configuration files for the devnet witness including the keys of the witness to make the devnet more predictable eg. the witness address and pairing code will always be the same. Next generate the genesis unit and the first asset, the blackbytes. Creating the blackbytes asset is optional, but it doesn't hurt to have it.

The genesis and blackbytes steps ask for password, simply press an Enter. There is an empty password set for the devnet witness.

npm run init
npm run genesis
npm run blackbytes

At this point the devnet hub and witness are configured and ready to be launched. Start the hub:

npm run hub

Then open a new console and start the witness (press Enter when it asks for password):

npm run witness

You can now open a browser and go to http://localhost:8080/ to see the Obyte devnet DAG explorer. New units should be posted by the witness every minute.

Installing Oscript editor

Oscript editor is recommended to install if you work with Autonomous Agents since it makes authoring agents a lot easier by providing syntax highlighting and code completion, validation and deployment.

Open another console and install the Oscript backend

git clone https://github.com/byteball/oscript-editor-backend.git
cd oscript-editor-backend
echo "devnet=1" > .env
yarn install

The .env file configures the Oscript backend for devnet. You can start the Oscript backend with

yarn start

Now that the backend is running, let's install the Oscript frontend which will provide you with a web based editor to develop Autonomous Agents in Oscript language.

git clone https://github.com/byteball/oscript-editor.git
cd oscript-editor
yarn

Run the Oscript editor in development mode:

yarn run serve

It is going to print the URL where the editor is available, but most likely it will be http://localhost:8081/ if you have the devnet explorer already running on port 8080.

At this point you are ready to develop Obyte Autonomous Agents and deploy them on your local devnet.

Installing devnet GUI wallet the hard way

So we have the whole Obyte infrastructure running on our laptops, but one thing is missing: the Obyte GUI wallet to access and use the devnet. You can build the testnet wallet from source by following the instructions on the obyte-gui-wallet readme section. To build the wallet with Autonomous Agents support, you will have to use the aa branch.

git clone https://github.com/byteball/obyte-gui-wallet.git
cd obyte-gui-wallet
git checkout aa
echo "devnet=1" > .env

and then follow the steps in the readme. Tip: use the same NW.js and Nodejs versions as recommended in the guide to avoid unnecessary problems.

Installing devnet GUI wallet the easy way

If you are familiar with docker, there is an simpler way to run the devnet wallet. It has the advantage of easily creating as many throwaway wallets you need for testing. You can build your own image or simply download a prebuilt one from docker hub at pmiklos/obyte-devnet-wallet. Let's use the prebuilt image:

docker run -d --rm \
    --name obyte-devnet-wallet \
    --network=host \
    -e DISPLAY=$DISPLAY \
    -v /tmp/.X11-unix:/tmp/.X11-unix \
    -v obyte-devnet-wallet-data:/obyte \
    pmiklos/obyte-devnet-wallet:2.7.2-aa

That's it. The above command should launch the GUI wallet for the devnet. I recommend to create a script or a bash alias for the above command to make it easy to launch the devnet wallet. I, for example, use the following bash function to easily create new devnet wallets:

function obyte-devnet-wallet() {
        local name="${1:-default}"
        docker run -d --rm --name obyte-devnet-wallet-$name --network=host -e DISPLAY=$DISPLAY -v /tmp/.X11-unix:/tmp/.X11-unix -v obyte-devnet-wallet-$name-data:/obyte pmiklos/obyte-devnet-wallet:2.7.2-aa
}

Then launching a devnet wallet is as simple as:

obyte-devnet-wallet mylittlewallet

Final tips

Funding the GUI wallet
In devnet, the witness holds all the funds initially. You can distribute those funds to any address by using the RPC interface of the witness exposed on port 6612:

$ curl --data '{"jsonrpc":"2.0", "id":1, "method":"sendtoaddress", "params":["7AAUNXYL3G5RB73TKQPCPGC6FLRM2G6", 12345678] }' http://127.0.0.1:6612

See more info in obyte-devnet GitHub page (check the aa branch for the latest development version).

Start a clean state
Occasionally you want to destroy the whole devnet state and start with a clean DAG. You can easily do that by removing the witness and hub configuration folders and re-running the initialization, genesis creation and blackbytes asset definition steps. On Linux, it would be (stop the witness and hub first):

rm -rf ~/.config/obyte-devnet-*
npm run init
npm run genesis
...
Sort:  

Congratulations @pmiklos! You received a personal award!

Happy Birthday! - You are on the Steem blockchain for 1 year!

You can view your badges on your Steem Board and compare to others on the Steem Ranking

Vote for @Steemitboard as a witness to get one more award and increased upvotes!