New Ethereum talks, every Monday. The week's conference uploads by event, in your inbox.

Loading player…

EthCC 2: Ivaylo Kirilov

Ethereum ParisWed, Oct 9, 2019, 12:00 AM

EthCC 2 The Ethereum Community Conference is created by the community, for the community. It brings together great minds and forethinkers, and allows the community to grow. follow us : @AssethFR https://ethcc.io

Transcript

okay um my name's ivailo kirilov i work for web3labs as formerly known as blk.io and i'm here to talk about ethereum and java yay okay um just set a bit of an agenda today so i'll be talking about what web3 labs is doing some of the open source projects that we were building out and hopefully i'll try and give some of the java developers here some ethereum background and some of the ethereum developers here some java background understand how java fits in in the ethereum ecosystem to begin with i work for web3 labs uh we're about eight developers uh seven of us based in london and uh we have one guy called sam based in australia at the moment um more on him a bit later and yeah we've been going for about two years we were formerly known as block io what else interesting have we done let's see we've done this which is a small contract platform uh it's called eparus it's got some deployment and developer tools which come in the form of web3j which we'll talk about shortly and on top of that you have some management support business intelligence reporting analytics that kind of thing so you can think of it a bit like a glorified blockchain explorer with some extra bits and pieces in there something like etherscan ether scan plus plus maybe i don't know except it's written in java so that didn't go well and yeah the main things about this is it's used in kind of an enterprise setting so we're targeting enterprises consortiums and private chains we support quorum which is ethereum fork which allows private transactions so in our blockchain explorer you have the ability to view private transactions if you have the rights to view them which is something cool get in touch with me if you want to talk about how we deploy this stuff and the infrastructure that we provide but i'm going to move on to the to the cool thing and why i'm here today to talk about our open source projects and what we're doing to help the ethereum community and the java community combine and the tools that we're providing enterprises to help them build on ethereum so some of you have probably heard of web3j none of you have probably heard of our lippy jvm implementation this is an initiative that we started beginning of this year so we're looking at the lib p2p protocol which is a communication protocol between f 2.0 clients and it's something we're trying to do a jvm implementation on uh some companies that work that said it last time again these companies use our tech so most notably opera they're in their android browser they're using web3j uh we have partnership with microsoft we're helping build our enterprise smart contract framework platform for them and consensus as well we have rob here from pantheon pantheon has been using some of the web3j code and it's used in acceptance tests there and [Music] lastly exim chain which is using our smart contract platform registry as a sas offering to manage their consortium essentially to provide analytics and reporting and business tools so a bit more on web3j lib p2p so lib php itself is a basically a modular network stack provides a bunch of modules like transport discovery connection and connection upgrades where kind of in the beginning of it we started this initiative in in january so we've got like some of the base core concepts implemented but we're looking to build this out and our developer sam he's the one kind of pushing this project forward he's by himself at the moment um by having talks with people like in protocol labs uh that have developed i believe it's the python ptp correct me if i'm wrong but yeah we're working together with um with with other people trying to implement lib ptp uh mainly because the peter we're taking a kind of specification driven approach because the spec for lib php hasn't been fleshed out fully yet and we want to make sure that all of the different lib php implementations kind of work together nicely client-centric focus meaning there's that we we don't want to be tied down to like a certain ethereum client to be able to use our our protocol we want to our implementation of the protocol we want to try and generalize it so anybody can pull out parts and modules that they need documentation test support and web3j as as said we did start in january so we're trying to build out as much documentation as we can and being specification driven uh means that we're also trying to help define these specs that need to be used in web3 in lib p2p so more about that you can get some more information on lipid pio you can check out the web3j github we have the lib p2p project there and then the reference implementation php project i believe this is in go i'm not sure yeah if you go to the github you'll see a table like this this table basically shows all of the kind of uh concepts that we want to try and implement and you can see some of the core ones we've already done so like net pair crypto libraries for full lib p2p have been implemented and at the moment we're working on the transport layer so uh how how we're actually going to be sending and receiving packets in in our lib php library that's enough about lib p2p web3j is a bit of a bigger topic to cover so hopefully i'll have enough time so for those of you that don't know anything about web3j this diagram represents nicely how it fits into kind of the java developing world you would have your java application which can be basically anything you want and let's say you want to interact some way with the blockchain then you'll be using web3j to make basically http calls to an ethereum client and then that ethereum client will propagate your transaction and the miners will at some point reach consensus on the transaction you've sent in java to the ethereum client so as i mentioned we we it's basically a http client we also support websockets and we also support ipc we have implementation of the ethereum wallet so you can actually create your own wallet with web3j um it's what opera does in in their android application we provide smart contract bindings uh i'll go into a bit more detail about that but essentially you can call web contract functions and you can deploy contracts directly from from your java code so all you need is your solidity source and then from there we we can convert that to java basically generate a java client for you which will then be able to call functions deploy your contract etc we have a reactive functional api more on that in a bit later and ens support so we can get rid of some of those hashes and make it a bit more user-friendly currently we're on web3j version 4.1.1 i believe is the most recent version and in web3j4 the difference between three and four is we've added rx2 java support so we upgraded from rx java one and i'll go into a bit more detail later on um some various bug fixes uh i think is probably not the best term here because we don't have bugs in web3j more we've done some various enhancements right we've made it better we've tackled more edge cases um bit 44 implementation so this is to do with how uh wallets get generated so you can have like a hierarchical structure of wallets generated from a single private key and pantheon support which is the new java client written by pegasus team in consensus so for those ethereum developers that are not java developers just to show how easy it is to to get started with web3j in java you'd create a web3j object we have a factory method so you can build your web3j object and you pass in a http service this can also be a websocket service or an ipc service we also support infurer so you can connect with connectvia and fura to use the inferior node in your java application and then you simply call methods uh we try and adhere to the uh web3 specs so you here you'd call methods like web3j dot send transaction web3j dot uh web3 client version web3j.

personal unlock account and then you have three different options on how to send these requests to the node you can send them via blocking call which means that the application will wait until this call returns a value before continuing you can send it asynchronously which means that the application won't block when you make the call and at some point in the future you can get the result if the result is uh available then you can use it and then the flow api that we have which i'll go into a bit more detail later on this is a nice diagram to show you in a bit more detail how web3j is actually working behind the scenes so in ethereum you have basically three types of transactions that we like to categorize in you can transfer ether which is basically the simplest transaction type you can deploy a contract and you can call a function in a contract we decided to split these up because essentially you'll call the deploy only once and then the functions are you can call multiple times so it's a different type of transaction and then in web3j what we do is we build a transaction from the to address i.e the address you want to send your transaction to the data which can be empty if it's a transfer uh or the evm byte code if it's to do with a contract so it's actually the evm byte code to deploy the contract or the evm byte code to call a function in a contract uh your nonce or actually the value which is the value of ether that you want to send the nonce which is the transaction count of your address essentially the nonce is used to generate contract addresses so when you want to deploy a new contract your two value will be empty and then using the nonce and the sender address a contract address will be generated and then the gas price and the gas limit does anyone want me to go over gas because it's been a you know it's a topic that people don't fully understand but it looks like there's no takers so if anyone wants to know more about gas and i can get into the specifics of how that works in ethereum then you can catch me after the talk so after we have this data we sign it with your private key then you have your signed transaction which is sent to an ethereum client that ethereum client which can be you know guest parity pantheon or any other ethereum client that supports web3 specification that client will then propagate your transaction the miners will reach consensus included in a block and at the same time in web3j a transaction manager is created for your transaction and that is essentially polling the ethereum client for the transaction status and at some point when your transaction is included in the blockchain you'll be returned a transaction receipt which will hold things like the contract cr uh the contract address if you're creating a contract the events and [Music] the status for example of your contract um so yeah sending ether the first type of transaction uh we have a utility class with the static method to make it very easy so you would create your web3j instance you'll connect to a node then you'll load up your credentials you can load up your credentials from from from a file from a wallet file or you can generate a new wallet file or you can load up credentials from some kind of mnemonic that you have because we have bib 44 support and then using web3g and the credentials you can create a transfer you pass in your web3j so that we know which node you want to talk to you pass in the credentials so we know who's sending this uh this ether you pass in the the to address so who do you want to send it to and then the value and the unit so we support units between all the units between way and ether um and obviously you don't want to send 0.2 away because you probably can't pay for the gas to send that in the first place and this is a blocking call so this will wait until the receipt comes the transaction receipt comes back and then in your transaction receipt you have some information that you can then print out or use however you see fit in your application you can also do this via the command line nobody really uses the command line utility i use metamask myself because i think it's a lot easier if you want to be cool you can use the command line utility it's got options to to send ether and it kind of works behind the scenes in the same way basically this code gets generated with the correct inputs and then you you get some feedback from from the node whether your transaction was successful or not which block it was mined in etc and then you can go off to etherscan and check it out if it's working or not smart contracts for those of you who are java developers and don't know anything about ethereum smart contracts are written in a language called solidity similar in concept to java it's a statically typed high-level language similar to java compiles to ethereum to evm bytecode which is then run on an ethereum virtual machine again similar to java how it's compiled to jvm by code and it runs on a java virtual machine so with web with web3j what you can do is you can create java wrappers for these contracts which is essentially a client that will have all the functions that are in your contract so you can call your your functions in java as you would call them in in solidity so just to give you an example uh this is like a very simple uh hello world kind of uh example you have a greater contract which extends mortal in in solidity the keyword is is in java is extends same thing and then you have this constructor which takes a greeting and it sets the greeting field and then you have a getter function which then just returns the greeting field so you'd compile this contract using uh the solidity compiler you pass in the the source code some flags and then your output directory and then this will generate an application binary interface and some evm bytecodes the application binary interface is essentially an array of all the functions that are inside your contract so for example you can see that this function has a name called greet so this is our agree function here and the outputs are a string and there are no inputs and then you can also see that the constructor here says type constructor it's a different type of transaction a different type of method sorry that is in solidity so the constructor you can only call once in your contract and then you can't call the constructor again obviously you can construct a new instance of your contract but the instance that you constructed you can't call the constructor again the constructor method and the input for this is is the greeting that we then return in degree function this is what by code looks like doesn't look too interesting something that maybe not a lot of people know in this room every contract has these uh bold bits in them and these are essentially flags to show you where this contract is stored in in the evm so this is the swarm hash of of your contract so this is where it's stored in swarm and then this part is to define what kind of storage you're using so in this case it's using a swarm hash so here it would say swarm but if you are using ipfs for example here would be the encoding of ipfs this is the keckack hash of literally uh swarm v1 i think and then this is the actual swarm hash so here you would have the literal hash of ipfs or whatever other storage mechanism you want to use and then with web3j what we do is we set we generate the smart contract wrapper which is which is this client which i'll show you an example of in the next slide uh you pass in the binary so that we we know the byte code just to send in in your in the transactions you wanna um call methods to your contract on and you pass in the api so we know the names of those methods and we can make it more more user-friendly essentially easier for developers to understand what functions are being called then you pass in the um the package you want it to be generated in and the output directory and this will generate a file similar to this now this version is uh generated with uh with an old version of web3j so some of the syntax is a little bit different but you get the general picture you have here a deploy function and this deploy function takes in the greeting that we want to put in so in web3j we have a dsl to interact with solidity types because they're slightly different to java types for example you have 256 bit integers in solidity you don't have that in java natively so we have some wrappers around around those types but in the newer versions of web3j we've actually hidden this implementation so you don't actually need to interact with solidity types you can just use the normal java types and and build transactions and they'll be converted behind the scenes by web3j so you can use them and here's like the grief function so degree function that takes in uh doesn't take in anything it doesn't have any any parameters so we built this function this uh this function is part of our dsl so it's not the function as in the java function um and it takes in the name of the function the inputs which is which is nothing and then the outputs which is a type reference of a string so we know that the return is a string and then this function has a method to be able to create the evm byte code that you need to call this agreed function in a transaction on the ethereum blockchain so this is just a simple hello world kind of uh web3j blockchain example we create the web3j instance we load our credentials and then we can deploy our contract using greeter.deploy so greeter is now a java class and you call deploy you pass in the web3j credentials so you know which node you're deploying to you know who's deploying from your your gas provider your gas price and the last thing is the input parameters for your for your contract and then you can call the grid function or any other function in your contract just as you would in like if you're using javascript kind of version and then you can you can print it out and you can see we passed in hello blockchain world in the constructor and we get returned hello blockchain world when we call the grid function uh one thing i'd like to to mention which i haven't really mentioned in any of my talks is that we have a gradle plugin so for those of you who know about gradle this is really cool because it means that you don't have to worry about compiling solidity code and you don't have to worry about generating smart contract wrappers how this works is uh basically you you apply the the web3j plugin you define a source set so this is the directory where you're putting your solidity files in by default it goes to believe source main solidity so it's in in kind of your main main project code area where your java code is and then every time you build the project your contracts will be compiled and smart contract wrappers will be generated for those for those contracts and because we're using gradle and it's got kind of uh what's the word i'm looking for incremental builds so if you don't change anything in your solidity file then it won't waste time regenerating and recompiling your contract and then we have some uh variables that you can you can play around with like for example the generated package name um generated files based directory so where do you want the generated files to be whether you want to exclude some contract so say you have some contract that is only meant to be used by other contracts that are extending it maybe you don't want it to be callable in your java code so you can exclude that contract from the plugin picking it up and then you can run gradle w build inside the source directory to to to build your content to build your application which will compile your contracts and will generate these smart contract wrappers now onto rx java i know i'm running low on time so i'm going to try and wrap things up shortly after this um so the flowable api the way it's different to send async is when you send async your your program sends the transaction then it continues uh executing and at some point in the future when you need uh the value you you'd call get on your on your initial send and if the value is present you'll get a value back if not you'll get an error so uh the flowable api basically allows you to define kind of like a callback function so whenever this function web3 client version returns a value then it will execute this block of code which makes it a bit easier to work with kind of asynchronous programs you can build more complex things for example we have some pre-built flowables already in web3j so if you want to replay all previous blocks and future blocks we have a replay past and future block flowable define your start number and then you define whether you want your full transaction objects uh there is this is a flag which is either true or false and what it means is um it will either return the full transaction object or just the hashes of the transactions in the block which might be useful for things like latency and bandwidth critical situations where maybe you don't need the full transaction object so you pass in false there and then for every block you can do whatever you want with it this is something our smart contract registry uses behind the scenes it essentially copies all the blocks from the blockchain into a database add some metadata and then we have a very powerful api to be able to query things and decode things in on the blockchain so it's not just hashes everywhere just an overview again of the whole web3j ecosystem so at its core it's a jvm-based kind of ethereum http client it's written in java which lib php is also written in kotlin which means that they're android compatible we also have a version of web3j which compiles against uh java 6 so we support over 98 of android phones that are out there and of course not to forget the scholar community we can also work with scholar because it's a jvm-based library uh the build tools like the gradle build tool that i mentioned we also have a similar one for maven clan support geth parity pantheon and we also have a dedicated web3j quorum library which allows you to do private transactions to our private networks and private consortiums and we also have some framework integrations namely with apache camel on our dsl we have a spring starter project so you can get started with spring and web3j very quickly and most recently i think actually on friday i completed integration with climatic's ion interoperability framework which is a cool kind of uh small contract-based cross-chain framework to be able to [Music] move data across chains essentially so we have we have like a web3j startup project which already makes it easier for you to get started with ion so you don't have to worry about what's happening behind the scenes and this is what our github looks like come check us out github.comweb3j we have the web3j uh library which has uh a good number of stars and a good number of forks and a good number of issues as well so if anyone wants to work on some issues while they're here at fcc then i will be a good good place to start quorum web3j spring boot starter project maven plug-in gradle plug-in and we have a sample project sample gradle project as well which is just a very basic kind of hello world java and gradle project and somewhere on there is also web3j ion down the list but i don't have space on the screen uh the future of web3j quickly if time permitting uh eip712 support which is basically some uh endpoints for assigning structured data so you we have like a sign structured data i think it's called endpoint uh something that we're implementing um we've tried to architect web3j so it's easily extensible so when new specs come out new definitions for new endpoints come out it's very easy to update them pretty much anyone can update them we want to add support for the experimental api encoder to allow us to build more complicated smart contract wrappers uh solidity five 0.

5 support is pretty much there there are just some edge cases that we haven't been looking at we don't have time to look at so if anybody is actually using uh solidity 0.5 contracts and is a java developer and you've run into problems then please let us know so that we can make some bounties for this uh in in github we're working with github into bitcoin to to make some bounties for issues that we don't have time to fix and we also want to create uh some ea compliant calls as well like to be able to send private transactions across any eea compliant client such as pantheon and yeah thanks for listening everyone web 3 labs i've got some stickers and some cards some business cards down at the front and i open the floor to some questions if anyone's got any any questions anyone listening still one person listening yes good stuff guys or was it just that you were listening you don't have a question i do have a question okay hello can you hear me well i can hear you does it work that's that's fine uh no i was just wondering so you were talking about the transaction manager that does that pulls the the the blockchain to um uh to basically get um yeah that's the one yeah is it um i suppose that it's probably not supported in json rpc but can we imagine i mean is it planned in the future to avoid having you know polling these these uh the transactions and have the blockchain kind of push these events to that is an interesting uh interesting question uh it's not something that we can really do in web3j uh without some yeah we need some kind of uh oh that's a good idea actually potentially but you still need to pull the node we need the node to be able to support pushing transaction receipts back to the client but the thing is with this poll is is set to default to poll every 15 seconds which is the block time in in ethereum obviously in private and consortium chains your block times might be lower so this is a configurable value how how often to poll and we generally think that you know polling every 15 seconds is not an issue um and there's no point in polling any faster especially on mainnet because you're not going to get any new information so we think it's a sensible default uh but pushing yeah if if uh what if the ethereum client could support pushing back uh a transaction receipt so maybe providing a callback url in the send um so that the ethereum can client can then um make a request to that url when it's finished processing the transaction then that that's basically the way to go to provide what you need or what you asked for uh anyone else just to let you know uh in a framework integration topic uh we did an integration with app inventor yeah app inventor is something where you're able to build a mobile application using a scratch-like language okay move blocks and so we did a block which encapsulates uh the web3j functionality accessing the blockchain so people can do easily a mobile application using uh web3j that sounds that sounds awesome i'd like to have a chat after after everything goes that'll be good it wasn't really a question more of a statement yeah yeah and we have a app inventor that ethereum.org if people want to know awesome we'll catch up after any other questions i think i'm i'm over time so if anyone wants to grab me after the the presentation to have a chat then feel free to do so thank you

Automatic transcript — names and jargon may be misspelled.