Home

Reference workflow for Dijets TestNet

Introduction#

Dijets TestNet is the test network for Dijets. It can be used to test DApps and/or smart contracts after they've been developed and implemented locally. (You can use Dijets-Up to test things locally.) Dijets TestNet is typically running the same DijetsNodeGo version as Dijets Mainnet, but sometimes it is also running an unreleased version. In general, you can expect Dijets TestNet's behavior to be about the same as Dijets Mainnet. Dijets Explorer and Wallet are both preconfigured to work with Dijets Testnet upon choosing.

This tutorial demonstrates a reference workflow for Dijets TestNet to show how it can be used. We'll cover the following in the process:

  1. Set up Dijets TestNet on Decypher
  2. Generate a 24 word mnemonic phrase through DijetsJS
  3. Derive external Utility Chain addresses through DijetsJS
  4. Get DJT from Dijets Faucet
  5. Send DJT via ethersJS
  6. Examine the resulting transaction on Dijets Unified Explorer
  7. Use a Private Key derived from a mnemonic phrase to sign into Dijets wallet

Set up Dijets Network on Decypher#

  • Network Name: Dijets Utility Chain
  • RPC URL: https://testnet.dijets.io/ext/bc/C/rpc
  • ChainID: 98119
  • Symbol: DJT

Generate a Mnemonic#

To begin, we'll create a mnemonic phrase with DijetsJS. Mnemonic phrases enable us to encode strong security into a human-readable phrase. DijetsJS currently supports 6 languages including English, Spanish, Italian, French, Korean, and Simplified Chinese. (More languages will be added to the library in the coming weeks)

First, generate a 24 word english BIP39-compliant mnemonic via DijetsJS.


_10
import { Mnemonic } from "dijets"
_10
const mnemonic: Mnemonic = Mnemonic.getInstance()
_10
const strength: number = 256
_10
const wordlist = mnemonic.getWordlists("english") as string[]
_10
const m: string = mnemonic.generateMnemonic(strength, randomBytes, wordlist)
_10
console.log(m)
_10
// "tumble abuse basic ecology accuse window poem weekend annual oil emerge alley retreat rabbit seed advance define off amused board quick wealth peasant disorder"

Derive Addresses#

After generating a mnemonic we can use DijetsJS to derive BIP32-compliant hierarchical deterministic (HD) Keypairs.


_34
import HDNode from "dijets/dist/utils/hdnode"
_34
import { Dijets, Mnemonic, Buffer } from "dijets"
_34
import { EVMAPI, KeyChain } from "dijets/dist/apis/evm"
_34
import { ethers } from "ethers"
_34
_34
const ip: string = "testnet.dijets.io"
_34
const port: number = 443
_34
const protocol: string = "https"
_34
const networkID: number = 5
_34
const dijets: Dijets = new Dijets(ip, port, protocol, networkID)
_34
const utilitychain: EVMAPI = dijets.UtilityChain()
_34
_34
const mnemonic: Mnemonic = Mnemonic.getInstance()
_34
const m: string =
_34
"tumble abuse basic ecology accuse window poem weekend annual oil emerge alley retreat rabbit seed advance define off amused board quick wealth peasant disorder"
_34
const seed: Buffer = mnemonic.mnemonicToSeedSync(m)
_34
const hdnode: HDNode = new HDNode(seed)
_34
_34
const keyChain: KeyChain = utilitychain.newKeyChain()
_34
_34
const uAddresses: string[] = []
_34
_34
for (let i: number = 0; i <= 2; i++) {
_34
const child: HDNode = hdnode.derive(`m/44'/120'/0'/0/${i}`)
_34
keyChain.importKey(child.privateKey)
_34
const utilitychainAddress = ethers.utils.computeAddress(child.privateKey)
_34
uAddresses.push(utilitychainAddress)
_34
}
_34
console.log(uAddresses)
_34
// [
_34
// '0x8db97C7cEcE249c2b98bDC0226Cc4C2A57BF52FC',
_34
// '0x3507A1131aba9D07714b76Eb8a245F434198690B',
_34
// '0xa14dFb7d8593c44a47A07298eCEA774557036ff3'
_34
// ]

Generate Private Keys from a Mnemonic#

As long as you have the mnemonic phrase, you can re-generate your private keys and the addresses they control.

For example, if you want to generate the private keys for the first 3 address in the Utility Chain keychain:

you might update the example script above to the following:


_24
const uAddresses: string[] = []
_24
const privateKeys: string[] = []
_24
for (let i: number = 0; i <= 2; i++) {
_24
// Deriving the _i_th external BIP44 Utility Chain address
_24
const child: HDNode = hdnode.derive(`m/44'/120'/0'/0/${i}`)
_24
keyChain.importKey(child.privateKey)
_24
// Converting the BIP44 addresses to hexadecimal addresses
_24
const utilitychainAddress = ethers.utils.computeAddress(child.privateKey)
_24
privateKeys.push(child.privateKey.toString("hex"))
_24
uAddresses.push(utilitychainAddress)
_24
}
_24
console.log({ uAddresses, privateKeys })
_24
// {
_24
// uAddresses: [
_24
// '0x8db97C7cEcE249c2b98bDC0226Cc4C2A57BF52FC',
_24
// '0x3507A1131aba9D07714b76Eb8a245F434198690B',
_24
// '0xa14dFb7d8593c44a47A07298eCEA774557036ff3'
_24
// ],
_24
// privateKeys: [
_24
// 'cd30aef1af167238c627593537e162ecf5aad1d4ab4ea98ed2f96ad4e47006dc',
_24
// 'b85479b26bc8fbada4737e90ab2133204f2fa2a9ea33c1e0de4452cbf8fa3be4',
_24
// 'c72e18ea0f9aa5457396e3bf810e9de8df0177c8e4e5bf83a85f871512d645a9'
_24
// ]
_24
// }

Get testnet DJT from Dijets Faucet#

We can get 1 DJT from Dijets faucet. Paste the address into Dijets faucet website. These DJT are for Dijets Testnet and have no monetary value.

Requesting DJT

The faucet will send 1 DJT to the address and return a transaction ID (txID). This txID can be used with the Dijets Testnet Explorer to learn more about the transaction.

Receiving DJT

Check the Transaction Details#

The txID, 0x9ae2666d9337e4c99d5e762900c26a3d9701b2269565e305b68640bf7ef46abd, can be seen here on Dijets Utility Chain Explorer.

Transaction details

Get the Balance#

We can also use the Dijets Explorer to get the balance for the 1st address 0x8db97C7cEcE249c2b98bDC0226Cc4C2A57BF52FC.

1st derived address balance

Alternatively, we can use ethersJS to get the balance.


_15
const ethers = require("ethers")
_15
const network = "https://testnet.dijets.io/ext/bc/C/rpc"
_15
const provider = ethers.getDefaultProvider(network)
_15
const address = "0x8db97C7cEcE249c2b98bDC0226Cc4C2A57BF52FC"
_15
_15
const main = async (): Promise<any> => {
_15
provider.getBalance(address).then((balance) => {
_15
// convert a currency unit from wei to ether
_15
const balanceInDjtx = ethers.utils.formatEther(balance)
_15
console.log(`balance: ${balanceInDjtx} DJT`)
_15
// balance: 2 DJT
_15
})
_15
}
_15
_15
main()

Sending DJT#

The faucet sent 1 DJT to the first address we generated. Let's send DJT from the 1st address to the 2nd address.


_28
// import ethers.js
_28
import { ethers } from "ethers"
_28
// network: using the Dijets testnet
_28
const network = "https://testnet.dijets.io/ext/bc/C/rpc"
_28
// provider: establish and RPC connection to the network
_28
const provider = new ethers.providers.JsonRpcProvider(network)
_28
_28
// Sender private key:
_28
// corresponding address 0x8db97C7cEcE249c2b98bDC0226Cc4C2A57BF52FC
_28
let privateKey =
_28
"cd30aef1af127208c627593537e162ecf5aad1d4ab4ea98ed2f96ad4e47006dc"
_28
// Create a wallet instance
_28
let wallet = new ethers.Wallet(privateKey, provider)
_28
// Receiver Address
_28
let receiverAddress = "0x3507A1131aba9D07714b76Eb8a245F434198690B"
_28
// DJT amount to send
_28
let amountInDjtx = "0.05"
_28
// Create a transaction object
_28
let tx = {
_28
to: receiverAddress,
_28
// Convert currency unit from ether to wei
_28
value: ethers.utils.parseEther(amountInDjtx),
_28
}
_28
// Send a transaction
_28
wallet.sendTransaction(tx).then((txObj) => {
_28
console.log(`"tx, https://explorer.dijets.io/tx/${txObj.hash}`)
_28
// A transaction result can be checked on Dijets Utility Chain Explorer with a transaction link which can be obtained here.
_28
})

Verify Success#

We can verify that the transaction, 0xafd787d60483adabb48479de36e83943c374476793a66177be4a1a8601e74414, was successful using the Dijets Testnet Explorer. The transaction can be seen here.

Transaction details

Get the Balance

We can also use the Dijets Explorer to get the balance for the 2nd address—0x3507A1131aba9D07714b76Eb8a245F434198690B.

Alternatively, we can use ethersJS to get the balance.


_15
const ethers = require("ethers")
_15
const network = "https://testnet.dijets.io/ext/bc/C/rpc"
_15
const provider = ethers.getDefaultProvider(network)
_15
const address = "0x3507A1131aba9D07714b76Eb8a245F434198690B"
_15
_15
const main = async (): Promise<any> => {
_15
provider.getBalance(address).then((balance) => {
_15
// convert a currency unit from wei to ether
_15
const balanceInDjtx = ethers.utils.formatEther(balance)
_15
console.log(`balance: ${balanceInDjtx} DJT`)
_15
// balance: 0.02 DJT
_15
})
_15
}
_15
_15
main()

Sign Into the Web Wallet#

Lastly, we can use the mnemonic to generate a private key to access the Dijets Web Wallet. We'll see that it has the DJT balance and that it derives the hexadecimal address from the private key.

Use the private key to access the Web Wallet.

Access the wallet

The balance is correct and the address is the 1st derived address.

Web wallet balance

Summary#

The Dijets Testnet plays a critical role in testing dapps, smart contracts and financial products before deploying to the Mainnet. Tooling like DijetsJS, the public API, faucet, and explorer helps to ensure that your testing and QA environment is close to Mainnet so that you can be confident when you launch on Mainnet.

Resources#

For additional and valuable resources please see below.

Faucet#

The Dijets Faucet can send DJT to Value Chain or Utility Chain addresses for testing purposes. (Testnet Djtx has no value.)

Wallet#

Dijets Web Wallet is a simple, secure, non-custodial wallet for storing Dijets assets. It supports Dijets Mainnet, Dijets TestNet and custom networks.

Explorer#

Dijets Explorer allows you to explore the network, transactions, addresses, smart contracts & much more.