Slide 1

Slide 1 text

Interacting with the Blockchain via Android Cristian Serje Native TL @Check24 @SerjeCristian @serjec

Slide 2

Slide 2 text

Personal Motivation

Slide 3

Slide 3 text

Why Blockchain? • >$268B • Disrupted technology • Digital Freedom • Keep ID and personal info secure • Goverment and companies taking it „serious“

Slide 4

Slide 4 text

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

Slide 5

Slide 5 text

What it is Blockchain? Is a record of transactions

Slide 6

Slide 6 text

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

Slide 7

Slide 7 text

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

Slide 8

Slide 8 text

Advantages of Blockchain • Transparency • Security • Instanteneous Transactions • Decentralized • Immutable • Double spend problem solved

Slide 9

Slide 9 text

Are there any disadvantages? • Everyone needs to cooperate. • Not regulated • Security issues

Slide 10

Slide 10 text

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

Slide 11

Slide 11 text

Brief History

Slide 12

Slide 12 text

Bitcoin • Created in 2009 • Market Cap of >$180B • All Digital „Cryptocurrency“

Slide 13

Slide 13 text

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

Slide 14

Slide 14 text

Smart Contracts • Smartcontract = human being • Computarized contract • Immutable code which lives on the blockchain in certain address

Slide 15

Slide 15 text

Power of Smart Contracts

Slide 16

Slide 16 text

Power of Smart Contracts 1. Trust each other 2. Sign a legal agreement 3. Get help from a mutual friend

Slide 17

Slide 17 text

Smart contracts to the rescue

Slide 18

Slide 18 text

Transactions

Slide 19

Slide 19 text

Transactions Regular transfers of ether from one user to a human user

Slide 20

Slide 20 text

Transactions Transfers of ether from one user to noone

Slide 21

Slide 21 text

Smart Contract Transfers of ether from one user to a smart contract

Slide 22

Slide 22 text

Ethereum Transaction

Slide 23

Slide 23 text

Interaction with the blockchain

Slide 24

Slide 24 text

What do we need? • Web3j • Infura • Metamask • Web3j Gradle plugin • Remix IDE

Slide 25

Slide 25 text

Web3j • Type safe Java/Android library • Command line tools • Ethereum wallet support • Smart contract wrappers • Easier integration with nodes on the Ethereum Network

Slide 26

Slide 26 text

Setting up web3J implementation 'org.web3j:core:4.2.0-android'

Slide 27

Slide 27 text

Ethereum Transaction

Slide 28

Slide 28 text

Connecting to Ethereum Network web3 = Web3j.build(HttpService("https://ropsten.infura.io/v3/YOUR_KEY}")) try { val clientVersion = web3.web3ClientVersion().sendAsync().get() if (!clientVersion.hasError()) { toast("Connected!") } else { toast(clientVersion.error.message) } } catch (e: Exception) { toast(e.message!!) }

Slide 29

Slide 29 text

Create a Wallet try { lastWalletFile = WalletUtils.generateNewWalletFile(PASSWORD, walletDir) toast("Wallet created!") } catch (e: Exception) { toast("Error creating wallet!") e.printStackTrace() }

Slide 30

Slide 30 text

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()

Slide 31

Slide 31 text

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")

Slide 32

Slide 32 text

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); } }

Slide 33

Slide 33 text

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; } }

Slide 34

Slide 34 text

Deploy Smart Contract

Slide 35

Slide 35 text

Check Smart Contract

Slide 36

Slide 36 text

Verify Smart Contract

Slide 37

Slide 37 text

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' }

Slide 38

Slide 38 text

Interacting with a Smart Contract

Slide 39

Slide 39 text

Interacting with a Smart Contract

Slide 40

Slide 40 text

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? = greeter.greet().sendAsync() val convertToString: String? = greeting?.get() toast(“Smart contract returned: $convertToString") // write to contract val transactionReceipt: Future? = greeter.changeGreeting(smartContractText.text.toString()).sendAsync() val result = "Successful transaction. Gas used: ${transactionReceipt?.get()?.blockNumber} ${transactionReceipt?.get()?.gasUsed}" toast(result)

Slide 41

Slide 41 text

Questions

Slide 42

Slide 42 text

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