@magic-ext/polkadot
TypeScript icon, indicating that this package has built-in type declarations

23.0.6 • Public • Published

Magic Extension Polkadot Blockchain

Installation

npm i magic-sdk @magic-ext/polkadot

Setup

Setup PolkadotExtension with magic-sdk

import { Magic } from 'magic-sdk';
import { PolkadotExtension } from '@magic-ext/polkadot';

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

// or

const magic = new Magic('YOUR_API_KEY', {
    extensions: {
        polkadot: new PolkadotExtension({
            rpcUrl: 'polkadot rpc url'
        })
    }
});

Magic SDK

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

Usage

Get account

Using getAccount function to get Polkadot public address for current user.

const publicAddress = await magic.polkadot.getAccount();
console.log('icon public address', publicAddress);

Send Transaction

Send polkadot native currency

      const handlerSendTransaction = async () => {

          const tx = await magic.polkadot.sendTransaction(
              '5H3pELHbg9skXE2HfLqP23UPgrgu2Juj55CH6sdDGWc2HKNs',
              1000000000000000,
          );

          console.log('transaction hash', tx)
      };

Call contract function as transaction

    const handlerContractCall = async () => {

          const api = await ApiPromise.create({ provider: new WsProvider('ws://127.0.0.1:9944/') });
          await api.isReady;
          const abi = new Abi(api.registry, contractABI);

          const data = abi.messages.flip();

          const tx = await magic.polkadot.contractCall('5C52CfgkwANdFuN3VgPSprQwNWKfkLWMHJbMRzp12h4YarCa', 0, 1000000, data);

          console.log('transaction hash', tx)
      }

Readme

Keywords

none

Package Sidebar

Install

npm i @magic-ext/polkadot

Weekly Downloads

356

Version

23.0.6

License

MIT

Unpacked Size

24.2 kB

Total Files

15

Last publish

Collaborators

  • ritalestermagic
  • darrentmagic
  • romin-halltari
  • magictristan
  • musicbender
  • jay.hwang
  • benmagic
  • dizigen
  • sgdheeban
  • mikeysight
  • ethella
  • damianjachyra
  • magiclabs_fe
  • jasonatmagic
  • bcleary06
  • hcote
  • seanli