addTokenTransfer method
Add a token transfer to the transaction @param {String | Uint8List} to Address of the recipient (hexadecimal or binary buffer) @param {int} amount Amount of token to transfer @param {String | Uint8List} tokenAddress Address of token to spend (hexadecimal or binary buffer) @param {int} tokenId ID of the token to use (default to 0)
Implementation
Transaction addTokenTransfer(dynamic to, int amount, dynamic tokenAddress,
{int tokenId = 0}) {
if (to is! Uint8List && to is! String) {
throw "'to' must be a string or Uint8List";
}
if (to is String) {
if (!isHex(to)) {
throw "'to' must be an hexadecimal string";
}
} else {
to = uint8ListToHex(to);
}
if (tokenAddress is! Uint8List && tokenAddress is! String) {
throw "'tokenAddress' must be a string or Uint8List";
}
if (tokenAddress is String) {
if (!isHex(tokenAddress)) {
throw "'tokenAddress' must be an hexadecimal string";
}
} else {
tokenAddress = uint8ListToHex(tokenAddress);
}
if (tokenId.isNaN && tokenId < 0) {
throw "'tokenId' must be a valid integer >= 0";
}
final TokenTransfer tokenTransfer = TokenTransfer(
amount: amount, tokenAddress: tokenAddress, to: to, tokenId: tokenId);
data!.ledger!.token!.transfers!.add(tokenTransfer);
return this;
}