How one can implement blockchain for android development??

0 votes

I have seen many tutorial on blockchain but they all are some how assuming the learner to be web developer or kind of related field. Is there some stuff for android developer to learn so that we can use android studio with blockchain technology.?

Jun 16, 2018 in Blockchain by ariaholic
• 7,340 points

retagged Nov 22, 2018 by Omkar 35 views

1 answer to this question.

0 votes

Essentially you need to understand what is blockchain and how it works? the blockchain is distributed system where there is no central node to handle all transaction. All transaction handled by the miner. The blockchain is the combination of blocks. Each block contains the hash value of the previous block and current block. If previous block hash code changed, current block hash code has to change too. Please see code below to understand simple how blocks interconnected and importance of hash code.

public class Block {

private int previoushash;
private String [] transactions;

private int blockhash;

public Block(int previoushash, String[] transactions) {
    this.previoushash = previoushash;
    this.transactions = transactions;

    Object[] contents = {Arrays.hashCode(transactions), previoushash};
    this.blockhash = Arrays.hashCode(contents);

}


public int getPrevioushash() {
    return previoushash;
}

public String[] getTransactions() {
    return transactions;
}


public int getBlockhash() {
    return blockhash;
}

}

Main.java

public class Main {

ArrayList<Block> blockchain = new ArrayList<>();

public static void main(String [] args) {
    /*
     hash= digital signature

        Each block contains:

            -list of transactions
            -previous hash

            -hash
     * */

    System.out.println("Blochchain test initialized:\n");

    String [] genesisTransactions = {"a send 10 bitcoin to elnur", "b send 3 bitcoin to elnur" , "c send 5 bitcoin to elnur"};
    Block genesisBlock = new Block(0, genesisTransactions);
    System.out.println("Hash of genesis block:");
    System.out.println(genesisBlock.getBlockhash());


    String [] block2transactions = {"elnur send 2 bitcoin to ibm","elnur send 6 bitcoin to sap","elnur send 12 bitcoin to amazon"};
    Block block2 = new Block(genesisBlock.getBlockhash(),block2transactions);
    System.out.println("Hash of block 2:");
    System.out.println(block2.getBlockhash());


    String [] block3transactions = {"elnur send 2 bitcoin to satoshi","satoshi send 1 bitcoin to starbuck"};
    Block block3 = new Block(block2.getBlockhash(),block3transactions);
    System.out.println("Hash of block 3:");
    System.out.println(block3.getBlockhash());

}

}

answered Jun 16, 2018 by charlie_brown
• 7,720 points

Related Questions In Blockchain

0 votes
1 answer

How can Blockchain be implemented for android development?

Essentially you need to understand what is ...READ MORE

answered Aug 10, 2018 in Blockchain by Johnathon
• 9,080 points
26 views
0 votes
1 answer

How can I create a blockchain for keeping records?

​You can use an already existing Blockchain. ...READ MORE

answered Jun 27, 2018 in Blockchain by Christine
• 15,790 points
40 views
0 votes
1 answer

How can I get into the development of blockchain decentralized applications?

try Microsoft Blockchain as a service, they ...READ MORE

answered Jun 29, 2018 in Blockchain by Shashank
• 10,350 points
26 views
0 votes
0 answers
0 votes
1 answer

Truffle tests not running after truffle init

This was a bug. They've fixed it. ...READ MORE

answered Sep 11, 2018 in Blockchain by Christine
• 15,790 points
138 views
0 votes
1 answer
0 votes
1 answer
0 votes
1 answer

How to store picture(s) in a hyperledger blockchain channel

You can hold images as encrypted characters ...READ MORE

answered Jun 16, 2018 in Blockchain by charlie_brown
• 7,720 points
144 views