sendRawTransaction method
Implementation
Future<String> sendRawTransaction(String serializedTransactionHex) {
serializedTransactionHex = serializedTransactionHex.startsWith("0x")
? serializedTransactionHex
: "0x$serializedTransactionHex";
return performTaskForClients(
(client) => client.sendRawTransaction(serializedTransactionHex),
minClients: 1,
maxTriesPerClient: 1,
maxClients: 5,
enforceParallel: true,
consilidate: (resultsWithErrors) {
final results = resultsWithErrors
.whereType<Value<String, EvmRpcClient>>()
.map((v) => v.value);
if (results.isEmpty) {
throw Exception(
"No client was able to send the transaction: ${results}",
);
}
final hashMap = results.fold<Map<String, int>>(
{},
(acc, hash) {
acc[hash] = (acc[hash] ?? 0) + 1;
return acc;
},
);
final hash = hashMap.entries.reduce(
(a, b) => a.value > b.value ? a : b,
);
return hash.key;
},
);
}