I. Installation
- Prepare environment
- Install nodejs
- Download from the official site
- Install web3
- npm install web3
- Install Ethereum – TestRpc
- npm install -g ethereumjs-testrpc
- Install solidity
- npm install -g solc
- Install nodejs
- Checking
- node -v
- npm -v
- solcjs –version
- Create contract in solidity:
- create file BIoT.sol in folder /Volumes/JetDrive130/LEARNING/Solidity/
- The content of file
-
//Created by Henry Pham
pragma solidity >=0.5.0 <0.7.0;contract BIoTStorage {
string public farmlogo;
string public farmname;
string public foodname;
string public farmaddress;
string public position;
string public humidity;
string public temperature;
function setFarmLogo(string memory _farmLogo) public {
farmlogo = _farmLogo;
}
function setFarm_FoodInfor(string memory _farmname, string memory _farmaddress, string memory _position, string memory _foodname, string memory _humidity, string memory _temperature) public {
farmname = _farmname;
farmaddress =_farmaddress;
position = _position;
foodname = _foodname;
humidity = _humidity;
temperature = _temperature;
}
function getFarmLogo() public view returns (string memory){
return farmlogo;
}function getFarm_FoodInfor() public view returns (string memory _fn, string memory _fa, string memory _position, string memory _foodname, string memory _humidity, string memory _temperature){
_fn = farmname;
_fa =farmaddress;
_position =position;
_foodname =foodname;
_humidity =humidity;
_temperature =temperature;
return (_fn, _fa, _position, _foodname,_humidity, _temperature);
}}
II. Compiling
- Solidity
- Theory: solc greeter.sol –bin –abi –optimize -o <output-dir>/
- Practice: solcjs /Volumes/JetDrive130/LEARNING/Solidity/BIoT.sol –bin –abi –optimize -o /Volumes/JetDrive130/Learning/Solidity/
- To generate the wrappers you run
- Install web3j CLI:
- Down load from: (or wget) https://github.com/web3j/web3j/releases/download/v4.1.0/web3j-4.1.0.tar
- export PATH=$PATH:~/web3j-4.1.0/bin
- Theory:
web3j solidity generate /path/to/<smart–contract>.bin /path/to/<smart–contract>.abi –o /path/to/src/main/java –p com.your.organisation.name
- Practice:
- Install web3j CLI: