BlockRazor
Go to website
繁体中文
繁体中文
  • 👉关于BlockRazor
  • 👨‍💻用户案例
    • 钱包
    • 去中心化交易所
    • Trading Bot
    • Searcher
    • 量化交易系统
  • 💸Solana
    • 总览
    • Authentication
    • APIs
      • sendTransaction
      • getTransactionFee
      • Sandwich Detector
  • 🖥️BSC
    • Authentication
    • Dedicate Node
      • 創建Dedicate Node
      • 使用Dedicate Node
    • 高性能網絡
      • Proto
      • Subscribe NewTxs
      • Subscribe NewBlocks
      • Send RawTx
      • Send RawTxBatch
      • 全節點同步
    • Block Builder
      • Send Bundle
      • Send PrivateTransaction
      • Call Bundle
      • Trace Bundle
    • APIs
      • GetGasPriceStream
      • GetAllGasPriceStream
      • Sandwich Detector
  • 🛡️Scutum(ETH & BSC)
    • 总览
    • New to MEV
    • 項目專屬RPC
    • 錢包用戶通用RPC
    • Searcher
      • Authentication
      • Subscribe Bundle
      • Send Bundle
  • 📄声明
    • 隱私聲明
Powered by GitBook
On this page
  • 介紹
  • 端點
  • 流控說明
  • 請求參數
  • 構建交易
  • Priority Fee & Tip
  • 交易構建示例
  • Proto
  • 返回示例
  1. Solana
  2. APIs

sendTransaction

介紹

sendTransaction 用於在Solana上發送已簽名的交易,支持gRPC協議。

端點

地区
URL

法蘭克福

frankfurt.solana-grpc.blockrazor.xyz:80

香港

hongkong.solana-grpc.blockrazor.xyz:80

紐約

newyork.solana-grpc.blockrazor.xyz:80

流控說明

Tier 4
Tier 3
Tier 2
Tier 1
Tier 0

10 TPM

5 TPS

50 TPS

100 TPS

Custom

請求參數

字段
必選
格式
示例
備注

signedtx

是

String

"AVXo5X……gEAAAA="

已完全簽名的交易,兼容base 64和base 58的編碼格式,建議用base 64

skipPreflight

否

Bool

false

默认为false,不跳过交易preflight检查,如设置为true,则跳过交易preflight检查

preflightCommitment

否

String

confirmed

構建交易

Priority Fee & Tip

賬戶地址

Gywj98ophM7GmkDdaWs4isqZnDdFCW7B46TXmKfvyqSm

交易構建示例

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;
}

返回示例

正常

signature:"2PCgCdD5gm4852ooyT2LQqiTgcau28hRNWCqBHCJ33EhhBsuAzAxYGLbS8kAmAMu7DW8JSrrKtaCGMZqQbtbGpgx" 

異常

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

PreviousAPIsNextgetTransactionFee

Last updated 11 days ago

用于preflight检查的commitment等级,分为processed、confirmed和finalized,详见,默认confirmed

Priority Fee是Solana在Base Fee(發送交易的最低成本,交易中每包含一個簽名花費5000 lamports)基礎上,以每CU lamports計價的額外交易費用。作為可選項,用戶在構建交易時可按需設置Priority Fee。由於計算資源有限,Leader節點在出塊時主要按交易價值對交易進行排序,Priority Fee越高的交易被優先納入下個區塊的概率越高。BlockRazor提供方法獲取建議的Priority Fee

在構建交易時,需在交易中添加Tip轉賬指令,用於進一步加速交易上鍊。BlockRazor不從Tip中收取服務費。Tier 4 - Tier 1用户的Tip指令轉賬金額至少為1000000 Lamports(0.001 Sol),Tier 0用戶的Tip指令的轉賬金額至少為100000 Lamports(0.0001 Sol),建議將Tip置為返回的推薦值,接收Tip的账户地址為:

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