WanX — Making Wanchain Cross-Chain Transactions Easier for Developers

Dan Reecer
Dec 20, 2018 · 8 min read

I recently sat down with one of our developers, Jeremiah, to talk about a developer package that he created to make Wanchain cross-chain transactions easier and less error-prone. Below he talks us through this package, and I’ve included his WanX tutorial video and demo DEX video as well.

Could you introduce yourself and what you do at Wanchain?

My name is Jeremiah Goyette, and I am a software engineer working for Wanchain since about June 2018. While I am based out of Austin, I work closely with many of the developers in Beijing and have been working with them on several aspects of the 2.0 and 3.0 releases.

When I first came on to Wanchain, I took over the code that handles the backend database synchronization for the Wanchain explorer at wanscan.org. This was a reasonable starting point given that it aligned well with my previous background. But as it turned out, starting with the explorer code was even more rewarding since it required me to learn all of the intricate details of cross-chain transactions, which proved to be invaluable knowledge when building out the WanX package.

Tell me about this WanX package that you’ve recently developed. What is it and how does it save time for developers building on Wanchain?

WanX is mainly just a storehouse of all the information one needs to do cross-chain transactions, with helper functions that allow developers to build and send the correct contract calls without having to think too much about it.

But before talking about what WanX does, it might be best to start with talking about cross-chain transactions in general. In the context of Wanchain, what we mean by “cross-chain transaction” is the conversion of an asset to its corresponding Wanchain proxy token, or back from the Wanchain token to the asset on the original chain. So, for example, one could make an inbound cross-chain transaction (inbound into the Wanchain network) to convert Bitcoin (BTC) into Wanchain Bitcoin token (wBTC), or make an outbound crosschain transaction to convert the wBTC token back to native BTC.

All cross-chain transactions involve an interplay of smart contract calls and events between the user and a Storeman group, who handles the asset conversions. Generally, a cross-chain transaction has two main parts: the lock and the redeem. The lock process is initiated by the user with a call to a smart contract, and then is completed when the Storeman group makes a followup call to the smart contract on the other chain. Likewise, the redeem is also initiated by the user with a call to a smart contract and is completed when the Storeman group follows up with a final smart contract call.

The basic model for a cross-chain transaction is thus:

1. Make a lock call to a smart contract

2. Wait for the Storeman group to respond

3. Make a redeem call to a smart contract

4. Wait for the Storeman group to respond.

Developers in this space will be familiar with making calls to smart contracts, and so really the whole of the cross-chain transaction process could be manually coded by any developer using web3. But that developer would need to do a good deal of research to figure out what are the method names and arguments required for the contract calls, as well as what are the addresses of the smart contracts.

This is where WanX comes into play. Instead of having to hardcode the various contract calls into the Dapp business logic, the developer can leverage WanX to construct the contract calls. No longer will the developer need to be concerned about the underlying mechanics of cross-chain transactions. Instead, with WanX the developer just needs to understand the simple API that WanX provides, and the order that the functions are to be executed.

WanX also normalizes many of the underlying functions and contract calls for the various chains, making an overall more consistent API. For example, to get the outbound fee for a BTC cross-chain transaction one needs to call getWbtc2BtcFee on a smart contract, while for an ETH cross-chain transaction one would need to call getWeth2EthFee on a different contract. But with WanX, the same function can be used to get the outbound fee for either chain.

WanX Tutorial from Jeremiah

In short, while any developer in the space could put together his or her own logic to do cross-chain transactions on Wanchain, WanX takes out much of the leg work, thereby making the development process quicker and less error prone.

Could you explain what developers can do with WanX?

As I mentioned before, WanX at this point is primarily focused on giving developers a straightforward interface for making cross-chain transactions. With that said, there is a proposal in the works to turn WanX into the primary package for leveraging all of the features of Wanchain. Thus, it is possible that soon WanX will also include support for privacy transactions, as well as include all the utility functions needed for key manipulation and querying the state of the ecosystem, such as getting the available Storeman groups and registered cross-chain ERC20 tokens. Ideally, in the future developers should be able to use WanX for all interactions with Wanchain, in place of the myriad of Wanchain packages that developers have been using to date.

But even if WanX just does cross-chain, it proves to be very useful. It is hard to imagine how Harry Ward (another Wanchain developer) and I would have built out the demo cross-chain DEX showcased last month without some package like WanX. While that demo was a bit contrived and not fully fleshed out, it showed really well that it can be just a matter of adding a few lines of code to get the crosschain feature working. We have all seen token exchange DEXs, but basically none where you can convert Bitcoin and Ethereum into a tradable token right there in the browser. And now that can be achieved with relatively minimal effort.

Wanchain Cross-chain Demo DEX

Can you talk about your experience building the Demo DEX and what other tools you used in that process?

We wanted our demo exchange to be a decentralized exchange, in that users should be able to trade directly with each other and without having to deposit their tokens into the exchange. To make that happen, we used 0x’s model and built out a system of smart contracts and relayer nodes. Like Ethereum, Wanchain uses the Solidity contract language, and so to write the contracts we were able to use the usual Solidity tools, like Truffle, Remix, and Ganache.

We also wanted the exchange to be user friendly and easy to transact. Accordingly, we chose to have the exchange use MetaMask and WanMask (the Wanchain MetaMask) so that users could sign and send transactions from the browser without needing to connect to a node directly. Along with Web3, we thus had everything we required to get the exchange rolling without any need for users to provide private keys or deposit funds into the exchange.

The development of the token exchange was pretty regular, given that we were not the first to build a Solidity-based token exchange. The real fun started when we were tasked to make the exchange a “cross-chain” exchange. At that time there was no WanX, and thus it was not so clear how we would achieve that. After a short time it became quite apparent that we desperately needed a new interface for making cross-chain transactions. And thus WanX was born.

Initially Harry and I had our doubts about the cross-chain exchange, thinking it would be either too cumbersome technically or too slow for users. But once WanX was plugged in and we started making our first cross-chain transactions, we saw right away that it was completely viable. Implementing cross-chain ended up adding very little technical overhead, and yet it added an gigantic wow factor.

— Thanks Jeremiah!

Wanchain 3.0 — Bridging Bitcoin to Ethereum and ERC20s

The recent Wanchain 3.0 launch means Wanchain now connects Bitcoin, Ethereum, and several ERC20 tokens. This launch is of major significance to leaders of Ethereum-based projects, as well as any project that requires interoperability. Upon launch of Wanchain 3.0, any dApp, protocol, DEX, or other project built on Ethereum can now break down the wall between their network and the community of Bitcoin users. For example, decentralized exchanges will now be able to offer Bitcoin trading pairs. New pairs on decentralized exchanges in the Wanchain-wrapped BTC token will allow for drastic increases in trades and liquidity for the space at large. Other use cases for this cross-chain capability could include cross-chain crypto loans, bringing Bitcoin to any application currently limited to Ethereum, or a cross-chain payment applications. The opportunities cross-chain with Bitcoin, Ethereum, and ERC20s like LRC or DAI will bring for Wanchain and the industry are quite exciting.

About Wanchain

Wanchain is a blockchain platform that enables decentralized transfer of value between blockchains. The Wanchain infrastructure enables the creation of distributed financial applications for individuals and organizations. Wanchain currently enables cross-chain transactions with Ethereum, and today’s product launch will enable the same functionalities with Bitcoin. Going forward, we will continue to bridge blockchains and bring cross-chain finance functionality to companies in the industry. Wanchain has employees globally with offices in Beijing (China), Austin (USA), and London (UK).

You can find more information about Wanchain on our website. Additionally, you can reach us through Telegram, Discord, Medium, Twitter, and Reddit. You can also sign up for our monthly email newsletter here.

Wanchain

Our mission is to provide an open and trusted platform to power transfer of digital assets across siloed blockchains. We believe this will enable us to connect and empower communities globally.

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade