AIOZDart
Introduction
AIOZDart
is a pure Dart package allowing you to easily integrate your Dart-based project with the AIOZ Network blockchain.
Getting started
To start using this library inside your project, just edit your pubspec.yml
file, adding the following lines:
dependencies:
aioz: "<version>"
You can even use a specific GitHub tag or branch if you want:
dependencies:
aioz:
git:
url: "git://github.com/AIOZNetwork/aioz.dart.git"
ref: "<branch or tag>"
Send your first transaction from Dart
import 'package:aioz/aioz.dart';
import 'package:aioz/proto/cosmos/bank/v1beta1/export.dart' as bank;
final networkInfo = NetworkInfo.fromSingleHost(
bech32Hrp: 'aioz',
host: 'https://grpc.my_aioz_grpc_node',
httpHost: 'https://lcd.my_aioz_lcd_node',
grpcPort: 9090,
httpPort: 1317,
);
final mnemonic = 'federal injury annual melt near scan daughter before nut catalog spend decade';
final wallet = HdWallet.fromMnemonic(
mnemonic,
prefix: networkInfo.bech32Hrp,
);
final recipient = '0x70207819eC28FB8cc692A4327C80282006E6476A';
final message = bank.MsgSend.create()
..fromAddress = wallet.accounts[0].bech32Address
..toAddress = hexToBech32Address(
networkInfo.bech32Hrp, recipient)
..amount.add(Coin.create()
..denom = 'attoaioz'
..amount = '1000000000000000000');
final fee = Fee()
..gasLimit = 200000.toInt64()
..amount.add(Coin.create()
..denom = 'attoaioz'
..amount = '200000000000000');
final signer = TxSigner.fromNetworkInfo(networkInfo);
final tx = await signer.createAndSign(
wallet, wallet.accounts[0].bech32Address, [message],
fee: fee);
final txSender = TxSender.fromNetworkInfo(networkInfo);
final response =
await txSender.broadcastTx(tx, mode: BroadcastMode.BROADCAST_MODE_BLOCK);
if (response.isSuccessful) {
print('Tx sent successfully. Response: ${response}');
} else {
print('Tx errored: ${response}');
}