Skip to content
Snippets Groups Projects
Commit 6ad4f520 authored by mi3u17's avatar mi3u17
Browse files

changes to Application.java and README file

parent 6cd99678
Branches
No related tags found
No related merge requests found
#MARINOS ILIADIS #MARINOS ILIADIS
##Eclipse Gradle project ##Eclipse Gradle project
## How to import the project into Eclipse ## How to import the project into Eclipse
Open Eclipse -> Go to File -> Open Project From File System -> Show other specialised import wizard-> Gradle -> Existing Gradle -> sample-project-gradle-master Open Eclipse -> Go to File -> Open Project From File System -> Show other specialised import wizard-> Gradle -> Existing Gradle -> sample-project-gradle-master
Import this project to Eclipse (I use Eclipse Oxygen 3A) as an existing grandle project. Import this project to Eclipse (I use Eclipse Oxygen 3A) as an existing grandle project.
Our eclipse project uses the web3j library. Java library to interact with Ethereum blockchain and solidity smart contracts Our eclipse project uses the web3j library. Java library to interact with Ethereum blockchain and solidity smart contracts
...@@ -30,10 +32,20 @@ https://docs.web3j.io/command_line.html ...@@ -30,10 +32,20 @@ https://docs.web3j.io/command_line.html
OR OR
Using the MyEtherWallet website to create an Ethereum wallet file
https://www.myetherwallet.com/
### Manage account
By using MetaMask Google Chrome Extension By using MetaMask Google Chrome Extension
check how it works here: check how it works here:
https://metamask.io/ https://metamask.io/
OR
By visiting Etherscan's website and add the addres to th search bar
https://etherscan.io/
### Request some ether ### Request some ether
Import the wallet file into the MetaMask account. Import the wallet file into the MetaMask account.
...@@ -58,6 +70,7 @@ https://infura.io/register.html ...@@ -58,6 +70,7 @@ https://infura.io/register.html
In this prototype java dapp we deploy our contract on the Ropsten Test Network In this prototype java dapp we deploy our contract on the Ropsten Test Network
### Solidity compiler and Java wrappers ### Solidity compiler and Java wrappers
A) Compiling Solidity source code A) Compiling Solidity source code
1) npm install -g solc 1) npm install -g solc
2) solc or solcjs <contract>.sol --bin --abi --optimize -o <output-dir>/ 2) solc or solcjs <contract>.sol --bin --abi --optimize -o <output-dir>/
...@@ -73,7 +86,6 @@ Solidity smart contract wrappers ...@@ -73,7 +86,6 @@ Solidity smart contract wrappers
Link: Link:
https://docs.web3j.io/smart_contracts.html#smart-contract-wrappers https://docs.web3j.io/smart_contracts.html#smart-contract-wrappers
### Viewing logs on blockchain ### Viewing logs on blockchain
Logback configuration is provided in the project dependencies giving the opportunity to logging of protocol Logback configuration is provided in the project dependencies giving the opportunity to logging of protocol
...@@ -83,7 +95,7 @@ To enable change the following line in the logback configuration: ...@@ -83,7 +95,7 @@ To enable change the following line in the logback configuration:
```xml ```xml
<logger name="org.web3j.protocol" level="DEBUG"/> <logger name="org.web3j.protocol" level="DEBUG"/>
``` ```
### Extra Dependencties (check build.grandle) ### Extra Dependencies (check build.grandle)
Assert java 3.10.0 Assert java 3.10.0
Javatuples 1.2 Javatuples 1.2
......
...@@ -49,14 +49,14 @@ public class Application { ...@@ -49,14 +49,14 @@ public class Application {
Web3j web3j = Web3j.build(new HttpService("https://ropsten.infura.io/fIJ2SJzY4NaKGKA9Ryxp")); //Need to add you Infura token. Sent to you by email when you register. Use the one for Ropsten. Web3j web3j = Web3j.build(new HttpService("https://ropsten.infura.io/fIJ2SJzY4NaKGKA9Ryxp")); //Need to add you Infura token. Sent to you by email when you register. Use the one for Ropsten.
log.info("Connected to Ethereum client version: " + web3j.web3ClientVersion().send().getWeb3ClientVersion()); log.info("Connected to Ethereum client version: " + web3j.web3ClientVersion().send().getWeb3ClientVersion());
//Load your Credentials and Ethereum wallet //Load your Credentials and Ethereum wallet file
Credentials credentials = Credentials credentials =
WalletUtils.loadCredentials( WalletUtils.loadCredentials(
"1234", //Need to add the password you have set for this wallet file "1234", //Need to add the password you have set for this wallet file
"C:\\Users\\Marinos\\Desktop\\test_gitlab\\db-blockchain-privacy\\sample-project-gradle-master\\wallet\\UTC--2018-06-16T11-26-34.298000000Z--fc87f1c9459a4e15731d004ebd923821f89aa007.json"); //Need to add the path of your generated Ethereum wallet file (.json). "C:\\Users\\Marinos\\Desktop\\test_gitlab\\db-blockchain-privacy\\sample-project-gradle-master\\wallet\\UTC--2018-06-16T11-26-34.298000000Z--fc87f1c9459a4e15731d004ebd923821f89aa007.json"); //Need to add the path of your generated Ethereum wallet file (.json).
log.info("Credentials loaded"); //Check the folder wallet inside the project folder to find an existing wallet file. log.info("Credentials loaded"); //Check the folder wallet inside the project folder to find an existing wallet file.
//Send 1 wei from your address to another address //Send 1 Wei from your address to another address
log.info("Sending 1 Wei (" log.info("Sending 1 Wei ("
+ Convert.fromWei("1", Convert.Unit.ETHER).toPlainString() + " Ether)"); + Convert.fromWei("1", Convert.Unit.ETHER).toPlainString() + " Ether)");
TransactionReceipt transferReceipt = Transfer.sendFunds( TransactionReceipt transferReceipt = Transfer.sendFunds(
...@@ -98,14 +98,17 @@ public class Application { ...@@ -98,14 +98,17 @@ public class Application {
* Print results * Print results
*/ */
//Deploy our smart contract - db.sol //Deploy our smart contract - Acladv.sol
log.info("Deploying smart contract - ACL-BaseData"); log.info("Deploying smart contract - ACL-BaseData");
Acladv contract = Acladv.deploy( Acladv contract = Acladv.deploy(
web3j, credentials, web3j, credentials,
ManagedTransaction.GAS_PRICE, Contract.GAS_LIMIT).send(); ManagedTransaction.GAS_PRICE, Contract.GAS_LIMIT).send();
//Get address of the deployed smart contract //Get address of the deployed smart contract
String contractAddress = contract.getContractAddress(); String contractAddress = contract.getContractAddress();
log.info("Smart Contract deployed to address: " + contractAddress);
//Check the contract on Etherscan website
log.info("View contract at https://ropsten.etherscan.io/address/" + contractAddress);
// String adro = contract.getDeployedAddress("1"); // String adro = contract.getDeployedAddress("1");
// String adrt = contract.getDeployedAddress("2"); // String adrt = contract.getDeployedAddress("2");
// String adrtr = contract.getDeployedAddress("3"); // String adrtr = contract.getDeployedAddress("3");
...@@ -114,8 +117,8 @@ public class Application { ...@@ -114,8 +117,8 @@ public class Application {
// log.info("Smart Contract deployed to address: " + adrt); // log.info("Smart Contract deployed to address: " + adrt);
// log.info("Smart Contract deployed to address: " + adrtr); // log.info("Smart Contract deployed to address: " + adrtr);
// log.info("Smart Contract deployed to address: " + adrf); // log.info("Smart Contract deployed to address: " + adrf);
log.info("Smart Contract deployed to address: " + contractAddress); // log.info("Smart Contract deployed to address: " + contractAddress);
//log.info("View contract at https://ropsten.etherscan.io/address/" + contractAddress); // log.info("View contract at https://ropsten.etherscan.io/address/" + contractAddress);
//Add user to the access control list //Add user to the access control list
TransactionReceipt userone = contract.addUser("0xFC87F1c9459A4e15731d004EbD923821f89AA007").send(); TransactionReceipt userone = contract.addUser("0xFC87F1c9459A4e15731d004EbD923821f89AA007").send();
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment