Ledgerium Blockchain: How to use Ledgerium Utility

Rahul Golash
Sep 6 · 6 min read

This repository is written for users to understand how to interact with Ledgerium Blockchain Testnets e.g. toorak, flinders. It provides various utility functions to test different scenarios on Ledgerium Blockchain e.g. deploy public and private smart contracts, execute transactions using web3js. The web3.js is a collection of packages which allow you to interact with a Ledgerium node, local or remote, using an HTTP or IPC connection.

User can check the package.json and can understand the required libraries.

"dependencies": {
"ethjs-unit": "npm:ethjs-unit-ledgerium",
},
"resolutions": {
"ethjs-unit": "npm:ethjs-unit-ledgerium",
"request": "2.88.0",
"quorum-js": "npm:quorum-xlg-js"
}

‘XLG’ is the native cryptocurrency used on the Ledgerium blockchain network and it is needed while interacting with Ledgerium Blockchain. web3.js package uses ethjs-unit whenever it needs to deal with the denomination. The default ethjs-unit package has ‘ether’ as its native currency which is being overridden for Ledgerium to ‘XLG’. In turn, Ledgerium has published ethjs-unit-ledgerium with XLG as native denomination and user has to use it in its development environment using yarn package.

// name your Ledgerium account, will often use it
led_account = eth.accounts[0];
// check your balance (denominated in XLG)
balance = web3.fromWei(eth.getBalance(led_account), "XLG");

Clone the repo and install the project

git clone https://github.com/ledgerium-io/ledgeriumutility.git
cd ledgeriumutility
yarn install

Specifications

The ledgeriumutility can be used with different switches

protocol

  • http
  • ws

hostname

  • toorak.ledgerium.io <If the user want to connect to toorak specific mother block producer node.>
  • flinders0X.ledgerium.io <If the user want to connect to flinders specific mother block producer node where X can be 1,2,3 or 4>

port

  • 9000 for Websocket, to be used with ws option
  • 8545 for HTTP, to be used with http option

usecontractconfig

While using this repository, the user can deploy fresh contract with smart contract code made available at $ledgeriumutility/contracts/. Once deployed, the address of the deployed smart contract is saved in $ledgeriumutility/keystore/contractsconfig.json. If the user wants to execute further transactions afterwards, this flag can be set to true.

readkeyconfig

If keystore\privatekey.json needs to be used for accounts and respective their private keys. Since transactions will be signed, private keys are needed. For example, two accounts are shown here.

{
"0xef759369e2b95b207fcc9ec2a6925fe3f8945f8f","20a139ed2023c910d54b2ce7fb4377d81dd3471d6f16f27116c39c6184a3fd7c",
"0x1cdca97f55f90955189852e817a8417104355665","f2edc70b6e292b3be76c488c80cfde773056255ce99a4049f34cf56ca2f66bdb"
}

Make sure that these accounts have XLG balance else, you can go to Ledgerium Faucet and ask for some test XLG.

Below screenshot shows that the account “0xef759369e2b95b207fcc9ec2a6925fe3f8945f8f has 3 XLG balance.

Usages

  • This is to generate the public/private key combination against the input of mnemonics on any Ledgerium Blockchain.

node index.js createPrivatePublicCombo=<mnemonics string>

➜ ledgeriumutility git:(master) ✗ node index.js createPrivatePublicCombo="some random mnemonics1"mnemonics: some random mnemonics1privateKey: 0x350691399ca8a580b246105b415c8a0bb6d3da73086185101ff911c768bcf081publicKey: 942780b1a7d4632d9f95e6581692b3df80791c02f1675ee3dfd40970f5a6ffa1894bd52455986006a12d29ded3d7ff8e22c926f963af72373ecaf62530ac49c9Ledgerium Account Address:3a55f310f9e263ebe92ccc6ee448773d1219fc02
  • Import account to the given Block Producer of Ledgerium Blockchain

node index.js protocol=<http/ws> hostname=<Block Producer node IP address> port=<rpc/ws port> testPersonalImportAccount=<private key> <password>

➜ ledgeriumutility git:(master) ✗ node index.js protocol=http hostname=138.197.193.201 port=8545 readkeyconfig=true testPersonalImportAccount=5bd12224a91405747042bc2b448b4c5a3e2f7ac67d9e6c08bde28f6ce77fbb53,passwordThere are 10 Ledgerium accounts & private keys in the privatekey fileNo of Ledgerium accounts on the node 5Account 0xa4382db1a2967c638b6c26b7e4dac9f0eaafe0fb got imported!FromAccount 0xa4382db1a2967c638b6c26b7e4dac9f0eaafe0fb has balance of 0 xlg
  • Deploy sample ERC20 smart contract name LedgeriumToken on Ledgerium Blockchain and run test cases

It will deploy a fresh LedgeriumToken smart contract on the blockchain. The LedgeriumToken code contract is available at $ledgeriumutility/contracts

node index.js protocol=<http/ws> hostname=<Block Producer node IP address> port=<rpc/ws port> readkeyconfig=true testLedgeriumToken

➜ ledgeriumutility git:(master) ✗ node index.js protocol=http hostname=138.197.193.201 port=8545 readkeyconfig=true testLedgeriumTokenThere are 10 Ledgerium accounts & private keys in the privatekey filegasPrice 0x746a528800FromAccount 0xef759369e2b95b207fcc9ec2a6925fe3f8945f8f has balance of 4.808389 xlgnonceToUse 4LedgeriumToken deployedAddress 0x6a63e2Be9fB8dd54DCCA5e4cB5a457D8CC80dcA2totalSupply 20000000000000000symbol XLGdecimals 8balanceOf 20000000000000000 of account 0xef759369e2b95b207fcc9ec2a6925fe3f8945f8fbalanceOf 0 of account 0x1cdca97f55f90955189852e817a8417104355665gasPrice 0x746a528800FromAccount 0xef759369e2b95b207fcc9ec2a6925fe3f8945f8f has balance of 3.972618 xlgnonceToUse 5TransactionLog for ledgeriumToken transfer - 0xd8900331dbd7aed7c575647083a3e67585ac1fb603d571181193e8672cc3d710balanceOf 123 of account 0x1cdca97f55f90955189852e817a8417104355665balanceOf 19999999999999877 of account 0xef759369e2b95b207fcc9ec2a6925fe3f8945f8f
  • Transfer XLG from one account to another account on Ledgerium Blockchain

node index.js protocol=<http/ws> hostname=<Block Producer IP address> port=<rpc/ws port> transferXLG=<private key of ‘from’ account>,<to account address>,<XLG amount>

➜ ledgeriumutility git:(master) ✗ node index.js protocol=http hostname=138.197.193.201 port=8545 transferXLG=20a139ed2023c910d54b2ce7fb4377d81dd3471d6f16f27116c39c6184a3fd7c,0x76266fbc8d8afb7be87ce6477664034d1edaaabf,2gasPrice 0x746a528800FromAccount 0xEF759369e2B95B207FCC9Ec2a6925Fe3F8945f8f has balance of 4.891174 xlgnonceToUse 8Now FromAccount 0xEF759369e2B95B207FCC9Ec2a6925Fe3F8945f8f has balance of 2.880674 xlgTransactionLog for transfer - 0xa357cdf7f3822025c42f05ef5a695dd1c7cc18221f5f30d463ee1458338e05bf
  • Add Invoice hash to Invoice smart contract on Ledgerium Blockchain

It will deploy a fresh Invoice smart contract on the blockchain. Invoice contract code is available at $ledgeriumutility/contracts

node index.js protocol=<http/ws> hostname=<Block Producer node IP address> port=<rpc/ws port> readkeyconfig=true testInvoice=<InvoiceID>,<Invoice Hash>

➜ ledgeriumutility git:(master) ✗ node index.js protocol=ws hostname=138.197.193.201 port=9000 readkeyconfig=true testInvoice=3004,0xcB4a457D8CC80dcA2There are 10 Ledgerium accounts & private keys in the privatekey filegasPrice 0x746a528800FromAccount 0xef759369e2b95b207fcc9ec2a6925fe3f8945f8f has balance of 1001.43453 xlgnonceToUse 26Invoice deployedAddress 0x0186f46D16a8276e6A920A51fD7EeCBbcadCb66aisHashExists returns falsegasPrice 0x746a528800FromAccount 0xef759369e2b95b207fcc9ec2a6925fe3f8945f8f has balance of 1001.1457425 xlgnonceToUse 27TransactionLog for Invoice Setvalue - 0x2343d4a57d6199315f5b94ddcf8e3b1a7ce5e31668e94e7ea58988862c0fddf1isHashExists returns truegetInvoiceID returns 3004
  • Deploy Greeter smart contract on Ledgerium Blockchain

Greeter contract is available at $ledgeriumutility/contracts

node index.js protocol=<http/ws> hostname=<Block Producer node IP address> port=<rpc/ws port> readkeyconfig=true testGreeter

➜ ledgeriumutility git:(master) ✗ node index.js protocol=ws hostname=138.197.193.201 port=9000 readkeyconfig=true testGreeterThere are 10 Ledgerium accounts & private keys in the privatekey filegasPrice 0x746a528800FromAccount 0xef759369e2b95b207fcc9ec2a6925fe3f8945f8f has balance of 1002.2829375 xlgnonceToUse 18Greeter deployedAddress 0x568CD96190569fAb2211c554e5BC58Bf2eB80190getMyNumber 0gasPrice 0x746a528800FromAccount 0xef759369e2b95b207fcc9ec2a6925fe3f8945f8f has balance of 1002.165957 xlgnonceToUse 19TransactioHash for Greeter Setvalue - 0x287e3af53a681a844538006ad3bff42b8b488556b6855ddfc54f10d7e5efb431Input value for TransactioHash 0x287e3af53a681a844538006ad3bff42b8b488556b6855ddfc54f10d7e5efb431 is 499getMyNumber after 499
  • Deploy SimpleStorage smart contract on Ledgerium Blockchain

Another sample contract code named SimpleStorage is available at $ ledgeriumutility/contracts

node index.js protocol=<http/ws> hostname=<Block Producer node IP address> port=<rpc/ws port> readkeyconfig=true testSimpleStorage

➜ ledgeriumutility git:(master) ✗ node index.js protocol=ws hostname=138.197.193.201 port=9000 readkeyconfig=true testSimpleStorageThere are 10 Ledgerium accounts & private keys in the privatekey filegasPrice 0x746a528800FromAccount 0xef759369e2b95b207fcc9ec2a6925fe3f8945f8f has balance of 1002.078528 xlgnonceToUse 22SimpleStorage deployedAddress
0x56aa35D33f769F000d6c5686432Bea72b02784cb
getMyNumber 101gasPrice 0x746a528800FromAccount 0xef759369e2b95b207fcc9ec2a6925fe3f8945f8f has balance of 1002.0254815 xlgnonceToUse 23TransactioHash for SimpleStorage set - 0xe0f85a87013bf084f95482ab1f9815ae05cfe3748d46caffeaf176933f533e7aInput value for TransactioHash 0xe0f85a87013bf084f95482ab1f9815ae05cfe3748d46caffeaf176933f533e7a : 499get after 499
  • Subscribe the ‘newBlockHeaders’ event on Ledgerium Blockchain

If user wants to subscribe for the next block header, one can use it like below

node index.js protocol=<http/ws> hostname=<Block Producer node IP address> port=<rpc/ws port> readkeyconfig=true testNewBlockEvent

➜ ledgeriumutility git:(master) ✗ node index.js protocol=ws hostname=138.197.193.201 port=9000 readkeyconfig=true testNewBlockEventThere are 10 Ledgerium accounts & private keys in the privatekey file
{
parentHash:'0xb58af9a23aff27894feefa87547ab45744ef91f0aa3467a4a14e04b9968214e7',
sha3Uncles:'0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347',
miner: '0x1a67eeA756B9c074219dBBd1a68b7A6919412645',
stateRoot:'0x9b64b84ba11a7a9f8bbca992fc966484322f6f2977e2d377e435ae4336cc4138',
transactionsRoot:'0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421',
receiptsRoot:'0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421',
logsBloom:
'0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000',
difficulty: '1',
number: 45507,
gasLimit: 9007199254740000,
gasUsed: 0,
timestamp: 1567653978,
extraData:'0xd98301080c846765746889676f312e31312e3130856c696e7578000000000000f90164f854941a67eea756b9c074219dbbd1a68b7a69194126459486dc44a5ae35a09a62585f2e3de29f14dce2ff2c94c1836760988668eea5275cd562755ec0b82cef9294cb680d316b281aebb68e73e813b7a53ec93c8f05b841cb1b29403e9d8de3e2108a5e3083d809b8ccd7048c56aadd617851aad5f1ef741c1c9e45395a5bb8f048d8bef599e03204802c65b38597cbd977d69d8c25ed9c01f8c9b841dd0e5ecf1cb9f9b07954c123d81e819fece0b6cb167ec4f5aeb87780b72242046018ce2a95d64f3ccc798f5300f0df9b4d8cf244aec027e631215215eb4096e400b84150672ac1efe5669a74d0786f74b18260dcfd3ded3b038bddab8e5c6feb4f2eca40d45bd0918866258af29da75b47166984a9939a4273715f529fd2ac7fba1e9e01b841a15932e295040b7feaf97adf494db5aca040b6128d740d8d296139b440acf005490548850aa8bbfe823e4b2fb50a48f4b631c0551758e486760366eda401977600',
mixHash:'0x63746963616c2062797a616e74696e65206661756c7420746f6c6572616e6365',
nonce: '0x0000000000000000',
hash:'0xe3ae778e3f1dbe7f3006be2a2a593c3ddd6d095ee7d7d978358fd279c6cd0b8b',
size: undefined
}

If one needs to develop and transact on custom developed smart contract after deploying, the code has to be compiled and .bin and .abi files are to be made available at ./build/contracts folder.

  • Solidity compiler to compile smart contract, to be deployed and transact
solc - overwrite - gas - bin - abi - optimize-runs=200 -o ./build/contracts ./contracts/contractname.sol```Output filescontractname.bin and contractname.abi are available in `./build/contracts` folder. If the file does not exist, the program will throw "file not found!" error
  • Precompiled smart contracts are deployed from the genesis block using — bin-runtime
solc --overwrite --gas --bin-runtime --abi --optimize-runs=200 -o ./build/contracts ./contracts/contractname.sol

Output files contractname.bin and contractname.abi are available in ./build/contracts folder. If the file does not exist, the program will throw “file not found!” error. This option will be useful when the user wants to set up a new Blockchain setup. Obviously, this option won’t be useful since testnets are already created and genesis block is already mined.

ledgerium.io

The official news source of the ledgerium Blockchain

Rahul Golash

Written by

VP Emerging Tech and Chief Blockchain Architect @Ledgerium.io

ledgerium.io

The official news source of the ledgerium Blockchain

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade