Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@magic-sdk/extension-icon

Package Overview
Dependencies
Maintainers
8
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@magic-sdk/extension-icon

magic icon extension

  • 0.1.7
  • unpublished
  • latest
  • npm
  • Socket score

Version published
Weekly downloads
0
Maintainers
8
Weekly downloads
 
Created
Source

Magic Extension Icon Blockchain

Installation

npm i magic-sdk @magic-sdk/extension-icon

Setup

Setup IconExtension with magic-sdk


import { Magic } from 'magic-sdk';
import { IconExtension } from '@magic-sdk/extension-icon';

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

// or

const magic = new Magic('YOUR_API_KEY', {
    extensions: {
        icon: new IconExtension({
            rpcUrl: 'icon 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 Icon public address for current user.

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

Send Transaction

Build the transaction object using builder class.

    /* Build `IcxTransaction` instance for sending ICX. */
    const txObj = new IconBuilder.IcxTransactionBuilder()
                .from("hxe4837d3b902dcaf9abe529f5584489c28d8b4621")
                .to("hxe4837d3b902dcaf9abe529f5584489c28d8b4621")
                .value(IconAmount.of(0.5, IconAmount.Unit.ICX).toLoop())
                .stepLimit(IconConverter.toBigNumber(100000))
                .nid(IconConverter.toBigNumber(3))
                .nonce(IconConverter.toBigNumber(1))
                .version(IconConverter.toBigNumber(3))
                .timestamp((new Date()).getTime() * 1000)
                .build();
    
    /* Build `MessageTransaction` instance for sending data. */
    const txObj = new IconBuilder.MessageTransactionBuilder()
                  .from('hxe4837d3b902dcaf9abe529f5584489c28d8b4621')
                  .to('hxe4837d3b902dcaf9abe529f5584489c28d8b4621')
                  .stepLimit(IconConverter.toBigNumber(1000000))
                  .nid(IconConverter.toBigNumber(3))
                  .nonce(IconConverter.toBigNumber(1))
                  .version(IconConverter.toBigNumber(3))
                  .timestamp((new Date()).getTime() * 1000)
                  .data(IconConverter.fromUtf8('Hello'))
                  .build();
           
    /* Build `DeployTransaction` instance for deploying SCORE. */
    const txObj = new DeployTransactionBuilder()
                .from('hxe4837d3b902dcaf9abe529f5584489c28d8b4621')
                .to('cx0000000000000000000000000000000000000000')
                .stepLimit(IconConverter.toBigNumber(2100000000))
                .nid(IconConverter.toBigNumber(3))
                .nonce(IconConverter.toBigNumber(1))
                .version(IconConverter.toBigNumber(3))
                .timestamp((new Date()).getTime() * 1000)
                .contentType('application/zip')
                .content(`0x${content}`)
                .params({
                    initialSupply: IconConverter.toHex('100000000000'),
                    decimals: IconConverter.toHex(18),
                    name: 'StandardToken',
                    symbol: 'ST',
                })
                .build();
    
    /* Build `CallTransaction` instance for executing SCORE function. */
    const txObj = new IconBuilder.CallTransactionBuilder()
                .from('hxe4837d3b902dcaf9abe529f5584489c28d8b4621')
                .to('cxd1602bde1d4b2b4facc8673c661c5e59e6ac20b4')
                .stepLimit(IconConverter.toBigNumber('2000000'))
                .nid(IconConverter.toBigNumber('3'))
                .nonce(IconConverter.toBigNumber('1'))
                .version(IconConverter.toBigNumber('3'))
                .timestamp((new Date()).getTime() * 1000)
                .method('hello')
                .params({})

By passing txObj instance to magic.icon.sendTransaction() method, it will automatically sign the transaction with current user and generate transaction object including signature, then send to ICON node.

    const txhash = await magic.icon.sendTransaction(txObj);

    console.log('transaction result', txhash);
    window.open(`https://bicon.tracker.solidwallet.io/transaction/${txhash}`)

FAQs

Package last updated on 01 May 2020

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc