In order to receive Polys using BramblDart, you first need to create your HD wallet in BramblDart.
First, you will need to generate a random mnemonic. This will allow you to instantiate a HD wallet instance.
The allowed size of Entropy is 96-256 bits and is
necessarily a multiple of 32 bits (4 bytes).
The parameters to the mnemonic/recovery phrase are a random number generator (we recommend using
Random.secure()), the entropy size, and the output language of the recovery phrase (defaults to
final mnemonic = generateMnemonic(Random.secure(), strength: 160, language: 'english');
Next, instantiate your HD wallet instance using this generated mnemonic:
final hdWallet = HdWallet.fromMnemonic(mnemonic);
If you want to use the addresses generated by this HD wallet in the future, please be careful to store your recovery phrase. This is very important, if you lose this it is very likely that you will lose any tokens that are owned by the HD Wallet.
First, generate an address using your HdWallet instance:
Please keep track of the indexes that you have used to create addresses. Using the same index will generate the same address.
Once you have derived the address, you can transfer it to the sending entity in a human readable Base58 encoding using the
import 'package:dio/dio.dart'; //You can also import the browser version import 'package:brambldart/brambldart.dart'; var networkId = 0x40; var propositionType = PropositionType.ed25519(); var privateKey = 'base58EncodedPrivateKey'; var apiUrl = "http://localhost:9085"; //Replace with your API var httpClient = Dio(BaseOptions( baseUrl: basePathOverride ?? basePath, contentType: 'application/json', connectTimeout: 5000, receiveTimeout: 3000) var bramblClient = BramblClient(httpClient: httpClient, basePathOverride: apiUrl); var credentials = bramblClient.credentialsFromPrivateKey(privateKey, networkId, propositionType); // You can now call rpc methods. This one will query the amount of Topl tokens you own Balance balance = bramblClient.getBalance(credentials.address); print(balance.toString());
Of course, this library supports creating, signing and sending Topl
import 'package:brambldart/brambldart.dart'; /// [...], you need to specify the url and your client, see example above var bramblClient = BramblClient(basePathOverride: apiUrl, httpClient: httpClient); var credentials = bramblClient.credentialsFromPrivateKey("0x..."); const value = 1; final assetCode = AssetCode.initialize(1, senderAddress, 'testy', 'valhalla'); final securityRoot = SecurityRoot.fromBase58( Base58Data.validated('11111111111111111111111111111111')); final assetValue = AssetValue( value.toString(), assetCode, securityRoot, 'metadata', 'Asset'); final recipient = AssetRecipient(senderAddress, assetValue); final data = Latin1Data.validated('data'); final assetTransaction = AssetTransaction( recipients: [recipient], sender: [senderAddress], changeAddress: senderAddress, consolidationAddress: senderAddress, propositionType: PropositionType.ed25519().propositionName, minting: true, assetCode: assetCode, data: data); final rawTransaction = await client.sendRawAssetTransfer(assetTransaction: assetTransaction); expect(rawTransaction['rawTx'], isA<TransactionReceipt>()); print(rawTransaction); final txId = await client.sendTransaction( [first], rawTransaction['rawTx'] as TransactionReceipt, rawTransaction['messageToSign'] as Uint8List);
Missing data, like the fee, the sender or a change/consolidation address will be
inferred by the BramblClient when not explicitly specified. If you only need
the signed transaction but don't intend to send it, you can use
Updated 3 months ago