How to use icon-sdk-js - 10 common examples

To help you get started, we’ve selected a few icon-sdk-js examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github icon-project / icon-sdk-js / quickstart / example / js / IcxTransactionExample.js View on Github external
async sendTransaction() {
        // Build raw transaction object
        const transaction = await this.buildICXTransaction();
        // Create signature of the transaction
        const signedTransaction = new SignedTransaction(transaction, this.wallet);
        // Read params to transfer to nodes
        const signedTransactionProperties = JSON.stringify(signedTransaction.getProperties()).split(",").join(", \n")
        document.getElementById('I01-1').innerHTML = `<b>Signed Transaction</b>: ${signedTransactionProperties}`;
        // Send transaction
        this.txHash = await this.iconService.sendTransaction(signedTransaction).execute();
        console.log(this.txHash)
        document.getElementById('I03-1').innerHTML = this.txHash;
        // Print transaction hash
        document.getElementById('I01-2').innerHTML = `<b>Transfer Request Complete.</b> Tx hash is ${this.txHash}`;
    }
github icon-project / icon-sdk-js / quickstart / example / js / DeployAndTransferTokenExample.js View on Github external
const contentType = "application/zip";
        // Enter token information
        // key name ("initialSupply", "decimals", "name", "symbol")
        // You must enter the given values. Otherwise, your transaction will be rejected.
        const params = {
            initialSupply: IconConverter.toHex(initialSupply),
            decimals: IconConverter.toHex(decimals),
            name: tokenName,
            symbol: tokenSymbol
        }
        const installScore = MockData.SCORE_INSTALL_ADDRESS;
        const stepLimit = await this.getMaxStepLimit();
        const walletAddress = this.wallet.getAddress();
        // networkId of node 1:mainnet, 2~:etc
        const networkId = IconConverter.toBigNumber(3);
        const version = IconConverter.toBigNumber(3);
        // Timestamp is used to prevent the identical transactions. Only current time is required (Standard unit : us)
        // If the timestamp is considerably different from the current time, the transaction will be rejected.
        const timestamp = (new Date()).getTime() * 1000;

        //Enter transaction information
        const deployTransactionBuilder = new DeployTransactionBuilder();
        const transaction = deployTransactionBuilder
            .nid(networkId)
            .from(walletAddress)
            .to(installScore)
            .stepLimit(stepLimit)
            .timestamp(timestamp)
            .contentType(contentType)
            .content(`0x${this.content}`)
            .params(params)
            .version(version)
github icon-project / icon-sdk-js / quickstart / example / js / DeployAndTransferTokenExample.js View on Github external
async buildDeployTransaction() {
        const { DeployTransactionBuilder } = IconBuilder;

        const initialSupply = IconConverter.toBigNumber("100000000000");
        const decimals = IconConverter.toBigNumber("18");
        const tokenName = "StandardToken";
        const tokenSymbol = "ST";
        const contentType = "application/zip";
        // Enter token information
        // key name ("initialSupply", "decimals", "name", "symbol")
        // You must enter the given values. Otherwise, your transaction will be rejected.
        const params = {
            initialSupply: IconConverter.toHex(initialSupply),
            decimals: IconConverter.toHex(decimals),
            name: tokenName,
            symbol: tokenSymbol
        }
        const installScore = MockData.SCORE_INSTALL_ADDRESS;
        const stepLimit = await this.getMaxStepLimit();
        const walletAddress = this.wallet.getAddress();
github icon-project / icon-sdk-js / quickstart / example / js / DeployAndTransferTokenExample.js View on Github external
const methodName = 'getStepCosts';
        // Check input and output parameters of api if you need
        const getStepCostsApi = governanceApi.getMethod(methodName);
        const getStepCostsApiInputs = getStepCostsApi.inputs.length > 0 ? JSON.stringify(getStepCostsApi.inputs) : 'none';
        const getStepCostsApiOutputs = getStepCostsApi.outputs.length > 0 ? JSON.stringify(getStepCostsApi.outputs) : 'none';
        console.log(`[getStepCosts]\n inputs: ${getStepCostsApiInputs} \n outputs: ${getStepCostsApiOutputs}`);

        // Get step costs by iconService.call
        const callBuilder = new CallBuilder();
        const call = callBuilder
            .to(MockData.GOVERNANCE_ADDRESS)
            .method(methodName)
            .build();
        const stepCosts = await this.iconService.call(call).execute();
        // For sending token, it is about twice the default value.
        return IconConverter.toBigNumber(stepCosts.default).times(2)
    }
github icon-project / icon-sdk-js / quickstart / example / js / IcxTransactionExample.js View on Github external
async buildICXTransaction() {
        const { IcxTransactionBuilder } = IconBuilder;

        const walletAddress = this.wallet.getAddress();
        // 1 ICX -> 1000000000000000000 conversion
        const value = IconAmount.of(1, IconAmount.Unit.ICX).toLoop();
        // You can use "governance score apis" to get step costs.
        const stepLimit = await this.getDefaultStepCost();
        // networkId of node 1:mainnet, 2~:etc
        const networkId = IconConverter.toBigNumber(3);
        const version = IconConverter.toBigNumber(3);
        // Timestamp is used to prevent the identical transactions. Only current time is required (Standard unit : us)
        // If the timestamp is considerably different from the current time, the transaction will be rejected.
        const timestamp = (new Date()).getTime() * 1000;
        
        //Enter transaction information
        const icxTransactionBuilder = new IcxTransactionBuilder();
        const transaction = icxTransactionBuilder
            .nid(networkId)
            .from(walletAddress)
            .to(MockData.WALLET_ADDRESS_2)
            .value(value)
            .stepLimit(stepLimit)
            .timestamp(timestamp)
            .version(version)
            .build();
github icon-project / icon-sdk-js / quickstart / example / js / IcxTransactionExample.js View on Github external
async buildICXTransaction() {
        const { IcxTransactionBuilder } = IconBuilder;

        const walletAddress = this.wallet.getAddress();
        // 1 ICX -> 1000000000000000000 conversion
        const value = IconAmount.of(1, IconAmount.Unit.ICX).toLoop();
        // You can use "governance score apis" to get step costs.
        const stepLimit = await this.getDefaultStepCost();
        // networkId of node 1:mainnet, 2~:etc
        const networkId = IconConverter.toBigNumber(3);
        const version = IconConverter.toBigNumber(3);
        // Timestamp is used to prevent the identical transactions. Only current time is required (Standard unit : us)
        // If the timestamp is considerably different from the current time, the transaction will be rejected.
        const timestamp = (new Date()).getTime() * 1000;
        
        //Enter transaction information
        const icxTransactionBuilder = new IcxTransactionBuilder();
        const transaction = icxTransactionBuilder
            .nid(networkId)
            .from(walletAddress)
            .to(MockData.WALLET_ADDRESS_2)
            .value(value)
            .stepLimit(stepLimit)
            .timestamp(timestamp)
            .version(version)
            .build();        
        return transaction;
github icon-project / icon-sdk-js / quickstart / example / js / TokenTransactionExample.js View on Github external
const methodName = 'getStepCosts';
        // Check input and output parameters of api if you need
        const getStepCostsApi = governanceApi.getMethod(methodName);
        const getStepCostsApiInputs = getStepCostsApi.inputs.length > 0 ? JSON.stringify(getStepCostsApi.inputs) : 'none';
        const getStepCostsApiOutputs = getStepCostsApi.outputs.length > 0 ? JSON.stringify(getStepCostsApi.outputs) : 'none';
        console.log(`[getStepCosts]\n inputs: ${getStepCostsApiInputs} \n outputs: ${getStepCostsApiOutputs}`);

        // Get step costs by iconService.call
        const callBuilder = new CallBuilder();
        const call = callBuilder
            .to(MockData.GOVERNANCE_ADDRESS)
            .method(methodName)
            .build();
        const stepCosts = this.iconService.call(call).execute();
        // For sending token, it is about twice the default value.
        return IconConverter.toBigNumber(stepCosts.default).times(2)
    }
github icon-project / icon-sdk-js / quickstart / example / js / TokenTransactionExample.js View on Github external
// Method name to check the balance
        const methodName = "balanceOf";
        // You must enter the given key name (“_owner”).
        const params = {
            _owner: address
        }
        const callBuilder = new CallBuilder();
        const call = callBuilder
            .to(tokenAddress)
            .method(methodName)
            .params(params)
            .build();
        // Check the wallet balance
        const balance = this.iconService.call(call).execute();
        const htmlId = address === MockData.WALLET_ADDRESS_1 ? 'T02-1' : 'T02-2';
        document.getElementById(htmlId).innerHTML = `<b>${IconAmount.of(balance, IconAmount.Unit.LOOP).convertUnit(IconAmount.Unit.ICX)}</b>`;
    }
github icon-project / icon-sdk-js / quickstart / example / js / DeployAndTransferTokenExample.js View on Github external
// Method name to check the balance
        const methodName = "balanceOf";
        // You must enter the given key name (“_owner”).
        const params = {
            _owner: address
        }
        const callBuilder = new CallBuilder();
        const call = callBuilder
            .to(tokenAddress)
            .method(methodName)
            .params(params)
            .build();
        // Check the wallet balance
        const balance = await this.iconService.call(call).execute();
        const htmlId = address === MockData.WALLET_ADDRESS_1 ? 'D04-2' : 'D04-3';
        document.getElementById(htmlId).innerHTML = `<b>${IconAmount.of(balance, IconAmount.Unit.LOOP).convertUnit(IconAmount.Unit.ICX)}</b>`;
    }
github icon-project / icon-sdk-js / quickstart / example / js / DeployAndTransferTokenExample.js View on Github external
async buildDeployTransaction() {
        const { DeployTransactionBuilder } = IconBuilder;

        const initialSupply = IconConverter.toBigNumber("100000000000");
        const decimals = IconConverter.toBigNumber("18");
        const tokenName = "StandardToken";
        const tokenSymbol = "ST";
        const contentType = "application/zip";
        // Enter token information
        // key name ("initialSupply", "decimals", "name", "symbol")
        // You must enter the given values. Otherwise, your transaction will be rejected.
        const params = {
            initialSupply: IconConverter.toHex(initialSupply),
            decimals: IconConverter.toHex(decimals),
            name: tokenName,
            symbol: tokenSymbol
        }
        const installScore = MockData.SCORE_INSTALL_ADDRESS;
        const stepLimit = await this.getMaxStepLimit();
        const walletAddress = this.wallet.getAddress();
        // networkId of node 1:mainnet, 2~:etc
        const networkId = IconConverter.toBigNumber(3);
        const version = IconConverter.toBigNumber(3);
        // Timestamp is used to prevent the identical transactions. Only current time is required (Standard unit : us)
        // If the timestamp is considerably different from the current time, the transaction will be rejected.
        const timestamp = (new Date()).getTime() * 1000;

        //Enter transaction information
        const deployTransactionBuilder = new DeployTransactionBuilder();