23.0.2 • Published 9 days ago

@magic-ext/harmony v23.0.2

Weekly downloads
-
License
MIT
Repository
github
Last release
9 days ago

Magic Extension Harmony Blockchain

Installation

npm i magic-sdk @magic-ext/harmony

Setup

Setup HarmonyExtension with magic-sdk

import { Magic } from 'magic-sdk';
import { HarmonyExtension } from '@magic-ext/harmony';

const magic = new Magic('YOUR_API_KEY', {
    extensions: [
        new HarmonyExtension({
            rpcUrl: 'harmony rpc url'
        })
    ]
});

// or

const magic = new Magic('YOUR_API_KEY', {
    extensions: {
        hmy: new HarmonyExtension({
            rpcUrl: 'harmony rpc url'
        })
    }
});

Magic SDK

See the developer documentation to learn how you can master the Magic SDK in a matter of minutes.

Usage

Send Transaction

By passing transaction payload to magic.harmony.sendTransaction() method, it will automatically sign the transaction with current user and generate transaction object including signature, then send to Harmony node.

  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 tx = await magic.harmony.sendTransaction(params)

  console.log(tx)

Deploy Contract

By passing deploy contract payload to magic.harmony.sendTransaction() method, it will automatically sign the transaction with current user and generate transaction object including signature, then send to Harmony node.

  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 tx = await magic.harmony.sendTransaction(contractBytecode);

console.log(tx)

Contract Send

By passing contract send payload to magic.harmony.sendTransaction() method, it will automatically sign the transaction with current user and generate transaction object including signature, then send to Harmony node.

const deployedContract = harmony.contracts.createContract(
   contractAbi,
   contractAddress
);

const tx = await deployedContract.methods.store(900);

let { txPayload } = tx.transaction;

txPayload.from = "one1jzxhswufkh7wgyq7s49u3rvp9vlts8wcwsq8y2";
txPayload.gasLimit = '210000';
txPayload.gasPrice = '1000000000';


const txn = await magic.harmony.sendTransaction(txPayload)

console.log(txn)
23.0.2

1 month ago

23.0.1

2 months ago

23.0.0

2 months ago

22.0.0

2 months ago

21.0.0

2 months ago

19.0.0

2 months ago

20.0.0

2 months ago

18.0.0

2 months ago

17.1.1

3 months ago

17.1.0

3 months ago

17.0.1

3 months ago

17.0.0

4 months ago

16.5.0

4 months ago

16.4.1

5 months ago

16.4.0

5 months ago

13.3.0

10 months ago

14.1.0

9 months ago

15.0.2

8 months ago

15.0.3

7 months ago

15.0.0

8 months ago

15.0.1

8 months ago

13.4.0

10 months ago

13.4.1

10 months ago

14.2.0

9 months ago

16.3.2

5 months ago

16.3.1

6 months ago

16.3.0

6 months ago

14.0.0

10 months ago

13.2.1

10 months ago

14.5.0

8 months ago

16.1.1

7 months ago

16.1.0

7 months ago

16.2.0

7 months ago

16.2.1

6 months ago

15.1.1

7 months ago

15.1.0

7 months ago

13.5.0

10 months ago

14.3.0

9 months ago

13.6.0

10 months ago

14.4.0

9 months ago

14.4.1

9 months ago

16.0.0

7 months ago

13.1.0

11 months ago

13.2.0

11 months ago

12.2.1

12 months ago

12.4.0

11 months ago

12.2.0

12 months ago

13.0.0

11 months ago

13.0.1

11 months ago

12.3.0

12 months ago

12.1.3

12 months ago

12.1.4

12 months ago

12.1.5

12 months ago

10.0.0

1 year ago

8.6.2

1 year ago

8.6.1

1 year ago

8.6.0

1 year ago

12.0.0

1 year ago

11.2.0

1 year ago

11.0.0

1 year ago

11.0.1

1 year ago

10.1.0

1 year ago

8.5.0

1 year ago

12.1.2

1 year ago

12.1.0

1 year ago

12.1.1

1 year ago

9.0.0

1 year ago

11.1.0

1 year ago

8.3.0

1 year ago

8.2.0

1 year ago

8.4.0

1 year ago

5.1.0

1 year ago

8.1.0

1 year ago

8.0.0

1 year ago

6.0.0

1 year ago

7.0.0

1 year ago

4.1.0

2 years ago

5.0.0

2 years ago

4.0.0

2 years ago

3.1.1

2 years ago

3.1.0

2 years ago

3.0.1

2 years ago

3.0.0

2 years ago

1.0.0

2 years ago

2.0.0

2 years ago

0.1.0

4 years ago