Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package main
- import (
- "context"
- "fmt"
- "log"
- "sync"
- "time"
- "github.com/gagliardetto/solana-go"
- "github.com/gagliardetto/solana-go/rpc"
- "github.com/gagliardetto/solana-go/types"
- )
- func sendTransaction(sender *solana.Wallet, receiver solana.PublicKey, client *rpc.Client) {
- // Define the amount to send in lamports (0.001 SOL):
- amount := uint64(0.001 * 1e9)
- // Create a transfer instruction:
- instruction := solana.NewTransferInstruction(
- solana.TokenProgramID,
- sender.PublicKey(),
- receiver,
- amount,
- ).Build()
- // Create a message for the transaction:
- message := types.NewMessage(
- types.NewMessageParam{
- FeePayer: sender.PublicKey(),
- Instructions: []types.Instruction{instruction},
- RecentBlockhash: client.GetRecentBlockhash(context.Background()), // Get recent blockhash
- },
- )
- // Sign the transaction:
- tx, err := types.NewTransaction(
- *message,
- []*solana.Wallet{sender},
- )
- if err != nil {
- log.Printf("Failed to create transaction: %v", err)
- return
- }
- // Send the transaction:
- _, err = client.SendTransaction(context.Background(), tx)
- if err != nil {
- log.Printf("Failed to send transaction: %v", err)
- }
- }
- func worker(ctx context.Context, workerID int, sender *solana.Wallet, receiver solana.PublicKey, client *rpc.Client) {
- for {
- select {
- case <-ctx.Done():
- fmt.Printf("Worker %d done\n", workerID)
- return
- default:
- sendTransaction(sender, receiver, client)
- fmt.Printf("Worker %d sent a transaction\n", workerID)
- // A brief pause to prevent spamming, adjust as necessary based on actual testing and rate limits
- time.Sleep(100 * time.Millisecond)
- }
- }
- }
- func main() {
- // Initialize RPC client (adjust as needed):
- client := rpc.New(rpc.DevNet_RPC) // Use DevNet for testing
- // Your wallet setup:
- senderPrivateKey := []byte("YourSenderPrivateKeyHere")
- sender := solana.NewWalletFromPrivateKeyBytes(senderPrivateKey)
- receiver := solana.MustPublicKeyFromBase58("YourReceiverPublicKeyHere")
- // Context to handle the 10-second duration:
- ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
- defer cancel()
- var wg sync.WaitGroup
- // Launching 16 workers:
- for i := 0; i < 16; i++ {
- wg.Add(1)
- go func(workerID int) {
- defer wg.Done()
- worker(ctx, workerID, sender, receiver, client)
- }(i)
- }
- // Wait for all workers to complete:
- wg.Wait()
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement