Cloud Defense Logo

Products

Solutions

Company

Book A Live Demo

Top 10 Examples of "icon-sdk-js in functional component" in JavaScript

Dive into secure and efficient coding practices with our curated list of the top 10 examples showcasing 'icon-sdk-js' in functional components in JavaScript. Our advanced machine learning engine meticulously scans each line of code, cross-referencing millions of open source libraries to ensure your implementation is not just functional, but also robust and secure. Elevate your React applications to new heights by mastering the art of handling side effects, API calls, and asynchronous operations with confidence and precision.

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}`;
    }
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)
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();
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)
    }
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();
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;
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)
    }
// 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>`;
    }
// 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>`;
    }
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();

Is your System Free of Underlying Vulnerabilities?
Find Out Now