My Experience Building A Simple Widget Using CoinMesh

Last updated: September 10, 2018

Spoiler alert: CoinMesh is going to be a gamechanger.

When it comes to building decentralised blockchain based applications, admittedly it can get complicated fast. What libraries do you use, how do you safely makes calls to a wallet node and interact with the blockchain itself? This is something that Coinmesh aims to simplify.

Instead of having to worry about what libraries, adapters and tools to use, you get a graphical user experience that allows you to create a starting base for blockchain based applications via a simple UI.

Because CoinMesh is still in alpha, it is advisable (at the time of writing this) to use the sample-generated-project which is setup to work with Bitcoin and Litecoin out-of-the-box.

My task was a simple one, a widget that has an input which allows you to enter a Litecoin wallet address and you get the balance in Litecoin back. Oddly enough, the Litecoin wallet doesn’t have a simple straightforward method to get the balance of an address.

This meant I had to write a couple of methods at the adapter level to allow me to import an address and then call the getReceivedbyAddress RPC method on the wallet itself. The way Bitcoin and Litecoin work is that you need to import the address first and then call a method to get its balance, this is known as a watch-only address.

Fortunately, the way CoinMesh is setup, everything is intuitive so I wasn’t scratching my head where things live. I was not only able to add in new adapter methods easily for interfacing with the wallet node itself via RPC calls, but create a front-end that can easily communicate with the backend with minimal work.

And if you’re wondering specifically what code I wrote, the backend Litecoin wallet adapter for importing an address and getting the balance is here in 30 lines of code.

The front-end code is even way more simple as you can see, the lookup and display code is here in this component.

The majority of the work is done inside of the doLookup method which is below:

doLookup() {
    this.wallet.post('addresses/getreceivedbyaddress', {
        address: this.address
    })
    .then(res => {
        this.result = JSON.parse(res.response);
        this.address = '';
    })
    .catch(e => {
        console.error(e);
    })
}

We call the wallet service, specifically the address method getreceivedbyaddress which accepts an accept from an input and then the JSON response which contains the balance is rendered in the HTML file. It’s super basic and it was a breeze to write.

If you don’t believe me, look how simple the code is in the entire Github repository here. There are so many developers out there who are put off building blockchain/cryptocurrency applications, but CoinMesh legitimately makes it easy for any decent developer to build an application.

If you’re wondering where the best place to start with CoinMesh is, this official blog post about the alpha does a great job explaining how to get up and running with the same sample application that I used.

Conclusion

It is projects like CoinMesh that are going to help cryptocurrency and blockchain technology become more widely adopted in different industries.

CoinMesh solves one of the major problems with technologies like Bitcoin and Litecoin, people don’t know where to begin or what the best practices for development are.

It is easy to forget this is an emerging industry and the rules are still being written.

Purchase Aurelia for Real World Applications over at Leanpub now

 

Dwayne

 

Leave a Reply

Your email address will not be published. Required fields are marked *