> ## Documentation Index
> Fetch the complete documentation index at: https://docs.magic.link/llms.txt
> Use this file to discover all available pages before exploring further.

# Harmony

## Overview

[Harmony](https://www.harmony.one/) (ONE) blockchain is an L2 blockchain platform built on the Ethereum network, making it easier for developers to create decentralized apps.

**As Harmony is EVM compatible**, you can follow the [Ethereum](/embedded-wallets/blockchains/ethereum/javascript)documentation to send your first transaction and utilize all other wallet features.

## Installation

Magic interacts with the [Harmony](https://www.harmony.one/) blockchain via Magic's extension NPM package [`@magic-ext/harmony`](https://www.npmjs.com/package/@magic-ext/harmony). The Harmony extension also lets you interact with the blockchain using methods from [Harmony's JavaScript SDK](https://github.com/harmony-one/sdk).

<CodeGroup>
  ```bash NPM icon="npm" theme={null}
  npm install --save @magic-ext/harmony
  ```

  ```bash Yarn icon="yarn" theme={null}
  yarn add @magic-ext/harmony
  ```
</CodeGroup>

## Configure Harmony

```js JavaScript icon="square-js" theme={null}
import { Magic } from 'magic-sdk';
import { HarmonyExtension } from '@magic-ext/harmony';
const { Harmony: Index } = require('@harmony-js/core');
const { ChainID, ChainType } = require('@harmony-js/utils');

const magic = new Magic('YOUR_API_KEY', {
  extensions: [
    new HarmonyExtension({
      rpcUrl: 'https://api.s0.b.hmny.io',
      chainId: ChainID.HmyTestnet,
    }),
  ],
});
```

## Send Transaction

### Getting Test ONE token

Before you can send transaction on the Harmony blockchain, you'll need to acquire some test ONE token (Harmony's native cryptocurrency for test network).

1. Go to our [**Harmony Example**](https://go.magic.link/example-harmony) application
2. Login with your email address
3. Copy your Harmony public address
4. Go to the [**Harmony Faucet**](https://onefaucet.ibriz.ai/)
5. Paste your copied Harmony public address in the text input
6. Now you can use your test ONE token in our [**example app**](https://go.magic.link/example-harmony)

### Call Extension Method

Note that the Magic Harmony extension follows the method names and conventions by [**Harmony's JavaScript SDK**](https://github.com/harmony-one/sdk). To send a standard Harmony blockchain transaction, you can call the `magic.harmony.sendTransaction` method.

```js JavaScript icon="square-js" theme={null}
import { Magic } from 'magic-sdk';
import { HarmonyExtension } from '@magic-ext/harmony';
const { Harmony: Index } = require('@harmony-js/core');
const { ChainID, ChainType } = require('@harmony-js/utils');

const magic = new Magic('YOUR_API_KEY', {
  extensions: [
    new HarmonyExtension({
      rpcUrl: 'https://api.s0.b.hmny.io',
      chainId: ChainID.HmyTestnet,
    }),
  ],
});

const params = {
  //  token send to
  to: 'one1jzxhswufkh7wgyq7s49u3rvp9vlts8wcwsq8y2',
  // amount to send
  value: '50000',
  // gas limit, you can use string
  gasLimit: '210000',
  // send token from shardID
  shardID: 0,
  // send token to toShardID
  toShardID: 0,
  // gas Price, you can use Unit class, and use Gwei, then remember to use toWei(), which will be transformed to BN
  gasPrice: 1000000000,
};

const txHash = await magic.harmony.sendTransaction(params);

console.log('transaction hash', txHash);
```

## Smart Contract

### Deploy Contract

#### Getting Test ONE token

Before you can send transaction on the Harmony blockchain, you'll need to acquire some test ONE token (Harmony's native cryptocurrency for test network).

1. Go to our [**Harmony Example**](https://go.magic.link/example-harmony) application
2. Login with your email address
3. Copy your Harmony public address
4. Go to the [**Harmony Faucet**](https://faucet.pops.one/)
5. Paste your copied Harmony public address in the text input
6. Now you can use your test ONE token in our [**example app**](https://go.magic.link/example-harmony)

#### Call Extension Method

Note that the Magic Harmony extension follows the method names and conventions by [**Harmony's JavaScript SDK**](https://github.com/harmony-one/sdk). To deploy an Harmony smart contract, you can call the `magic.harmony.sendTransaction` method to send deploy contract transaction.

```js JavaScript icon="square-js" theme={null}
import { Magic } from 'magic-sdk';
import { HarmonyExtension } from '@magic-ext/harmony';
const { Harmony: Index } = require('@harmony-js/core');
const { ChainID, ChainType } = require('@harmony-js/utils');

const magic = new Magic('YOUR_API_KEY', {
  extensions: [
    new HarmonyExtension({
      rpcUrl: 'https://api.s0.b.hmny.io',
      chainId: ChainID.HmyTestnet,
    }),
  ],
});

const bin =
  '608060405234801561001057600080fd5b5060c68061001f6000396000f3fe6080604052348015600f576000' +
  '80fd5b506004361060325760003560e01c80636057361d146037578063b05784b8146062575b600080fd5b6060600480' +
  '36036020811015604b57600080fd5b8101908080359060200190929190505050607e565b005b60686088565b60405180' +
  '82815260200191505060405180910390f35b8060008190555050565b6000805490509056fea265627a7a723158209e86' +
  '9bf97eba094ccf7533f0f92b4de32cf3cce7d7cff974769bca975e178b0164736f6c63430005110032';

const contractBytecode = {
  data: `0x${bin}`,
  gasLimit: '210000',
  // send token from shardID
  shardID: 0,
  // send token to toShardID
  toShardID: 0,
  // gas Price, you can use Unit class, and use Gwei, then remember to use toWei(), which will be transformed to BN
  gasPrice: 1000000000,
  arguments: [],
};

const txHash = await magic.harmony.sendTransaction(contractBytecode);

console.log('transaction hash', txHash);
```

### Contract Send

#### Getting Test ONE token

Before you can send transaction on the Harmony blockchain, you'll need to acquire some test ONE token (Harmony's native cryptocurrency for test network).

1. Go to our [**Harmony Example**](https://go.magic.link/example-harmony) application
2. Login with your email address
3. Copy your Harmony public address
4. Go to the [**Harmony Faucet**](https://onefaucet.ibriz.ai/)
5. Paste your copied Harmony public address in the text input
6. Now you can use your test ONE token in our [**example app**](https://go.magic.link/example-harmony)

#### Call Extension Method

Note that the Magic Harmony extension follows the method names and conventions by [**Harmony's JavaScript SDK**](https://github.com/harmony-one/sdk). To call an Harmony smart contract function, you can call the `magic.harmony.sendTransaction` method to send contract transaction.

```js JavaScript icon="square-js" theme={null}
import { Magic } from 'magic-sdk';
import { HarmonyExtension } from '@magic-ext/harmony';
const { Harmony: Index } = require('@harmony-js/core');
const { ChainID, ChainType } = require('@harmony-js/utils');

const magic = new Magic('YOUR_API_KEY', {
  extensions: [
    new HarmonyExtension({
      rpcUrl: 'https://api.s0.b.hmny.io',
      chainId: ChainID.HmyTestnet,
    }),
  ],
});

const harmony = new Index(
  // rpc url
  'https://api.s0.b.hmny.io',
  {
    // chainType set to Index
    chainType: ChainType.Harmony,
    // chainType set to HmyLocal
    chainId: ChainID.HmyTestnet,
  },
);

let contractAddress = '0x67a3f8db0c98524e8e4513f95cd68f7fbbca7f06';

const contractAbi = [
  {
    constant: false,
    inputs: [
      {
        internalType: 'uint256',
        name: 'num',
        type: 'uint256',
      },
    ],
    name: 'store',
    outputs: [],
    payable: false,
    stateMutability: 'nonpayable',
    type: 'function',
  },
  {
    constant: true,
    inputs: [],
    name: 'retreive',
    outputs: [
      {
        internalType: 'uint256',
        name: '',
        type: 'uint256',
      },
    ],
    payable: false,
    stateMutability: 'view',
    type: 'function',
  },
];

const deployedContract = harmony.contracts.createContract(contractAbi, contractAddress);

const tx = await deployedContract.methods.store(900);

let { txPayload } = tx.transaction;

txPayload.from = (await magic.user.getMetadata()).publicAddress;
txPayload.gasLimit = '210000';
txPayload.gasPrice = '1000000000';

const txHash = await magic.harmony.sendTransaction(txPayload);

console.log('transaction hash', txHash);
```

## Compatibility

* All `Auth`, `User` and most `Wallet` module methods\*
* All EVM Provider functionality to respond to supported [RPC methods](/embedded-wallets/sdk/client-side/javascript#evm-rpc-methods)
* Widget UI for token balances and token transfers\*

*\*Some features are not yet compatible such as NFT Viewer and Fiat On-ramps.*

*Need a feature or see a problem?* File an issue on our [github repo](https://github.com/magiclabs/magic-js).

## Resources & Tools

* Documentation: [https://docs.harmony.one/home/](https://docs.harmony.one/home/)
* Block Explorer: [https://explorer.harmony.one/](https://explorer.harmony.one/) (Mainnet)
* Faucet: [https://onefaucet.ibriz.ai/](https://onefaucet.ibriz.ai/)
* [Example](https://go.magic.link/example-harmony)
