Are you properly waiting for your transactions? – Bernardo Vieira

Photo by NordWood Themes on Unsplash

Ever since we have databases, the UI always talked with it asynchronously. But we’ve never thought much about it because databases are nearly instantaneous. Thus, we just wait for the response.

This principle doesn’t always apply when talking about blockchain transactions. In small private networks with fast consensus algorithms, it’s hard to realize the time consumption. But what about large nets, where transactions take seconds? Will you ask the user to wait?

Let’s see how we can use those two different approaches.

Let’s start with the first and more common approaches, waiting.

Imagine you are coding a dapp, created the contracts and now ar interacting with them. We often run into code like

It seems like, there’s nothing wrong with it, but the truth is, the result of this await is actually a “send transaction”.

What if you then want to wait for it to be mined? In a simple way, you could just wait for the next block to be mined, true. So you could just send the transaction, get the current block number and start an interval to verify when the current block changes. This means that a new block was mined therefore, your transaction was mined.

Wrong! What if your transaction has a transaction fee too low when compared to other transactions and is not accepted in the next block?

Just add a simple getTransaction in the loop and wait until the blockNumber isn’t null. In fact, this works, but the user is still waiting, maybe after 1 minute right now. He just wants to transfer a token.

There are a number of ways in which we can solve this problem. But instead of reinventing the wheel, I want to present you something.

Meet blocknative. Before further reading, try their demo

BlockNative created 3 tools to help and make this new blockchain world much smoother. They’ve created onboard, notify and assist. Each one of these three tools does something different and very useful.

Let start with onboard, which gives a pattern to wallet selection. Isn’t that hard to offer the user the best option? Just give the user many options. As an alternative, see web3connect.

Then assist. It mostly assists the user and takes a lot of work from the developers’ shoulders. Show the user a list of requirements, for example, network, auth, wallet, funds, etc.

And finally, the most important one, notify. Instead of leaving the user waiting for the transaction to be mined, why not notify? We all have notifications of some sort around us. We all know how to deal well with them. We all do something else while waiting for the notification.

And this is all as simple as a few lines of code.

Of course, Metamask also notifies us, some other wallet also do. But not all of us use metamask or the other notification-enabled wallets. And why do wallets have to play that role?

We have a long way to go, but this is getting better. Of course, I could have presented more tools, but I only intended to introduce the subject. Besides all these helpful tools, you can always, of course, create your own notification system. But remember, don’t leave the user waiting.

Thanks for reading, until next time.
Leave a comment or reach me on twitter.

Thanks, TechHQ for the opportunity.

Coins Kaufen: Bitcoin.deAnycoinDirektCoinbaseCoinMama (mit Kreditkarte)Paxfull

Handelsplätze / Börsen: | KuCoinBinanceBitMexBitpandaeToro

Lending / Zinsen erhalten: Celsius NetworkCoinlend (Bot)

Cloud Mining: HashflareGenesis MiningIQ Mining

Werbung: Immobilienmakler HeidelbergMakler Heidelberg

By continuing to use the site, you agree to the use of cookies. more information

The cookie settings on this website are set to "allow cookies" to give you the best browsing experience possible. If you continue to use this website without changing your cookie settings or you click "Accept" below then you are consenting to this.