Interacting with the Blockchain via Android

3d23492af0992cf10d5fba5d72912d3b?s=47 serjec
September 24, 2019

Interacting with the Blockchain via Android

Blockchain is disrupting software industry. The term itself has become a popular topic. Everyone is talking about blockchain and its usages in decentralized applications. How can we be part of it? In this talk, i am going to explain to you roughly about dApps, Blockchains, and how can we interact our Mobile Android App with the Ethereum Network.



September 24, 2019


  1. Interacting with the Blockchain via Android Cristian Serje Native TL

    @Check24 @SerjeCristian @serjec
  2. Personal Motivation

  3. Why Blockchain? • >$268B • Disrupted technology • Digital Freedom

    • Keep ID and personal info secure • Goverment and companies taking it „serious“
  4. What it is Blockchain? Blockchain is a technology that allows

    to make instantaneous transactions on a network without any middlemen. Keeping a record of what happens
  5. What it is Blockchain? Is a record of transactions

  6. Why is it called Blockchain? Transactions Transactions Transactions Previous Hash

    Root Hash Nonce Timestamp Previous Hash Root Hash Nonce Timestamp Previous Hash Root Hash Nonce Timestamp
  7. How does it work? A User request a transaction A

    block representing the transaction is created The block it‘s broadcasted to all the nodes of the network All the nodes validate the block and the transaction The block is added to the chain The transaction is verified and executed
  8. Advantages of Blockchain • Transparency • Security • Instanteneous Transactions

    • Decentralized • Immutable • Double spend problem solved
  9. Are there any disadvantages? • Everyone needs to cooperate. •

    Not regulated • Security issues
  10. Brief History 1990 2009 2011/12 2012/13 The concept of distributed

    computing Bitcoin Currency payments Smart Contracts 2013/14 2014/15 Finantial markets using blockchain beyond cash transaction Contracts Origin Transactions 2015/16 2016/17 2018/19 NASDAQ blockchain trials Market consolidation and more developments Year of ICO and Adoption Application
  11. Brief History

  12. Bitcoin • Created in 2009 • Market Cap of >$180B

    • All Digital „Cryptocurrency“
  13. The Rise of Ethereum • Decentralization Application Platform • The

    world of computer • Turing-complete virtual machine • Other assets • Smart Contract • Public blockchain (main & test) • Ether • 2nd largest crypto
  14. Smart Contracts • Smartcontract = human being • Computarized contract

    • Immutable code which lives on the blockchain in certain address
  15. Power of Smart Contracts

  16. Power of Smart Contracts 1. Trust each other 2. Sign

    a legal agreement 3. Get help from a mutual friend
  17. Smart contracts to the rescue

  18. Transactions

  19. Transactions Regular transfers of ether from one user to a

    human user
  20. Transactions Transfers of ether from one user to noone

  21. Smart Contract Transfers of ether from one user to a

    smart contract
  22. Ethereum Transaction

  23. Interaction with the blockchain

  24. What do we need? • Web3j • Infura • Metamask

    • Web3j Gradle plugin • Remix IDE
  25. Web3j • Type safe Java/Android library • Command line tools

    • Ethereum wallet support • Smart contract wrappers • Easier integration with nodes on the Ethereum Network
  26. Setting up web3J implementation 'org.web3j:core:4.2.0-android'

  27. Ethereum Transaction

  28. Connecting to Ethereum Network web3 ="}")) try { val

    clientVersion = web3.web3ClientVersion().sendAsync().get() if (!clientVersion.hasError()) { toast("Connected!") } else { toast(clientVersion.error.message) } } catch (e: Exception) { toast(e.message!!) }
  29. Create a Wallet try { lastWalletFile = WalletUtils.generateNewWalletFile(PASSWORD, walletDir) toast("Wallet

    created!") } catch (e: Exception) { toast("Error creating wallet!") e.printStackTrace() }
  30. Send Ether val credentials = WalletUtils.loadCredentials(PASSWORD, File(walletPath + "/${lastWalletFile}")) val

    receipt = sendFunds( web3, credentials, “to-adddress“ BigDecimal(“how much ether?“), Convert.Unit.ETHER ).sendAsync().get()
  31. Get Balance val ethGetBalance = web3 .ethGetBalance(walletAddressText.text.toString(), DefaultBlockParameterName.LATEST) .sendAsync() .get()

    // 1 wei = 10^-18 Ether toast("Balance ${Convert.fromWei(ethGetBalance.balance.toString(), Convert.Unit.ETHER)} ether")
  32. Smart Contract contract Mortal { /* Define variable owner of

    the type address */ address owner; /* This constructor is executed at initialization and sets the owner of the contract */ constructor() public { owner = msg.sender; } /* Function to recover the funds on the contract */ function kill() public { if (msg.sender == owner) selfdestruct(msg.sender); } }
  33. Smart Contract contract Greeter is Mortal { /* Define variable

    greeting of the type string */ string greeting; /* This runs when the contract is executed */ constructor(string _greeting) public { greeting = _greeting; } /* change greeting */ function changeGreeting(string _greeting) public { greeting = _greeting; } /* Main function */ function greet() public view returns (string) { return greeting; } }
  34. Deploy Smart Contract

  35. Check Smart Contract

  36. Verify Smart Contract

  37. Interacting with a Smart Contract buildscript { repositories { mavenCentral()

    } dependencies { classpath ''org.web3j:web3j-gradle-plugin:4.3.0‘ } } apply plugin: 'org.web3j' plugins { id 'org.web3j' version '0.1.4' }
  38. Interacting with a Smart Contract

  39. Interacting with a Smart Contract

  40. Read/Write into a Smart Contract val greeter = Greeter.load(contractAddress, web3,

    credentials, gasLimit, gasPrice) // check contract validity toast("Greeter valid: ${greeter.isValid}") // read from contract val greeting: Future<String>? = greeter.greet().sendAsync() val convertToString: String? = greeting?.get() toast(“Smart contract returned: $convertToString") // write to contract val transactionReceipt: Future<TransactionReceipt>? = greeter.changeGreeting(smartContractText.text.toString()).sendAsync() val result = "Successful transaction. Gas used: ${transactionReceipt?.get()?.blockNumber} ${transactionReceipt?.get()?.gasUsed}" toast(result)
  41. Questions

  42. Interaction with the Blockchain. Via Android THANKS! @SerjeCristian serjec