2

I am very new to creating blockchain dapps, so some guidance would be appreciated. I am conceptualizing how to approach creating a private blockchain so that users can communicate about the status of a project that they are working on using Ethereum. For example, say there is a shared text file (this does not have to be a large .txt file) that has some instructions for a project (it could be any project) that each user is given access to as a team. Given this shared resource with instructions, users can make changes where needed, and then when they are finished, the timestamp and hashed identity of the user is recorded to show that their side of the project is completed. Everyone in the private blockchain would see this. My questions are as follows:

(1) How could Ethereum be used to approach this?

(2) I am used to writing code in Java, but I also code in C++ and JavaScript. Could Java be used to write smart contracts for something like this, or would another programming language be better?

(3) How could I eventually develop a frontend application that could be used by each user to track the status of each person's contribution? Since web servers are centralized, would I need to use something like IPFS? I do not understand how to create a user interface or if Ethereum provides this sort of thing.

I know that these are general questions, but I am just needing to be pointed in the right direction with some of these ideas and/or directed to some similar GitHub projects that are not overly difficult to use. Again, advice would be appreciated.

2

Ethereum is not very suitable for storing files or almost any reasonable amounts of text data. The costs of using the contracts would be too high. At most you should store a little bit of text and some numbers. Ethereum is mostly designed for storing the logic and not much of data.

In theory you can use any programming language to write your code as long as there exists a converter/wrapper into something the Ethereum blockchain understands. Most of the popular programming languages most likely have some sort of framework for writing smart contracts, but unsure which ones have what. The most straightforward is of course to write everything in Solidity directly.

Ethereum does not provide user interfaces. Those you have to write with external tools. The most popular combination is probably Metamask (for communicating with the blockchain) and web3js (for the UI).

  • Thank you for helping me to think through this. Just to clarify, so if I wanted to upload say a PDF or .txt that could be accessible for all users to look at in the UI (and then for them to comment on completing tasks associated with that pdf or .txt to output a string of some sort saying what was done), would I use Ethereum for that? I am confused in terms of how I would go about loading a pdf or .txt and then add a contract with updated string statements from users using that private blockchain. That would be done with the smart contract code, correct? – reverb1010 Aug 29 '18 at 18:32
  • Basically you'd need to use something like IPFS for the file storage and store the reference hash only in Ethereum. You can build your logic around the IPFS hash - that's cheap enough to store and to handle in smart contracts with other user logic. – Lauri Peltonen Aug 29 '18 at 18:39
  • That is helpful, thank you. So where do I develop the smart contract that will provide the functionality for users to communicate and update the progress? That is not in IPFS, correct? Basically, this would just have the user name, the hash information, and then return a string of whatever the users entered. That is all I would need it to do. – reverb1010 Aug 29 '18 at 21:51
  • Probably easiest is to write it in Solidity. After that you deploy it to the Ethereum blockchain. – Lauri Peltonen Aug 30 '18 at 5:30
  • Is there any way to reduce the cost of storing a string in solidity? I am using ganache and I do not know if the gas will be enough for that. I am having to store about a sentence worth of characters for each client, and then broadcast those messages to all the users on that private blockchain I have created with a javascript UI. – reverb1010 Sep 2 '18 at 2:19
0

First write a smart contract in solidity.

pragma solidity ^0.4.17;

contract TestMethod{
   string public name = "Reverb";

   function updateName(string _name) public{
       name = _name;
   }
}

This compile it and generate wrapper classes with the help of below commands. Use solidity compiler first and execute command it will give you one bin and one abi file.

>> solc TestMethod.sol --bin --abi --optimize -o ./

Use web3j wrapper file generator and with the help of abi and bin file, execute the below command.

>> web3j solidity generate TestMethod.bin TestMethod.abi -o . -p org.web3j.samp
le

You will get a java wrapper class like this.

package org.web3j.sample;

import java.math.BigInteger;
import java.util.Arrays;
import java.util.Collections;
import org.web3j.abi.TypeReference;
import org.web3j.abi.datatypes.Function;
import org.web3j.abi.datatypes.Type;
import org.web3j.abi.datatypes.Utf8String;
import org.web3j.crypto.Credentials;
import org.web3j.protocol.Web3j;
import org.web3j.protocol.core.RemoteCall;
import org.web3j.protocol.core.methods.response.TransactionReceipt;
import org.web3j.tx.Contract;
import org.web3j.tx.TransactionManager;

/**
 * <p>Auto generated code.
 * <p><strong>Do not modify!</strong>
 * <p>Please use the <a href="https://docs.web3j.io/command_line.html">web3j command line tools</a>,
 * or the org.web3j.codegen.SolidityFunctionWrapperGenerator in the 
 * <a href="https://github.com/web3j/web3j/tree/master/codegen">codegen module</a> to update.
 *
 * <p>Generated with web3j version 3.4.0.
 */
public class TestMethod extends Contract {
    private static final String BINARY = "60c0604052600660808190527f526576657262000000000000000000000000000000000000000000000000000060a090815261003e9160009190610051565b5034801561004b57600080fd5b506100ec565b828054600181600116156101000203166002900490600052602060002090601f016020900481019282601f1061009257805160ff19168380011785556100bf565b828001600101855582156100bf579182015b828111156100bf5782518255916020019190600101906100a4565b506100cb9291506100cf565b5090565b6100e991905b808211156100cb57600081556001016100d5565b90565b6102a1806100fb6000396000f30060806040526004361061004b5763ffffffff7c010000000000000000000000000000000000000000000000000000000060003504166306fdde03811461005057806384da92a7146100da575b600080fd5b34801561005c57600080fd5b50610065610135565b6040805160208082528351818301528351919283929083019185019080838360005b8381101561009f578181015183820152602001610087565b50505050905090810190601f1680156100cc5780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b3480156100e657600080fd5b506040805160206004803580820135601f81018490048402850184019095528484526101339436949293602493928401919081908401838280828437509497506101c39650505050505050565b005b6000805460408051602060026001851615610100026000190190941693909304601f810184900484028201840190925281815292918301828280156101bb5780601f10610190576101008083540402835291602001916101bb565b820191906000526020600020905b81548152906001019060200180831161019e57829003601f168201915b505050505081565b80516101d69060009060208401906101da565b5050565b828054600181600116156101000203166002900490600052602060002090601f016020900481019282601f1061021b57805160ff1916838001178555610248565b82800160010185558215610248579182015b8281111561024857825182559160200191906001019061022d565b50610254929150610258565b5090565b61027291905b80821115610254576000815560010161025e565b905600a165627a7a723058202be32a6af265c5583cba0e7c6731a4b971eeac0ec50f7b8aaf89a9e21d33184d0029";

    public static final String FUNC_NAME = "name";

    public static final String FUNC_UPDATENAME = "updateName";

    protected TestMethod(String contractAddress, Web3j web3j, Credentials credentials, BigInteger gasPrice, BigInteger gasLimit) {
        super(BINARY, contractAddress, web3j, credentials, gasPrice, gasLimit);
    }

    protected TestMethod(String contractAddress, Web3j web3j, TransactionManager transactionManager, BigInteger gasPrice, BigInteger gasLimit) {
        super(BINARY, contractAddress, web3j, transactionManager, gasPrice, gasLimit);
    }

    public RemoteCall<String> name() {
        final Function function = new Function(FUNC_NAME, 
                Arrays.<Type>asList(), 
                Arrays.<TypeReference<?>>asList(new TypeReference<Utf8String>() {}));
        return executeRemoteCallSingleValueReturn(function, String.class);
    }

    public RemoteCall<TransactionReceipt> updateName(String _name) {
        final Function function = new Function(
                FUNC_UPDATENAME, 
                Arrays.<Type>asList(new org.web3j.abi.datatypes.Utf8String(_name)), 
                Collections.<TypeReference<?>>emptyList());
        return executeRemoteCallTransaction(function);
    }

    public static RemoteCall<TestMethod> deploy(Web3j web3j, Credentials credentials, BigInteger gasPrice, BigInteger gasLimit) {
        return deployRemoteCall(TestMethod.class, web3j, credentials, gasPrice, gasLimit, BINARY, "");
    }

    public static RemoteCall<TestMethod> deploy(Web3j web3j, TransactionManager transactionManager, BigInteger gasPrice, BigInteger gasLimit) {
        return deployRemoteCall(TestMethod.class, web3j, transactionManager, gasPrice, gasLimit, BINARY, "");
    }

    public static TestMethod load(String contractAddress, Web3j web3j, Credentials credentials, BigInteger gasPrice, BigInteger gasLimit) {
        return new TestMethod(contractAddress, web3j, credentials, gasPrice, gasLimit);
    }

    public static TestMethod load(String contractAddress, Web3j web3j, TransactionManager transactionManager, BigInteger gasPrice, BigInteger gasLimit) {
        return new TestMethod(contractAddress, web3j, transactionManager, gasPrice, gasLimit);
    }
}

Further you can deploy the contract with the deploy() method and use updateName() method for updating the data. For more information, please refer to this blog.

https://medium.com/coinmonks/ethereum-blockchain-hello-world-smart-contract-with-java-9b6ae2961ad1

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.