BlockRazor
Go to website
English
English
  • 👉About BlockRazor
  • 👨‍💻Use Cases
    • Wallet
    • DEX
    • Searcher
    • Trading Bot
    • Algorithmic Trading
  • 💸Solana
    • Overview
    • Authentication
    • APIs
      • sendTransaction
      • getTransactionFee
      • Sandwich Detector
  • 🖥️BSC
    • Authentication
    • High-performance Network
      • Proto
      • Subscribe NewTxs
      • Subscribe NewBlocks
      • Send RawTx
      • Send RawTxBatch
      • Full Node Synchronization
    • Block Builder
      • Send Bundle
      • Send PrivateTransaction
      • Call Bundle
      • Trace Bundle
    • APIs
      • GetGasPriceStream
      • GetAllGasPriceStream
      • Sandwich Detector
  • 🛡️Scutum(ETH & BSC)
    • Overview
    • New to MEV
    • Exclusive for Project
    • General for Wallet User
    • Searcher
      • Authentication
      • Subscribe Bundle
      • Send Bundle
  • 📄Statement
    • Privacy Statement
Powered by GitBook
On this page
  • Introduction
  • Endpoint
  • Rate Limit
  • Request Parameter
  • Transaction Construction
  • Transaction Construction Example
  • Proto
  • Response Example
  1. Solana
  2. APIs

sendTransaction

Introduction

sendTransaction is used to send signed transaction on Solana based on gRPC.

Endpoint

Region
URL

Frankfurt

frankfurt.solana-grpc.blockrazor.xyz:80

Hong Kong

hongkong.solana-grpc.blockrazor.xyz:80

New York

newyork.solana-grpc.blockrazor.xyz:80

Rate Limit

Tier 4
Tier 3
Tier 2
Tier 1
Tier 0

10 TPM

5 TPS

50 TPS

100 TPS

Custom

Request Parameter

Parameters
Mandatory
Format
Example
Remark

signedtx

mandatory

String

"AVXo5X……gEAAAA="

Fully signed transactions, compatible with encoding protocal base 64 and base 58, with base 64 being recommended

skipPreflight

optional

Bool

false

The default value is false, which means that the transaction preflight check will not be skipped. If set to true, the transaction preflight check will be skipped.

preflightCommitment

optional

String

confirmed

Transaction Construction

Priority Fee & Tip

Account Address

Gywj98ophM7GmkDdaWs4isqZnDdFCW7B46TXmKfvyqSm

Transaction Construction Example

package main

import (
	"context"
	pb "example/pb/serverpb"
	"fmt"

	"github.com/gagliardetto/solana-go"
	"github.com/gagliardetto/solana-go/programs/system"
	"github.com/gagliardetto/solana-go/rpc"
	"google.golang.org/grpc"
	"google.golang.org/grpc/credentials/insecure"
)

const (
	// BlockRazor relay endpoint address
	blzRelayEndpoint = "frankfurt.solana-grpc.blockrazor.xyz:80"
	// replace your solana rpc endpoint
	mainNetRPC = ""
	// replace your authKey
	authKey = ""
	// relace your private key(base58)
	privateKey = ""
	// publicKey(base58)
	publicKey = ""
	// transfer amount
	amount = 200_000

	// tip account
	tipAccount = "Gywj98ophM7GmkDdaWs4isqZnDdFCW7B46TXmKfvyqSm"
	tipAmount  = 1_000_000
)

func main() {
	var err error
	account, err := solana.WalletFromPrivateKeyBase58(privateKey)
	receivePub := solana.MustPublicKeyFromBase58(publicKey)

	// setup grpc connect
	conn, err := grpc.NewClient(blzRelayEndpoint,
		grpc.WithTransportCredentials(insecure.NewCredentials()),
		grpc.WithPerRPCCredentials(&Authentication{authKey}),
	)
	if err != nil {
		panic(fmt.Sprintf("connect error: %v", err))
	}

	// use the Gateway client connection interface
	client := pb.NewServerClient(conn)

	// grpc request warmup
	client.GetHealth(context.Background(), &pb.HealthRequest{})

	// new rpc client and get latest block hash
	rpcClient := rpc.New(mainNetRPC)
	blockhash, err := rpcClient.GetLatestBlockhash(context.TODO(), rpc.CommitmentFinalized)
	if err != nil {
		panic(fmt.Sprintf("[get latest block hash] error: %v", err))
	}

	// construct instruction
	transferIx := system.NewTransferInstruction(amount, account.PublicKey(), receivePub).Build()
	tipIx := system.NewTransferInstruction(tipAmount, account.PublicKey(), solana.MustPublicKeyFromBase58(tipAccount)).Build()

	// construct transation, replace your transation
	tx, err := solana.NewTransaction(
		[]solana.Instruction{transferIx, tipIx},
		blockhash.Value.Blockhash,
		solana.TransactionPayer(account.PublicKey()),
	)
	if err != nil {
		panic(fmt.Sprintf("new tx error: %v", err))
	}

	// transaction sign
	_, err = tx.Sign(
		func(key solana.PublicKey) *solana.PrivateKey {
			if account.PublicKey().Equals(key) {
				return &account.PrivateKey
			}
			return nil
		},
	)
	if err != nil {
		panic(fmt.Sprintf("sign tx error: %v", err))
	}

	txBase64, _ := tx.ToBase64()
	sendRes, err := client.SendTransaction(context.TODO(), &pb.SendRequest{
		Transaction:         txBase64,
		Mode:                "fast",
		SkipPreflight:       false,
		PreflightCommitment: "confirmed",
	})
	if err != nil {
		panic(fmt.Sprintf("[send tx] error: %v", err))
	}

	fmt.Printf("[send tx] response: %+v \n", sendRes)
	return
}

type Authentication struct {
	apiKey string
}

func (a *Authentication) GetRequestMetadata(context.Context, ...string) (map[string]string, error) {
	return map[string]string{"apiKey": a.apiKey}, nil
}

func (a *Authentication) RequireTransportSecurity() bool {
	return false
}

Proto

syntax = "proto3";

package serverpb;

option go_package = "./pb/serverpb";


service Server {
    rpc SendTransaction(SendRequest) returns(SendResponse) {};

    rpc GetHealth(HealthRequest) returns(HealthResponse) {};
}

message SendRequest {
    string transaction = 1;
    string mode = 2;
    bool skipPreflight = 3;
    string preflightCommitment = 4;
}

message SendResponse {
    string signature = 1;
}

message HealthRequest {
}

message HealthResponse {
    string status = 1;
}

Response Example

Success

signature:"2PCgCdD5gm4852ooyT2LQqiTgcau28hRNWCqBHCJ33EhhBsuAzAxYGLbS8kAmAMu7DW8JSrrKtaCGMZqQbtbGpgx" 

Error

error: rpc error: code = Unknown desc = Insufficient tip, please increase the tip amount and try again, at least 1000000 lamports

PreviousAPIsNextgetTransactionFee

Last updated 7 days ago

The commitment level used for preflight checking is divided into processed, confirmed and finalized. For details, see . The default is confirmed.

Priority Fee is an additional transaction fee charged by Solana in CU lamports on top of Base Fee (the minimum cost of sending a transaction, 5,000 lamports for each signature included in the transaction). As an option, users can set Priority Fee as needed when constructing a transaction. Due to limited computing resources, Leader nodes order transactions mainly by transaction value when generating blocks. Transactions with higher Priority Fee have a higher probability of being included in the next block. BlockRazor provides the method to help users obtain the recommended Priority Fee.

When constructing a transaction, you need to add a instruction of Tip transfer into the transaction to further speed up the inclusion. BlockRazor does not charge service fees from Tips. Tier 4 - Tier 1 users must have a Tip transfer amount of at least 1,000,000 Lamports (0.001 Sol) and Tier 0 users must have a Tip transfer amount of at least 100,000 Lamports (0.0001 Sol). It is recommended to set it to the value returned by . The account to receive Tip is:

💸
getTransactionfee
getTransactionfee
https://docs.anza.xyz/consensus/commitments