Hey! These docs are for version 0.18.0, which is no longer officially supported. Click here for the latest version, 0.21.0!

Connect to a Network

The Dash test network

The purpose of this tutorial is to walk through the steps necessary to access the network.

Overview

Platform services are provided via a combination of HTTP and gRPC connections to DAPI, and some connections to an Insight API. Although one could interact with DAPI by connecting to these directly, or by using DAPI-client, the easiest approach is to use the JavaScript Dash SDK.

Prerequisites

📘

Minimum Supported Version

As of Dash Platform v0.16, NodeJS v12 or higher must be used

Connect via Dash SDK

1. Install the Dash SDK

The JavaScript SDK package is available from npmjs.com and can be installed by running npm install dash (from the command line):

npm install dash

2. Connect to Dash Platform

Create a file with the following contents. Then run it by typing node <file.js> (from the command line):

📘

As of Dash Platform v0.17.0, the SDK connects to testnet by default.

const Dash = require('dash');

const client = new Dash.Client();

async function connect() {
  return await client.getDAPIClient().core.getBestBlockHash();
}

connect()
  .then((d) => console.log('Connected. Best block hash:\n', d))
  .catch((e) => console.error('Something went wrong:\n', e))
  .finally(() => client.disconnect());

Once this returns successfully, you're ready to begin developing! For details on all SDK options and methods, please refer to the SDK documentation.

Connect Directly to DAPI (Optional)

🚧

Advanced Topic

Normally, the Dash SDK, dapi-client, or another library should be used to interact with DAPI. This may be helpful for debugging in some cases, but generally is not required.

The example below demonstrates retrieving the hash of the best block hash directly from a DAPI node via command line and several languages:

curl --request POST \
  --url http://seed-1.testnet.networks.dash.org:3000/ \
  --header 'content-type: application/json' \
  --data '{"method":"getBlockHash","id":1,"jsonrpc":"2.0","params":{"height": 100 }}'
import requests

url = "http://seed-1.testnet.networks.dash.org:3000/"

payload = "{\"method\":\"getBlockHash\",\"id\":1,\"jsonrpc\":\"2.0\",\"params\":{\"height\":100}}"
headers = {'content-type': 'application/json'}

response = requests.request("POST", url, data=payload, headers=headers)

print(response.text)
require 'uri'
require 'net/http'

url = URI("http://seed-1.testnet.networks.dash.org:3000/")

http = Net::HTTP.new(url.host, url.port)

request = Net::HTTP::Post.new(url)
request["content-type"] = 'application/json'
request.body = "{\"method\":\"getBlockHash\",\"id\":1,\"jsonrpc\":\"2.0\",\"params\":{\"height\":100}}"

response = http.request(request)
puts response.read_body

Did this page help you?