github.com/gagliardetto/solana-go@v1.11.0/rpc/examples/getTransaction/getTransaction.go (about)

     1  // Copyright 2021 github.com/gagliardetto
     2  //
     3  // Licensed under the Apache License, Version 2.0 (the "License");
     4  // you may not use this file except in compliance with the License.
     5  // You may obtain a copy of the License at
     6  //
     7  //      http://www.apache.org/licenses/LICENSE-2.0
     8  //
     9  // Unless required by applicable law or agreed to in writing, software
    10  // distributed under the License is distributed on an "AS IS" BASIS,
    11  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    12  // See the License for the specific language governing permissions and
    13  // limitations under the License.
    14  
    15  package main
    16  
    17  import (
    18  	"context"
    19  
    20  	"github.com/davecgh/go-spew/spew"
    21  	bin "github.com/gagliardetto/binary"
    22  	"github.com/gagliardetto/solana-go"
    23  	"github.com/gagliardetto/solana-go/rpc"
    24  )
    25  
    26  func main() {
    27  	endpoint := rpc.TestNet_RPC
    28  	client := rpc.New(endpoint)
    29  
    30  	txSig := solana.MustSignatureFromBase58("4bjVLV1g9SAfv7BSAdNnuSPRbSscADHFe4HegL6YVcuEBMY83edLEvtfjE4jfr6rwdLwKBQbaFiGgoLGtVicDzHq")
    31  	{
    32  		out, err := client.GetTransaction(
    33  			context.TODO(),
    34  			txSig,
    35  			nil,
    36  		)
    37  		if err != nil {
    38  			panic(err)
    39  		}
    40  		spew.Dump(out)
    41  		spew.Dump(out.Transaction.GetTransaction())
    42  	}
    43  	{
    44  		out, err := client.GetTransaction(
    45  			context.TODO(),
    46  			txSig,
    47  			&rpc.GetTransactionOpts{
    48  				Encoding: solana.EncodingJSON,
    49  			},
    50  		)
    51  		if err != nil {
    52  			panic(err)
    53  		}
    54  		spew.Dump(out)
    55  		spew.Dump(out.Transaction.GetTransaction())
    56  	}
    57  	{
    58  		out, err := client.GetTransaction(
    59  			context.TODO(),
    60  			txSig,
    61  			&rpc.GetTransactionOpts{
    62  				Encoding: solana.EncodingBase58,
    63  			},
    64  		)
    65  		if err != nil {
    66  			panic(err)
    67  		}
    68  		spew.Dump(out)
    69  		spew.Dump(out.Transaction.GetBinary())
    70  	}
    71  	{
    72  		out, err := client.GetTransaction(
    73  			context.TODO(),
    74  			txSig,
    75  			&rpc.GetTransactionOpts{
    76  				Encoding: solana.EncodingBase64,
    77  			},
    78  		)
    79  		if err != nil {
    80  			panic(err)
    81  		}
    82  		spew.Dump(out)
    83  		spew.Dump(out.Transaction.GetBinary())
    84  
    85  		decodedTx, err := solana.TransactionFromDecoder(bin.NewBinDecoder(out.Transaction.GetBinary()))
    86  		if err != nil {
    87  			panic(err)
    88  		}
    89  		spew.Dump(decodedTx)
    90  	}
    91  }