Skip to content
This repository has been archived by the owner on Nov 4, 2020. It is now read-only.

Latest commit

 

History

History
67 lines (52 loc) · 2.35 KB

smart-contract.md

File metadata and controls

67 lines (52 loc) · 2.35 KB

📜 Smart Contract

Deploy Contract

Getting Test ICON

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

  1. Go to our ICON Example application
  2. Login with your email address
  3. Copy your ICON public address
  4. Go to the ICON Faucet****
  5. Paste your copied ICON public address in the text input
  6. You can receive up to 100 test ICON per day
  7. Now you can use your test ICON in our example app****

Call Extension Method

Note that the Magic ICON extension follows the method names and conventions by ICON's Javascript SDK. (link to documentation). Please follow ICON contract deploy documentation to create and compile the smart contract. To deploy an ICON smart contract, you can call the magic.icon.sendTransaction method to send deploy contract transaction.

{% tabs %} {% tab title="ES Modules/TypeScript" %}

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

import IconService from "icon-sdk-js";

const { DeployTransactionBuilder, IconConverter } = IconService;
 
const magic = new Magic('YOUR_API_KEY', {
  extensions: [
    new IconExtension({
      rpcUrl: 'ICON_RPC_NODE_URL'
    })
  ]
});

const metadata = await magic.user.getMetadata();

// Build a transaction
const txObj = new DeployTransactionBuilder()
  .from(metadata.publicAddress)
  .to('cx0000000000000000000000000000000000000000')
  .stepLimit(IconConverter.toBigNumber(2100000000).toString())
  .nid(IconConverter.toBigNumber(3).toString())
  .nonce(IconConverter.toBigNumber(1).toString())
  .version(IconConverter.toBigNumber(3).toString())
  .timestamp((new Date()).getTime() * 1000)
  .contentType('application/zip')
  .content(`0x${compiledContractContent}`)
  .params({
    initialSupply: IconConverter.toHex('100000000000'),
    decimals: IconConverter.toHex(18),
    name: 'StandardToken',
    symbol: 'ST',
  })
  .build();

// Send transaction to deploy contract
const txhash = await magic.icon.sendTransaction(txObj);

console.log(`Transaction Hash: ${txhash}`);

{% endtab %} {% endtabs %}