Skip to content

Instantly share code, notes, and snippets.

@cgcardona
Last active May 12, 2021 21:06
Show Gist options
  • Select an option

  • Save cgcardona/0c2f19e496d8e8f76bac9113b193ce4c to your computer and use it in GitHub Desktop.

Select an option

Save cgcardona/0c2f19e496d8e8f76bac9113b193ce4c to your computer and use it in GitHub Desktop.

If I am looking to build and deploy dApps on the AVAX network, where do you suggest I start?

Backend

First you want to set up your development environment. For that you'll want to install GoLang version >= 1.15.5 and set up it's $GOPATH. Next install AvalancheGo which is the official node implementation of the Avalanche network.

Now you can fire up a 5 node staking network:

./avash
Config file set: /Users/username/.avash.yaml
Avash successfully configured.
avash> runscript scripts/five_node_staking.lua
RunScript: Running scripts/five_node_staking.lua
RunScript: Successfully ran scripts/five_node_staking.lua

Now that you have an Avalanche network running you can interact via curl w/ the JSON RPC. Check the docs for example requests/responses.

curl can be cumbersome. To make your workflow smoother try the POSTMAN Collection with full support for the entire RPC of the X-Chain, C-Chain and P-Chain.

Frontend

You have the backend up and running so now you need to get the front end running. This consists of NodeJS, Javascript and Typescript. For that first you want to install nvm which is the node version manager.

wget -qO- https://raw.githubusercontent.com/nvm-sh/nvm/v0.35.3/install.sh | bash

Install the LTS (long-term support) version of NodeJS, which at the time of writing is v14.16.0. This includes javascript and npm, the node package manager, for installing nodejs packages.

nvm install v14.16.0
# set as your default nodejs version
nvm default 14.16.0

Next install ts-node which is a TypeScript execution and REPL for node.js, with source map support.

# With TypeScript.
npm install -g typescript
npm install -g ts-node

To use ts-node

# Execute a script as `node` + `tsc`.
ts-node script.ts

# Starts a TypeScript REPL.
ts-node

Now you want AvalancheJS, the javascript/typescript client for the Avalanche Network. To build the library locally

git clone https://github.com/ava-labs/avalanchejs.git
cd avalanchejs
npm install
npm run build
npm test

If you don't want to build it locally and just want to install it you can use npm install avalanche -s.

There are dozens of example scripts to test which you can run with ts-node. First make sure that a local network is running via avash.

ts-node examples/info/peers.ts
[
  {
    ip: '127.0.0.1:57292',
    publicIP: '127.0.0.1:9655',
    nodeID: 'NodeID-NFBbbJ4qCmNaCzeW7sxErhvWqvEQMnYcN',
    version: 'avalanche/1.2.0',
    lastSent: '2021-02-16T16:24:42-08:00',
    lastReceived: '2021-02-16T16:24:42-08:00'
  },
  ...
]

If needed you can run the Web Wallet and Faucet on localhost.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment