NextBlock
SupportWebsiteDashboard
  • What is NextBlock?
  • Pricing & Rate Limits
  • Getting Started
    • Quickstart
      • GoLang Sample Code
      • Bundle Sending Sample
    • Contact
  • API
    • Basics
    • Authentication
    • Submit Transaction
    • Submit Batched Transactions
    • Examples
      • Golang
        • Connection
        • Keepalive
        • Tip floor stream
        • Submit single transactions
        • Submit batched transactions
      • Http
      • Rust
Powered by GitBook
On this page
Export as PDF
  1. API
  2. Examples
  3. Golang

Submit batched transactions

You can use the batch transaction request. At the time of this writing batch transactions will always be submitted as an atomic jito bundle. That means either all of them succeed and land or none of them.

var NextblockTipWallets = solana.PublicKeySlice{
	solana.MustPublicKeyFromBase58("NEXTbLoCkB51HpLBLojQfpyVAMorm3zzKg7w9NFdqid"),
	solana.MustPublicKeyFromBase58("nextBLoCkPMgmG8ZgJtABeScP35qLa2AMCNKntAP7Xc"),
	solana.MustPublicKeyFromBase58("NextbLoCkVtMGcV47JzewQdvBpLqT9TxQFozQkN98pE"),
	solana.MustPublicKeyFromBase58("NexTbLoCkWykbLuB1NkjXgFWkX9oAtcoagQegygXXA2"),
	solana.MustPublicKeyFromBase58("NeXTBLoCKs9F1y5PJS9CKrFNNLU1keHW71rfh7KgA1X"),
	solana.MustPublicKeyFromBase58("NexTBLockJYZ7QD7p2byrUa6df8ndV2WSd8GkbWqfbb"),
	solana.MustPublicKeyFromBase58("neXtBLock1LeC67jYd1QdAa32kbVeubsfPNTJC1V5At"),
	solana.MustPublicKeyFromBase58("nEXTBLockYgngeRmRrjDV31mGSekVPqZoMGhQEZtPVG"),
}

func GetRandomNextblockTipWallet() solana.PK {
	randVal := rand.IntN(len(NextblockTipWallets))
	return NextblockTipWallets[randVal]
}

func BuildAndSendBatchTransaction() error {
	pk := solana.MustPrivateKeyFromBase58("<signer private key>")
	// rpcClient cli has to be initialized somewhere 
	// there are also other ways of retrieving latest blockhash / using nonce accounts
	bh, _ := cli.GetLatestBlockhash(context.TODO(), rpc.CommitmentFinalized)
	txBuilder := solana.NewTransactionBuilder()
	txBuilder.SetFeePayer(pk.PublicKey())
	txBuilder.SetRecentBlockHash(bh.Value.Blockhash)
        // add tip instruction
	txBuilder.AddInstruction(
		system.NewTransferInstruction(1000000, pk.PublicKey(), GetRandomNextblockTipWallet()).Build(),
	)
	// add a dummy transfer instruction of 10000 lamports
	// this should be replaced with useful instructions...
	txBuilder.AddInstruction(
		system.NewTransferInstruction(uint64(10000), pk.PublicKey(), solana.MustPublicKeyFromBase58("<receiving publickkey>")).Build(),
	)
	tx, err := txBuilder.Build()
	if err != nil {
		return err
	}
	_, err = tx.Sign(func(key solana.PublicKey) *solana.PrivateKey {
		return &pk
	})
	if err != nil {
		return err
	}
	// nextblockApiClient has to be initialized and in scope
	// it currently has no additional parameters as it will always be sent as a jito bundle
	submitResponse, err := nextblockApiClient.PostSubmitBatchV2(context.TODO(), &api.PostSubmitBatchRequest{
		Entries: []*api.PostSubmitRequestEntry{
			{
				Transaction: &api.TransactionMessage{Content: base64EncodedTransaction},
			},
			{
				Transaction: &api.TransactionMessage{Content: base64EncodedTransaction},
			},
		},
	})
	if err != nil {
		fmt.Println(err)
		return
	}
	fmt.Println(submitResponse)
}
PreviousSubmit single transactionsNextHttp

Last updated 6 days ago