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:
- Set up Dijets TestNet on Decypher
- Generate a 24 word mnemonic phrase through DijetsJS
- Derive external Utility Chain addresses through DijetsJS
- Get DJT from Dijets Faucet
- Send DJT via ethersJS
- Examine the resulting transaction on Dijets Unified Explorer
- 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.
_10import { Mnemonic } from "dijets"_10const mnemonic: Mnemonic = Mnemonic.getInstance()_10const strength: number = 256_10const wordlist = mnemonic.getWordlists("english") as string[]_10const m: string = mnemonic.generateMnemonic(strength, randomBytes, wordlist)_10console.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.
_34import HDNode from "dijets/dist/utils/hdnode"_34import { Dijets, Mnemonic, Buffer } from "dijets"_34import { EVMAPI, KeyChain } from "dijets/dist/apis/evm"_34import { ethers } from "ethers"_34_34const ip: string = "testnet.dijets.io"_34const port: number = 443_34const protocol: string = "https"_34const networkID: number = 5_34const dijets: Dijets = new Dijets(ip, port, protocol, networkID)_34const utilitychain: EVMAPI = dijets.UtilityChain()_34_34const mnemonic: Mnemonic = Mnemonic.getInstance()_34const 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"_34const seed: Buffer = mnemonic.mnemonicToSeedSync(m)_34const hdnode: HDNode = new HDNode(seed)_34_34const keyChain: KeyChain = utilitychain.newKeyChain()_34_34const uAddresses: string[] = []_34_34for (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}_34console.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:
- 0x8db97C7cEcE249c2b98bDC0226Cc4C2A57BF52FC
- 0x3507A1131aba9D07714b76Eb8a245F434198690B
- 0xa14dFb7d8593c44a47A07298eCEA774557036ff3
you might update the example script above to the following:
_24const uAddresses: string[] = []_24const privateKeys: string[] = []_24for (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}_24console.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.
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.
Check the Transaction Details#
The txID, 0x9ae2666d9337e4c99d5e762900c26a3d9701b2269565e305b68640bf7ef46abd
,
can be seen here on Dijets Utility Chain Explorer.
Get the Balance#
We can also use the Dijets Explorer to get the balance for the 1st address 0x8db97C7cEcE249c2b98bDC0226Cc4C2A57BF52FC.
Alternatively, we can use ethersJS to get the balance.
_15const ethers = require("ethers")_15const network = "https://testnet.dijets.io/ext/bc/C/rpc"_15const provider = ethers.getDefaultProvider(network)_15const address = "0x8db97C7cEcE249c2b98bDC0226Cc4C2A57BF52FC"_15_15const 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_15main()
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_28import { ethers } from "ethers"_28// network: using the Dijets testnet_28const network = "https://testnet.dijets.io/ext/bc/C/rpc"_28// provider: establish and RPC connection to the network_28const provider = new ethers.providers.JsonRpcProvider(network)_28_28// Sender private key:_28// corresponding address 0x8db97C7cEcE249c2b98bDC0226Cc4C2A57BF52FC_28let privateKey =_28 "cd30aef1af127208c627593537e162ecf5aad1d4ab4ea98ed2f96ad4e47006dc"_28// Create a wallet instance_28let wallet = new ethers.Wallet(privateKey, provider)_28// Receiver Address_28let receiverAddress = "0x3507A1131aba9D07714b76Eb8a245F434198690B"_28// DJT amount to send_28let amountInDjtx = "0.05"_28// Create a transaction object_28let tx = {_28 to: receiverAddress,_28 // Convert currency unit from ether to wei_28 value: ethers.utils.parseEther(amountInDjtx),_28}_28// Send a transaction_28wallet.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.
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.
_15const ethers = require("ethers")_15const network = "https://testnet.dijets.io/ext/bc/C/rpc"_15const provider = ethers.getDefaultProvider(network)_15const address = "0x3507A1131aba9D07714b76Eb8a245F434198690B"_15_15const 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_15main()
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.
The balance is correct and the address is the 1st derived address.
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.