Advertisement
rand17

Untitled

Mar 16th, 2024
607
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Go 2.41 KB | None | 0 0
  1. package main
  2.  
  3. import (
  4.     "context"
  5.     "fmt"
  6.     "log"
  7.     "sync"
  8.     "time"
  9.  
  10.     "github.com/gagliardetto/solana-go"
  11.     "github.com/gagliardetto/solana-go/rpc"
  12.     "github.com/gagliardetto/solana-go/types"
  13. )
  14.  
  15. func sendTransaction(sender *solana.Wallet, receiver solana.PublicKey, client *rpc.Client) {
  16.     // Define the amount to send in lamports (0.001 SOL):
  17.     amount := uint64(0.001 * 1e9)
  18.  
  19.     // Create a transfer instruction:
  20.     instruction := solana.NewTransferInstruction(
  21.         solana.TokenProgramID,
  22.         sender.PublicKey(),
  23.         receiver,
  24.         amount,
  25.     ).Build()
  26.  
  27.     // Create a message for the transaction:
  28.     message := types.NewMessage(
  29.         types.NewMessageParam{
  30.             FeePayer:        sender.PublicKey(),
  31.             Instructions:    []types.Instruction{instruction},
  32.             RecentBlockhash: client.GetRecentBlockhash(context.Background()), // Get recent blockhash
  33.         },
  34.     )
  35.  
  36.     // Sign the transaction:
  37.     tx, err := types.NewTransaction(
  38.         *message,
  39.         []*solana.Wallet{sender},
  40.     )
  41.     if err != nil {
  42.         log.Printf("Failed to create transaction: %v", err)
  43.         return
  44.     }
  45.  
  46.     // Send the transaction:
  47.     _, err = client.SendTransaction(context.Background(), tx)
  48.     if err != nil {
  49.         log.Printf("Failed to send transaction: %v", err)
  50.     }
  51. }
  52.  
  53. func worker(ctx context.Context, workerID int, sender *solana.Wallet, receiver solana.PublicKey, client *rpc.Client) {
  54.     for {
  55.         select {
  56.         case <-ctx.Done():
  57.             fmt.Printf("Worker %d done\n", workerID)
  58.             return
  59.         default:
  60.             sendTransaction(sender, receiver, client)
  61.             fmt.Printf("Worker %d sent a transaction\n", workerID)
  62.             // A brief pause to prevent spamming, adjust as necessary based on actual testing and rate limits
  63.             time.Sleep(100 * time.Millisecond)
  64.         }
  65.     }
  66. }
  67.  
  68. func main() {
  69.     // Initialize RPC client (adjust as needed):
  70.     client := rpc.New(rpc.DevNet_RPC) // Use DevNet for testing
  71.  
  72.     // Your wallet setup:
  73.     senderPrivateKey := []byte("YourSenderPrivateKeyHere")
  74.     sender := solana.NewWalletFromPrivateKeyBytes(senderPrivateKey)
  75.     receiver := solana.MustPublicKeyFromBase58("YourReceiverPublicKeyHere")
  76.  
  77.     // Context to handle the 10-second duration:
  78.     ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
  79.     defer cancel()
  80.  
  81.     var wg sync.WaitGroup
  82.  
  83.     // Launching 16 workers:
  84.     for i := 0; i < 16; i++ {
  85.         wg.Add(1)
  86.         go func(workerID int) {
  87.             defer wg.Done()
  88.             worker(ctx, workerID, sender, receiver, client)
  89.         }(i)
  90.     }
  91.  
  92.     // Wait for all workers to complete:
  93.     wg.Wait()
  94. }
  95.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement