# Hemi Ethereum

Source: https://developers.bitgo.com/docs/hemieth

## Overview

Hemi is a modular Layer 2 protocol built on both Bitcoin and Ethereum, providing superior scaling, security, and cross-chain interoperability. The network uses the Hemi Virtual Machine (hVM), which embeds a full Bitcoin node within an EVM framework, allowing developers to build applications that leverage both blockchains simultaneously. Hemi uses a Proof-of-Proof (PoP) consensus mechanism to achieve finality anchored to Bitcoin security. Gas fees are paid in ETH, and standard EVM tooling operates without modification.

## Explorer
<a href="https://explorer.hemi.xyz/" target="_blank" rel="noreferrer">https://explorer.hemi.xyz/</a>


## Wallets Types

BitGo enables holding hemieth in the following wallet types:

|                  | Multisig Cold | Multisig Hot | MPC Cold | MPC Hot |
| ---------------- | ------------- | ------------ | -------- | ------- |
| **Custody**      | ❌            | ❌            | ✅       | ❌      |
| **Self-Custody** | ❌            | ❌            | ✅       | ✅      |

## Ticker Symbols

| Mainnet | Testnet |
| ------- | ------- |
| HEMIETH | THEMIETH |

## Faucet

You can use a faucet to obtain free testnet themieth for development and testing purposes.

**Faucet:** https://app.hemi.xyz/en/tunnel/?networkType=testnet

## Units

Each Hemi Ethereum consists of `1,000,000,000,000,000,000` (<code>10<sup>18</sup></code>) wei, so not even a single Hemi Ethereum can be stored numerically without exceeding the range of JavaScript numbers. Gas fees use gwei.

- 1 hemieth = <code>10<sup>18</sup></code> wei
- 1 wei = <code>10<sup>-18</sup></code> hemieth
- 1 gwei = <code>10<sup>-9</sup></code> hemieth

For that reason, only string balance properties are available, which are `balanceString`, `confirmedBalanceString`, and
`spendableBalanceString`.

## Tokens

Hemi Ethereum supports the ERC20 token standard. ERC20 tokens on Hemi are available as BitGo supported assets.

## Fees

Hemi Ethereum supports EIP-1559 transaction pricing. Each transaction includes a base fee that fluctuates based on network demand and burns algorithmically, plus an optional priority fee to incentivize block producers. The network denominates and pays gas in ETH.

## Create Wallet

```javascript
bitgo
  .coin('themieth')
  .wallets()
  .generateWallet({
    label: 'My Test Wallet',
    passphrase: 'secretpassphrase1a5df8380e0e30',
    enterprise: '5612c2beeecf83610b621b90964448cd',
    walletVersion: 4,
  })
  .then(function (wallet) {
    // print the new wallet
    console.dir(wallet);
  });
```
```shell
export BITGO_EXPRESS_HOST="<YOUR_LOCALHOST>"
export COIN="themieth"
export ACCESS_TOKEN="<YOUR_ACCESS_TOKEN>"
export LABEL="<DESIRED_WALLET_NAME>"
export PASSPHRASE="<YOUR_BITGO_LOGIN_PASSPHRASE>"
export ENTERPRISE_ID="<YOUR_ENTERPRISE_ID>"

curl -X POST \
 http://$BITGO_EXPRESS_HOST/api/v2/$COIN/wallet/generate \
 -H 'Content-Type: application/json' \
 -H "Authorization: Bearer $ACCESS_TOKEN" \
  -d '{
    "label": "'"$LABEL"'",
    "passphrase": "'"$PASSPHRASE"'",
    "enterprise": "'"$ENTERPRISE_ID"'",
    "walletVersion": 4
}'
```

## Create Address

```javascript
bitgo
  .coin('themieth')
  .wallets()
  .getWallet({ id: '585c51a5df8380e0e3082e46' })
  .then(function (wallet) {
    return wallet.createAddress();
  })
  .then(function (newAddress) {
    // print new address details
    console.dir(newAddress);
  });
```
```shell
export WALLET="585c51a5df8380e0e3082e46"
export ACCESS_TOKEN="<YOUR_ACCESS_TOKEN>"

curl -X POST \
-H "Authorization: Bearer $ACCESS_TOKEN" \
https://app.bitgo-test.com/api/v2/themieth/wallet/$WALLET/address
```

## Consolidate Balance

Hemi Ethereum supports Multisignature smart-contract wallets which utilize forwarder smart contracts to enable multiple receive addresses. The forwarder smart contract automatically consolidates native tokens received in your receive addresses to your base address. However, if you receive non-native tokens, such as ERC20 tokens, the wallet initiates a different consolidation transaction to the base address. Additionally, forwarders can only send assets to the base address of the wallet.

## Estimate Fee

```javascript
const BitGoJS = require('../../../src/index.js');
const bitgo = new BitGoJS.BitGo({ env: 'test' });
const accessToken = '<YOUR_ACCESS_TOKEN>';
const coin = 'themieth';

async function getFeeEstimate() {
  try {
    await bitgo.authenticateWithAccessToken({ accessToken });
    const res = await bitgo.coin(coin).feeEstimate({ numBlocks: 2 });
    console.dir(res);
  } catch (err) {
    console.error('Error fetching fee estimate:', err);
  }
}

getFeeEstimate();
```
```shell
export COIN="themieth"
export ACCESS_TOKEN="<YOUR_ACCESS_TOKEN>"

curl -X GET \
 https://app.bitgo-test.com/api/v2/$COIN/tx/fee \
 -H 'Content-Type: application/json' \
 -H "Authorization: Bearer $ACCESS_TOKEN"
```

## Transact

```javascript
const tx = await fundedWallet.send({
    address: '<DESTINATION_ADDRESS>',
    amount: '<AMOUNT>',
    walletPassphrase: process.env.PASSWORD,
  });
```
```shell
export BITGO_EXPRESS_HOST="<YOUR_LOCALHOST>"
export COIN="themieth"
export WALLET_ID="<YOUR_WALLET_ID>"
export ACCESS_TOKEN="<YOUR_ACCESS_TOKEN>"
export ADDRESS="<DESTINATION_ADDRESS>"
export AMOUNT="<AMOUNT_IN_BASE_UNITS>"
export WALLET_PASSPHRASE="<YOUR_WALLET_PASSPHRASE>"

curl -X POST \
 http://$BITGO_EXPRESS_HOST/api/v2/$COIN/wallet/$WALLET_ID/sendcoins \
  -H 'Content-Type: application/json' \
  -H "Authorization: Bearer $ACCESS_TOKEN" \
  -d '{
    "address": "'"$ADDRESS"'",
    "amount": "'"$AMOUNT"'",
    "walletPassphrase": "'"$WALLET_PASSPHRASE"'"
}'
```

## Stake

Hemi Ethereum isn't a stakeable asset.
