Ledgerium Blockchain: Public Transactions using Truffle with Ledgerium Box

Rahul Golash
Aug 23 · 6 min read

Ledgerium Box is a skeleton project which is published on Truffle Box, to help developers to get on to the Ledgerium Blockchain and interact with its Invoice smart contract. It uses Truffle Framework to deploy the Invoice Smart Contract on to any of the specified node of Ledgerium Blockchain’s Testnet i.e. Toorak or Flinders.

This article explains how to use Ledgerium Box to execute public transactions on ‘ Invoice’ Smart Contract.

It is to be noted that the user has to ‘unlock’ the Ledgerium account, which is used to send the transactions with its password beforehand.

Prerequisites

Do read Install Ledgerium Core and Setup Development environment to connect with Ledgerium Blockchain to have your environment ready before continuing with this article.

Setting Up

npx truffle unbox ledgerium-io/truffle-ledgerium-box

Alternatively, you can install truffle globally and then run the unbox command.

npm install -g truffle 
truffle unbox ledgerium-io/truffle-ledgerium-box

Run the development console. This will instantiate local truffle-ganache set up for you to test that Truffle is working properly.

➜ truffle-ledgerium-box git:(master) truffle develop Truffle Develop started at http://127.0.0.1:9545/ Accounts: 
(0) 0xef759369e2b95b207fcc9ec2a6925fe3f8945f8f
(1) 0x1cdca97f55f90955189852e817a8417104355665
(2) 0x76266fbc8d8afb7be87ce6477664034d1edaaabf
(3) 0xa4382db1a2967c638b6c26b7e4dac9f0eaafe0fb
(4) 0xd81c256b771b2825850e39e2d7efb8ab4ca44772
(5) 0xfd3f2266b1ae447759de8cc25fab1ebf9f71056d
(6) 0x51d4c9a16807155b26ca63b4f1c45f2e0ab9632f
(7) 0x8e4f9563aa743f1357fe111527d5fc6ce847ec27
(8) 0xff22823bac227789d4881b94817370f8c74cbe71
(9) 0x247161402686101d02d15545608caac644ceec43
Private Keys:
(0) 20a139ed2023c910d54b2ce7fb4377d81dd3471d6f16f27116c39c6184a3fd7c (1) f2edc70b6e292b3be76c488c80cfde773056255ce99a4049f34cf56ca2f66bdb (2) 1c085631a00fb3e7fe3ec1e28939d9c15bb8037aa688a4466de10c4d579b3552 (3) 5bd12224a91405747042bc2b448b4c5a3e2f7ac67d9e6c08bde28f6ce77fbb53 (4) fb6faa037bbd270bb0071eb1422217d1ce44babaed31e267244aa2a59007edba (5) 1b25cd046989cb15846d07778424d587e5e423a0a095a67da2d7e0169cadd887 (6) 999bc70ce21f1207a375f940d6b098ba8ecf693d7d0954cae4808373dd2e23f2 (7) cb0ca8cbba05598f8367de98d45817d726cadd7a49641942148fe448e50aa772 (8) ec040f4412856089ce2d16ad0dc91d23000580eb053d22611a96927449f07911 (9) 0a4703afc8386d46b5464da9bf97c9f3a7bb81b028b666294ef44b3b4117af2b
Mnemonic: doll manual expose ghost cabin mosquito release fashion grain people issue build ⚠️ Important ⚠️ : This mnemonic was created for you by Truffle. It is not secure. Ensure you do not use it on production blockchains, or else you risk losing funds. truffle(develop)>
  • Ensure that you’re able to both compile, test, and finally migrate your contracts to your local ganache set up.
compile 
test
migrate

If everything looks good, you can exit the Truffle console with `.exit.`. This makes the truffle setup complete.

  • Next is to connect with Ledgerium blockchain. Edit `truffle-config.js` file under truffle-ledgerium-box folder.
module.exports = {
networks: {
flinders: {
host: ‘flinders01.ledgerium.io’, //flinders Testnet, ‘toorak.ledgerium.net’ for toorak
port: 8545, //Need to check with RPC port of the specific ledgerium node, default 8545
network_id: ‘2019’, // Match any network id
from: ‘0xef759369e2b95b207fcc9ec2a6925fe3f8945f8f’
}
},
solc: {
// Turns on the Solidity optimizer. For development the optimizer’s quite helpful, just remember to be careful, and potentially turn it off, for live deployment and/or audit time. For more information, see the Truffle 4.0.0 release notes.
// https://github.com/trufflesuite/truffle/releases/tag/v4.0.0
optimizer: {
enabled: true,
runs: 200
}
}
};

In this article, we are using one of the flinders block producers nodes i.e. flinders01.ledgerium.io which is running RPC port 8545. Set the `from` field to “0xef759369e2b95b207fcc9ec2a6925fe3f8945f8f, we are using this account for this article.

Take the test XLG from Ledgerium Faucet

  • Migrate your invoice contract to the Ledgerium Flinders network node.
➜ truffle-ledgerium-box git:(master) ✗ truffle migrate — network flinders⚠️ Important ⚠️
If you’re using an HDWalletProvider, it must be Web3 1.0 enabled or your migration will hang.
Starting migrations…
======================>
Network name: ‘flinders’
> Network id: 2020
> Block gas limit: 9007199254740000
2_deploy_contracts.js
=====================
Going to connect to http://flinders01.ledgerium.io:8545Replacing ‘Invoice’
— — — — — — — — — -
> transaction hash: 0x07dfbc952706346fabf255abf063eee389dd834bb50fc0395c416e0508a64eb2> Blocks: 1 Seconds: 8
> contract address: 0xBeA37B161d94b2c3140376E264929BC21B0A1518
> account: 0xd34fC4abe46BfDb1939e00b3dcd5B27911a6C05d
> balance: 2.98471562
> gas used: 521367
> gas price: 20 gwei
> value sent: 0 ETH
> total cost: 0.01042734 ETH
> Saving migration to chain.
> Saving artifacts
— — — — — — — — — — — — — — — — — — -
> Total cost: 0.01042734 ETH
Summary
=======
> Total deployments: 1
> Final cost: 0.01042734 ETH

0xBeA37B161d94b2c3140376E264929BC21B0A1518 is the Invoice Smart contract address on Ledgerium Flinders Testnet.

  • Connect to Ledgerium Blockchain Flinders Testnet with one of the Block Producer’s nodes flinders01.ledgerium.io. Additionally, the Ledgerium account which needs to be used to execute public transactions has to be imported as the node’s native account. Below are the steps showing, how to connect to the remote node on RPC http://flinders01.ledgerium.io:8545 and import the account using its private key, along with some password (which needs to be remembered for later usages too).
> geth attach http://flinders01.ledgerium.io:8545
Welcome to the Geth JavaScript console!
instance: Geth/flinders01-69c30/v1.8.12-stable-46338e95(quorum-v2.2.1)/linux-amd64/go1.11.10
coinbase: 0x1a67eea756b9c074219dbbd1a68b7a6919412645
at block: 19010 (Wed, 04 Sep 2019 00:38:13 AEST)
datadir: /eth
modules: admin:1.0 debug:1.0 eth:1.0 istanbul:1.0 net:1.0 personal:1.0 rpc:1.0 txpool:1.0 web3:1.0
> personal.importRawKey(“20a139ed2023c910d54b2ce7fb4377d81dd3471d6f16f27116c39c6184a3fd7c”,”password”)
“0xef759369e2b95b207fcc9ec2a6925fe3f8945f8f”
>
  • Since the transactions will be sent unsigned by the private key, the account needs to be unlocked before executing it. It can be done 2 ways.

Go to geth console

geth attach http://flinders01.ledgerium.io:8545
Welcome to the Geth JavaScript console!
instance: Geth/flinders01-69c30/v1.8.12-stable-46338e95(quorum-v2.2.1)/linux-amd64/go1.11.10
coinbase: 0x1a67eea756b9c074219dbbd1a68b7a6919412645
at block: 29279 (Wed, 04 Sep 2019 14:53:58 AEST)
datadir: /eth
modules: admin:1.0 debug:1.0 eth:1.0 istanbul:1.0 net:1.0 personal:1.0 rpc:1.0 txpool:1.0 web3:1.0
> personal.unlockAccount(“0xef759369e2b95b207fcc9ec2a6925fe3f8945f8f”,”somepassword”)
true
>

Or Unlock it programmatically by connecting the node with web3 and call

web3.eth.personal.unlockAccount("0xef759369e2b95b207fcc9ec2a6925fe3f8945f8f","somepassword")

Now, the Ledgerium account is ready to be used for the rest of the workflow.

module.exports.ACCOUNT = process.env.ACCOUNT || "0xef759369e2b95b207fcc9ec2a6925fe3f8945f8f"module.exports.CONTRACT = process.env.CONTRACT || "0xBeA37B161d94b2c3140376E264929BC21B0A1518"

Run Node Express Backend Server

  • First, ensure that you’re in the truffle-ledgerium-box/server folder.
  • Run the npm install command. This will install all the necessary node dependencies.
npm install
  • Run the node express back end server in dev mode. This will bring up the express server on PORT 9086.
npm run dev
  • Make a test get call to express server. This will return “Hello from the API message”.
http://localhost:9086

Run React Front End Application

  • First, ensure that you’re in the truffle-ledgerium-box/client folder.
  • Run the npm install command. This will install all the necessary node dependencies.
npm install

Run the web application in dev mode. This will up bring the react front end application on PORT 4000.

npm run dev

Check out to the following URL to access the web application.

http://localhost:4000

Execute Transactions

Here are the steps to interact with the Ledgerium Blockchain using this skeleton project.

  • Confirm whether 0xEF759369e2B95B207FCC9Ec2a6925Fe3F8945f8f account is hosted on flinders01.ledgerium.io node by selecting “Get Accounts”.
  • Select ‘Public Transactions’ option. In this screen, the rest of the steps will be executed.
  • Try adding a new invoice to the smart contract ‘Invoice’

Invoice ID — ‘1001’ and Invoice Hash — ‘0xb27af35c588047a3c32f

This pop-up shows that the new invoice is added to the smart contract. Below is the log from the server console.

Dealing with Invoice Smart Contract Address: “0xBeA37B161d94b2c3140376E264929BC21B0A1518"

Invoice Id ‘1001, Invoice Hash ‘0xb27af35c588047a3c32f

Tx Result {
"blockHash":"0x615e025ecbff9f84d948f279084ccf911125b60d12da5b4bf3c0f1795d1df107",
"blockNumber":19785,
"contractAddress":null,
"cumulativeGasUsed":86798,
"from":"0xef759369e2b95b207fcc9ec2a6925fe3f8945f8f",
"gasUsed":86798,
"logsBloom":"0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
"status":true,
"to":"0xbea37b161d94b2c3140376e264929bc21b0a1518",
"transactionHash":"0x10b2a6fd653c4a4909ab72f0b226d5d9538e8c738c57d681ac709001dadfa00e",
"transactionIndex":0,
"events":{}
}
  • Now, you can simply verify whether any invoice existed with the hash ‘0xb27af35c588047a3c32f
  • Now, next is to enquire the invoice ID to the blockchain with the given hash 0xb27af35c588047a3c32f

This pop-up shows that the invoice ‘1001’ is corresponding to the given hash exists in the smart contract.

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