github.com/gagliardetto/solana-go@v1.11.0/rpc/sendTransaction.go (about) 1 // Copyright 2021 github.com/gagliardetto 2 // This file has been modified by github.com/gagliardetto 3 // 4 // Copyright 2020 dfuse Platform Inc. 5 // 6 // Licensed under the Apache License, Version 2.0 (the "License"); 7 // you may not use this file except in compliance with the License. 8 // You may obtain a copy of the License at 9 // 10 // http://www.apache.org/licenses/LICENSE-2.0 11 // 12 // Unless required by applicable law or agreed to in writing, software 13 // distributed under the License is distributed on an "AS IS" BASIS, 14 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 // See the License for the specific language governing permissions and 16 // limitations under the License. 17 package rpc 18 19 import ( 20 "context" 21 "encoding/base64" 22 "fmt" 23 24 "github.com/gagliardetto/solana-go" 25 ) 26 27 // SendTransaction submits a signed transaction to the cluster for processing. 28 func (cl *Client) SendTransaction( 29 ctx context.Context, 30 transaction *solana.Transaction, 31 ) (signature solana.Signature, err error) { 32 opts := TransactionOpts{ 33 SkipPreflight: false, 34 PreflightCommitment: "", 35 } 36 37 return cl.SendTransactionWithOpts( 38 ctx, 39 transaction, 40 opts, 41 ) 42 } 43 44 // SendTransaction submits a signed transaction to the cluster for processing. 45 // This method does not alter the transaction in any way; 46 // it relays the transaction created by clients to the node as-is. 47 // 48 // If the node's rpc service receives the transaction, 49 // this method immediately succeeds, without waiting for any confirmations. 50 // A successful response from this method does not guarantee the transaction 51 // is processed or confirmed by the cluster. 52 // 53 // While the rpc service will reasonably retry to submit it, the transaction 54 // could be rejected if transaction's recent_blockhash expires before it lands. 55 // 56 // Use getSignatureStatuses to ensure a transaction is processed and confirmed. 57 // 58 // Before submitting, the following preflight checks are performed: 59 // 60 // - The transaction signatures are verified 61 // - The transaction is simulated against the bank slot specified by the preflight 62 // commitment. On failure an error will be returned. Preflight checks may be 63 // disabled if desired. It is recommended to specify the same commitment and 64 // preflight commitment to avoid confusing behavior. 65 // 66 // The returned signature is the first signature in the transaction, which is 67 // used to identify the transaction (transaction id). This identifier can be 68 // easily extracted from the transaction data before submission. 69 func (cl *Client) SendTransactionWithOpts( 70 ctx context.Context, 71 transaction *solana.Transaction, 72 opts TransactionOpts, 73 ) (signature solana.Signature, err error) { 74 txData, err := transaction.MarshalBinary() 75 if err != nil { 76 return solana.Signature{}, fmt.Errorf("send transaction: encode transaction: %w", err) 77 } 78 79 return cl.SendEncodedTransactionWithOpts( 80 ctx, 81 base64.StdEncoding.EncodeToString(txData), 82 opts, 83 ) 84 }