// sendTransactions is an example function for sending a transaction.
// It's designed to reuse an existing gRPC client connection to avoid connection latency.
func sendTransactions(client basepb.BaseApiClient, authToken string, rawTxString string) {
log.Println("[SendTx] Sending transaction...")
ctx, cancel := context.WithTimeout(context.Background(), 3*time.Second)
defer cancel()
// Add the authentication token to the outgoing request's metadata.
md := metadata.Pairs("authorization", authToken)
ctx = metadata.NewOutgoingContext(ctx, md)
req := &basepb.SendTransactionRequest{
RawTransaction: rawTxString,
}
res, err := client.SendTransaction(ctx, req)
if err != nil {
log.Printf("[SendTx] Failed to send transaction: %v", err)
} else {
log.Printf("[SendTx] Transaction sent successfully. Hash: %s", res.GetTxHash())
}
}