Let’s Play With DCTL and the Transaction Explorer

Before we dive into actually creating smart contracts and making blockchain magic, it’ll be worth taking ONE MORE POST to learn about the Dragonchain command line tool and a simple block explorer app we can use to see our transactions happening.

What’s the DCTL command line tool good for?

The DCTL tool from Dragonchain is available as a nodejs package and is installed using npm, like this:

npm install -g dctl

This will install it globally so you can use it anywhere.

Once installed, try running the dctl command by itself:

$ dctl
Usage: dctl [options] [command]

Options:
  -V, --version       output the version number
  -h, --help          output usage information

Commands:
  status|s            Get the status of your chain
  transaction|t       Commands for interfacing with transactions
  transactionType|tt  Commands for interfacing with transaction types
  contract|c          Commands for interfacing with contracts
  block|b             Commands for interfacing with blocks
  creds|k             Manage dragonchain credentials on this machine
  interchain|i        Manage interchains configured for a dragonchain
  help [cmd]          display help for [cmd]

You’ll see we have a number of options for interacting with our Dragonchain node from checking the status to creating and retrieving transactions and blocks and beyond.

Before we can do all of that, though, we’ll need to setup our credentials file so that the DCTL tool knows which chain we’re talking to.

Assuming you have all the credentials you were given when you created your L1 node on the Dragonchain console website, you can create your credentials file using the sample format and instructions available here.

Then let’s check the status of our node with the “dctl status” command to make sure we’re wired up correctly:

{
  "status": 200,
  "response": {
    "id": "uDVMagYWemvWH281ry7zdX6kap7e3dBZhJjuCbDyh4qU",
    "level": 1,
    "url": "<your endpoint>",
    "hashAlgo": "blake2b",
    "scheme": "trust",
    "version": "4.0.1",
    "encryptionAlgo": "secp256k1"
  },
  "ok": true
}

Sweet. Now let’s get to the good stuff.

Creating Transactions (and Transaction Types)

Before we can actually create a transaction on our Dragonchain, we need to create a Transaction Type. This keeps things all nice and organized in our chain.

One note about transaction types that the developers have reiterated: be aware that when you DELETE a transaction type from your chain, you’ll no longer be able to query for transactions based on that transaction type.

The transactions WILL still exist, of course, but you’ll have to pull them by ID if you need them once you’ve deleted the transaction type itself.

Okay, back to the good stuff.

Let’s create a transaction TYPE to test with:

dctl transactionType create TestTransactionType

(Or we can use the shorthand version:)

dctl tt c TestTransactionType

{
  "status": 200,
  "response": {
    "success": true
  },
  "ok": true
}

Awesome. Now let’s create a real transaction using our new type (be aware that this will debit your available transaction credits on the Dragonchain console!):

dctl t c TestTransactionType 'Hello world!'

Could not parse JSON for payload, sending raw data instead...
{
  "status": 201,
  "response": {
    "transaction_id": "70689b8b-4d22-4159-a801-d9d17a2592b0"
  },
  "ok": true
}

Okay, so it fussed at me about sending plain text instead of a JSON object string that could be parsed. Fine, fine. For now, let’s GET that new transaction from the blockchain using the transaction_id we were given back:

dctl t g 70689b8b-4d22-4159-a801-d9d17a2592b0

{
  "status": 200,
  "response": {
    "version": "2",
    "dcrn": "Transaction::L1::FullTransaction",
    "header": {
      "txn_type": "TestTransactionType",
      "dc_id": "uDVMagYWemvWH281ry7zdX6kap7e3dBZhJjuCbDyh4qU",
      "txn_id": "70689b8b-4d22-4159-a801-d9d17a2592b0",
      "block_id": "27662642",
      "timestamp": "1570551425",
      "tag": "",
      "invoker": ""
    },
    "payload": "Hello world!",
    "proof": {
      "full": "IJtJ0R5+akyeOQHrC0YN4cQbzPmikLvBPZQI4iDg6y0=",
      "stripped": "MEUCIQC0hg6tOnb0S/yFd9zqQANckDHNtUh7fiNdjReXNidxqwIgY69wXIA+B+bXQeIXBc2Nv49npH9gqc9m3Sz4DLOkvIc="
    }
  },
  "ok": true
}

Wicked! So we’ve now created our very first Dragonchain transaction type and transaction. Pretty easy all things said and done.

But it’d be a pain in the ass to have to look up every transaction manually as we’re testing, so let’s look at a better way of doing it.

Using the Dragonchain Block Explorer

Early on in my adventures with Dragonchain, I started working on a simple block explorer so I could keep an eye on my validation (level 2) node. Now that I’m working on L1 (business node) stuff, I’ve added some functionality so that we can peek at our transactions very easily. It looks like this.

Viewing a Dragonchain Business Node transaction using the simple block explorer available from the community

Nifty.

You can download and start running the block explorer from the community GitHub a few of us started recently.

Get the Dragonchain Block Explorer

I highly recommend you get that up and running as we continue building things. I have a feeling it’ll be VERY handy to be able to quickly and easily see our transactions….

Okay, okay. NOW let’s move on to the basics of using Docker (in the next post).

Until next time,
John

Leave a comment

Your email address will not be published. Required fields are marked *