This tutorial provides a step by step guide to deploy a smart contract in the LACChain networks orchestrated by LACNet. You do not need any programming or blockchain experience to complete this tutorial. It is just the first step. If you have previously developed smart contracts for Ethereum or Hyperledger Besu, the only difference here is that the GAS price is zero in LACChain Networks. Our [GAS Distribution Mechanism] keeps a smart-contract-based accounting of the GAS used by each node. In the [Pro-Testnet](link), every entity can use as much GAS as needed. In the [Mainnet Omega](link) the amount of GAS per block your node can consume is determined by the membership chose. Making your smart contracts ready for our GAS Distribution Mechanism only requires [a couple of small changes](link) from your Ethereum smart contracts, that you can see in this tutorial.
The first step is to run a writer node in one of the LACChain networks. We recommend that you start by running a node in the Pro-Testnet. You can install a node in the Pro-Testnet [using Ansible](link), [using Dockers](link), and [using Kubernetes](link). Remember that you also need to complete the [Permissioning Process](link) for your node to be permissioned. After your node has been successfully deployed and permissioned, you will have to wait until the node has synced the entire blockchain and is up to date. You can see when that happens by [MORE].
Check that you have the environment variable WRITER_KEY set on your node:
$ env
In case you do not have the WRITER_KEY variable in your environment, please set this variable with the content of the file /lacchain/data/key.
$ export WRITER_KEY=PRIVATE_KEY //where PRIVATE_KEY is content of /lacchain/data/key
Enter the node’s console and run the following commands
$ cd /root/lacchain/gas-relay-signer
$ systemctl import-environment WRITER_KEY
$ service relaysigner start
Verify relaysigner is working well, go to the log file.
$ cd /root/lacchain/gas-relay-signer/log
$ tail -100 idbServiceLog.log
The first lines should be something like this:
General Logger: 2021/11/23 16:19:19 main.go:60: smartContract=0x3B62E51E37d090453600395Ff1f9bdf4d7398404 AgentKey=/home/adrian/.ethereum/keystore/UTC--2020-06-26T19-00-23.241896464Z--bceda2ba9af65c18c7992849c312d1db77cf008e
General Logger: 2021/11/23 16:19:19 main.go:65: Init RelaySigner
General Logger: 2021/11/23 16:19:19 client.go:46: Connected to Ethereum Node: ws://localhost:4546
That means relaysigner is configured and working well.
Next step is set your node address (by default) that will be permissioned to consume GAS. Please, run these commands on your node and copy your node address:
$ cd /root/lacchain/data
$ cat nodeAddress
Now send an email with the subject “Permissioning node in Pro-Testnet” to [email protected] writing as content your node address and the name of your organization. When you receive the response, your node will be ready to send transactions or deploy contracts.
A simple contract will be deployed which records a hash associated with the end user who sent the transaction. For this part you will need to have nodejs installed. Check whether node is installed on your local computer by running the following command:
$ node --version
If the command does not return a version number, download and install node by following the instructions for the operating system you use on the Node.js website. Node version should be at least v14. Check whether yarn is installed on your local computer by running the following command:
$ yarn --version
If the command does not return a version number, download and install yarn by running the following command:
$ npm install -g yarn
Please clone this repository. It contains all the code necessary to deploy a contract and send a transaction.
$ git clone https://github.com/lacchain/samples.git
Now download all the necessary dependencies.
$ cd samples
$ yarn install
After having downloaded the project dependencies, we are going to configure the local variables, for which make sure you have the IP of your writer node, as well as the private key of the end user with which you will deploy the contract.
$ cd samples
Open a text editor and change the RPC_URL value to the IP of your writer node in /samples/keys.js file, keep port 80 set.
module.exports = {
RPC_URL:"http://1.1.1.1:80"
}
Save the changes. Now change the Web3 parameter to the IP of your writer node in /samples/web3.js file. Also, keep port 80 set.
const Web3 = require('web3')
const web3 = new Web3('http://1.1.1.1:80')
module.exports = web3
Next, set your user final address and private key, these values will be of the end user who will send the transaction.
const addressFrom = '0x173CF75f0905338597fcd38F5cE13E6840b230e9' //SET USER ADDRESS HERE
const privKey = Buffer.from('0E273FFD9CF5214F7D6ADE5D1ABFD6D101B648AF12BC2DE6AC4AFCB4DB805CD3', 'hex') //SET USER FINAL PRIVATE_KEY HERE
Finally, set your node address and a timestamp which is 1 day ahead of the current date. To know how to get the timestamp, you can go to this link,
const nodeAddress = "0xd00e6624a73f88b39f82ab34e8bf2b4d226fd768" //SET YOUR NODE ADDRESS HERE
const expiration = 1736394529 //SET TIMESTAMP HERE
To deploy the contract, please run the following command:
$ cd samples
$ node deployPublicSmartContract.js
If everything goes well, you will get the address of the contract deployed.
To deploy another smart contract, for example an ERC20 token.
$ cd samples
Open a text editor and uncomment erc20 constant in /samples/deployPublicSmartContract.js file, comment other bytecodes.
//const simpleStorageByteCode = "0x6080604...030033";
const erc20 = "0x6080604...030033"
//const simpleHashByteCode = "0x6080604...030033"
Check our terms and conditions, privacy policies, and cookies policy.
Copyright 2022 © All rights Reserved. Designed by LACNet