Converting to/from Wei

In some crypto apps, you may need to interact with wei, which is the base unit of Ethereum (1 ETH = 10^18 Wei). While the Web3 & Metamask plugin may have a "convert to/from wei" action, this may not be as useful, as you may need to make multiple wei calculations.

Since wei works in numbers extremely large, Bubble has a slightly difficult time dealing with them. For example, if you were to simply multiply or divide a number type by 10^18 (1 with 18 0's), Bubble will represent that number as 10 e18, so that it doesn't need to write out the full 19 digits. This causes issues in API calls or Web3 services that require you to express Wei as the full number rather than the shortened form.

A better approach to converting to Wei is to use a Javascript expression from the toolbox plugin. Add the following expression, with the "var - transaction..." part being whichever number you need, making sure to set the result type as a text rather than a number. Bubble will then output this as 1000000000000000000 rather than 10 e18, which will be more useful in many contexts in crypto apps/services.

Last updated