Number to HEX

import { parse } from "@forta/usemetamask"
// ..
parse.toHex(22) // "0x16"

ETH to WEI

import { parse } from "@forta/usemetamask"
// ..
parse.toWei(0.01) // "10000000000000000"

ETH to TX_WEI

This will parse a number to wei and return it's HEX value. It's useful for RPC methods like eth_sendTransaction

import { parse } from "@forta/usemetamask"
// ..
parse.toTxWei(0.01) // "0x2386F26FC10000"

WEI to ETH

import { parse } from "@forta/usemetamask"
// ..
const ETH_IN_WEI = 1_000_000_000_000_000_000
parse.weiToEth(ETH_IN_WEI * 3) // 3

HEX number to decimal

import { parse } from "@forta/usemetamask"
// ..
parse.hexToInt("0x2") // 2

View full API definition