flutter_icon_network 1.0.0 flutter_icon_network: ^1.0.0 copied to clipboard
ICON SDK for Flutter. ICON supports SDK for 3rd party or user services development. You can integrate ICON SDK for your project and utilize ICON’s functionality.
ICON SDK for Flutter #
ICON supports SDK for 3rd party or user services development. You can integrate ICON SDK for your project and utilize ICON’s functionality.
This document is focused on how to use the SDK properly. For the detailed API specification, see the API reference documentation.
Version #
1.0.0
Prerequisite #
This Flutter SDK works on the following platforms:
- Dart: >=2.12.0 <3.0.0
- Flutter: >=2.4.0
Installation #
From specific git
flutter_icon_network:
git: https://git.baikal.io/mobile/boilerplate/flutter_icon_network
Or pub.dev
flutter_icon_network: ^1.0.0
Quick Start #
We provide different types of code examples to help you to start quickly from scratch. This is an example project of ICON SDK Flutter. In this project, the examples are implemented as follows.
Example | Description |
---|---|
WalletExample | An example of creating and loading a wallet. |
IcxTransactionExample | An example of transferring ICX and confirming the result. |
DeployTokenExample | An example of deploying token. |
TokenTransactionExample | An example of transferring IRC token and confirming the result. |
SyncBlockExample | An example of checking block confirmation and printing the ICX and token transfer information. |
FlutterIconNetwork #
APIs are called through FlutterIconNetwork
.
FlutterIconNetwork
can be initialized as follows.
// FlutterIconNetwork is a singleton class. Make sure you call at the first time in the main.dart file
FlutterIconNetwork.instance.init(host: "https://bicon.net.solidwallet.io/api/v3", isTestNet: true);
host
: the network url, check the mainnet or testnet url at https://www.icondev.io/introduction/the-icon-networkisTestNet
: use Testnet or Mainnet
Wallet #
This example shows how to create a new wallet or load wallet with a private key.
Create a wallet
Create new EOA by calling the function below. After creation, the address and private key can be looked up.
final wallet = await FlutterIconNetwork.instance.createWallet;
print("address": "${wallet['address']}");
print("privateKey": "${wallet['private_key']}");
// Output
address:hx4d37a7013c14bedeedbe131c72e97ab337aea159
privateKey:00e1d6541bfd8be7d88be0d24516556a34ab477788022fa07b4a6c1d862c4de516
Load a wallet
You can call existing EOA by calling load
function.
After creation, address and private key can be looked up.
final wallet = await FlutterIconNetwork.instance.load(/*YOUR_PRIVATE_KEY*/);// Load wallet with privateKey
print("address": "${wallet['address']}"); // Address lookup
print("privateKey": "${wallet['private_key']}");// PrivateKey lookup
ICX Transfer #
This example shows how to transfer ICX and check the result.
ICX transfer transaction
In this example, send 1 ICX to an address and return the transaction hash
final txHash = await FlutterIconNetwork.instance.sendIcx(
yourPrivateKey: /*YOUR_PRIVATE_KEY*/,
destinationAddress: /*RECEIVE_ADDRESS*/,
value: 1)
print("txHash $txHash");
// Output
txHash: 0x64bd29d0cf2a51a6ea0e0c01dab823295210fe3bd1bc4a831217fdb0789bfa3f
Check the transaction result after sending ICX, by running:
final tResult = await FlutterIconNetwork.instance!.getTransactionResult(
"0x64bd29d0cf2a51a6ea0e0c01dab823295210fe3bd1bc4a831217fdb0789bfa3f");
print("tResult $tResult");
// Output
tResult: {
block_hash: 0x2e13ecd1c65656ce6985edee1ee644862518894bf4ed5adefda11ff644f2f314,
block_height: 20346610,
cumulative_step_used: 173580,
to: cx24781bef9b47a52f63aa6cb8b61268753c141b1f,
txHash: 0x64bd29d0cf2a51a6ea0e0c01dab823295210fe3bd1bc4a831217fdb0789bfa3f,
score_address: null,
step_used: 173580,
status: 1,
step_price: 12500000000,
tx_index: 1
}
Check the ICX balance
In this example, you can check the ICX balance by looking up the transaction before and after the transaction.
ICX balance can be confirmed by calling getIcxBalance
function from FlutterIconNetwork
final balance = await FlutterIconNetwork.instance.getIcxBalance(privateKey: /*YOUR_PRIVATE_KEY*/);
print("balance: $balance")
// Output
balance:5000000000000000000
Token Deploy and Transfer #
This example shows how to deploy a token and check the result. After that, shows how to send tokens and check the balance.
Token deploy transaction
You need a SCORE project to deploy token. Only available in Android, on iOS the SDK not support yet
In this example, To deploy a SCORE by choose the zip file contain the source code the sampleToken.zip file contain in source code, please download it to your phone.
Prepare basic information of the token you want to deploy and make a parameter object.
final transactionResult = await FlutterIconNetwork.instance.deployScore(
privateKey: /*YOUR_PRIVATE_KEY*/, initIcxSupply: "10");
Token transfer
To send token to an address through SCORE
final response = await FlutterIconNetwork.instance.sendToken(
yourPrivateKey: /*PRIVATE_KEY*/,
toAddress: /*RECEIVE_ADDRESS*/,
value: /*NUMBER_OF_TOKEN*/,
scoreAddress: /*SCORE_ADDRESS*/);
Check the transaction result after sending ICX, by running:
final tResult = await FlutterIconNetwork.instance!.getTransactionResult(
"0x64bd29d0cf2a51a6ea0e0c01dab823295210fe3bd1bc4a831217fdb0789bfa3f");
print("tResult $tResult");
// Output
tResult: {
block_hash: 0x2e13ecd1c65656ce6985edee1ee644862518894bf4ed5adefda11ff644f2f314,
block_height: 20346610,
cumulative_step_used: 173580,
to: cx24781bef9b47a52f63aa6cb8b61268753c141b1f,
txHash: 0x64bd29d0cf2a51a6ea0e0c01dab823295210fe3bd1bc4a831217fdb0789bfa3f,
score_address: null,
step_used: 173580,
status: 1,
step_price: 12500000000,
tx_index: 1
}
Check token balance
To check the token balance in SCORE
final balance = await FlutterIconNetwork.instance.getTokenBalance(
privateKey: /*PRIVATE_KEY*/,
scoreAddress: /*SCORE_ADDRESS*/);
Sync Block #
This example shows how to read block information and print the transaction result for every block creation.
Read block information
In this example, getLastBlock
is called periodically in order to check the new blocks,
by updating the transaction information for every block creation.
// Check the recent blocks
final lastBlock = await FlutterIconNetwork.instance!.getLastBlock();
print("block height: ${lastBlock['height']}")
// Output
block height: 0x1384b04
If a new block has been created, get the transaction list.
final transactionList = await FlutterIconNetwork.instance!.getConfirmedTransactionIdList();
print("lenght: ${transactionList.lenght}")
print("Transaction at item 0: ${transactionList[0]}")
// Output
lenght: 1
Transaction at item 0: 0x74bb8bc3a3f1e45fda18cac1746941e9f9f909e0783bd851f624a5a9b56a90d1
Check the token name & symbol
You can check the token SCORE by calling the checkScoreTokenName
and checkScoreTokenSymbol
functions.
final name = await FlutterIconNetwork.instance!.checkScoreTokenName("cx9e7f89f7f7fa8bd5d56e67282328a3ca87a082b1");
final symbol = await FlutterIconNetwork.instance!.checkTokenSymbol("cx9e7f89f7f7fa8bd5d56e67282328a3ca87a082b1");
print("tokenName $name");
print("tokenSymbol symbol");
// Output
tokenName: StandardToken
tokenSymbol: ST
References #
Licenses #
This project follows the Apache 2.0 License. Please refer to LICENSE for details.