build method
Uint8List
build({
- int? maxSizeBytes,
- String? sender,
- GasConfig? gasConfig,
- TransactionExpiration? expiration,
- bool onlyTransactionKind = false,
Implementation
Uint8List build({
int? maxSizeBytes,
String? sender,
GasConfig? gasConfig,
TransactionExpiration? expiration,
bool onlyTransactionKind = false,
}) {
final kind = {
"ProgrammableTransaction": {
"inputs": inputs,
"commands": commands,
},
};
if (onlyTransactionKind) {
final options = BcsWriterOptions(maxSize: maxSizeBytes);
return SuiBcs.TransactionKind.serialize(kind, options: options).toBytes();
}
final expirationValue = expiration ?? this.expiration;
final senderValue = sender ?? this.sender;
final gasConfigValue = this.gasData.toJson();
if (gasConfig != null) {
gasConfig.toJson().forEach((key, value) {
if (value != null) {
gasConfigValue[key] = value;
}
});
}
if (senderValue == null) {
throw ArgumentError('Missing transaction sender');
}
if (gasConfigValue["budget"] == null) {
throw ArgumentError('Missing gas budget');
}
if (gasConfigValue["payment"] == null) {
throw ArgumentError('Missing gas payment');
}
if (gasConfigValue["price"] == null) {
throw ArgumentError('Missing gas price');
}
final transactionData = {
"sender": prepareSuiAddress(senderValue),
"expiration": expirationValue?.toJson() ?? { "None": true },
"gasData": {
"payment": gasConfigValue["payment"],
"owner": prepareSuiAddress(this.gasData.owner ?? senderValue),
"price": BigInt.parse(gasConfigValue["price"].toString()),
"budget": BigInt.parse(gasConfigValue["budget"].toString()),
},
"kind": {
"ProgrammableTransaction": {
"inputs": inputs,
"commands": commands,
},
},
};
return SuiBcs.TransactionData.serialize(
{ "V1": transactionData },
options: BcsWriterOptions(maxSize: maxSizeBytes),
).toBytes();
}