Skip to main content

Method Signature

align.blockchain.utils.parseEther(ether: string): bigint

Parameters

ether
string
required
Amount in ether

Returns

Returns the amount in wei as a bigint.

Examples

import Align from "@tolbel/align";

const align = new Align({
  apiKey: process.env.ALIGN_API_KEY!,
  environment: "sandbox",
});

// Convert 1 ETH to wei
const wei = align.blockchain.utils.parseEther("1.0");
console.log(wei.toString()); // "1000000000000000000"

// Convert 0.5 ETH to wei
const halfWei = align.blockchain.utils.parseEther("0.5");
console.log(halfWei.toString()); // "500000000000000000"

Use in Transaction

const amountInEther = "0.1";
const amountInWei = align.blockchain.utils.parseEther(amountInEther);

// Use for contract call
const tx = await contract.deposit({
  value: amountInWei,
});