Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
// 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 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)
buildTokenTransaction() {
const { Builder } = this.iconService;
const { CallTransactionBuilder } = Builder;
const walletAddress = this.wallet.getAddress();
// You can use "governance score apis" to get step costs.
const value = IconAmount.of(1, IconAmount.Unit.ICX).toLoop();
const stepLimit = 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;
// SCORE name that send transaction is “transfer”.
const methodName = "transfer";
// Enter receiving address and the token value.
// You must enter the given key name("_to", "_value"). Otherwise, the transaction will be rejected.
const params = {
_to: MockData.WALLET_ADDRESS_2,
_value: IconConverter.toHex(value)
}
async buildTokenTransaction() {
const { CallTransactionBuilder } = IconBuilder;
const walletAddress = this.wallet.getAddress();
// You can use "governance score apis" to get step costs.
const value = IconAmount.of(1, IconAmount.Unit.ICX).toLoop();
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;
// SCORE name that send transaction is “transfer”.
const methodName = "transfer";
// Enter receiving address and the token value.
// You must enter the given key name("_to", "_value"). Otherwise, the transaction will be rejected.
const params = {
_to: MockData.WALLET_ADDRESS_2,
_value: IconConverter.toHex(value)
}
async getWalletBalance() {
const balanceA = await this.iconService.getBalance(MockData.WALLET_ADDRESS_1).execute();
const balanceB = await this.iconService.getBalance(MockData.WALLET_ADDRESS_2).execute();
document.getElementById('I02-1').innerHTML = `<b>${IconAmount.of(balanceA, IconAmount.Unit.LOOP).convertUnit(IconAmount.Unit.ICX)}`;
document.getElementById('I02-2').innerHTML = `<b>${IconAmount.of(balanceB, IconAmount.Unit.LOOP).convertUnit(IconAmount.Unit.ICX)}`;
}
</b></b>