github.com/InjectiveLabs/sdk-go@v1.53.0/examples/chain/tx/query/1_GetTx/example.go (about)

     1  package main
     2  
     3  import (
     4  	"context"
     5  	"fmt"
     6  	"os"
     7  	"time"
     8  
     9  	"github.com/InjectiveLabs/sdk-go/client"
    10  	"github.com/InjectiveLabs/sdk-go/client/common"
    11  
    12  	rpchttp "github.com/cometbft/cometbft/rpc/client/http"
    13  
    14  	chainclient "github.com/InjectiveLabs/sdk-go/client/chain"
    15  )
    16  
    17  func main() {
    18  	// network := common.LoadNetwork("mainnet", "k8s")
    19  	network := common.LoadNetwork("mainnet", "lb")
    20  	tmRPC, err := rpchttp.New(network.TmEndpoint, "/websocket")
    21  
    22  	if err != nil {
    23  		panic(err)
    24  	}
    25  
    26  	senderAddress, cosmosKeyring, err := chainclient.InitCosmosKeyring(
    27  		os.Getenv("HOME")+"/.injectived",
    28  		"injectived",
    29  		"file",
    30  		"inj-user",
    31  		"12345678",
    32  		"5d386fbdbf11f1141010f81a46b40f94887367562bd33b452bbaa6ce1cd1381e", // keyring will be used if pk not provided
    33  		false,
    34  	)
    35  
    36  	if err != nil {
    37  		panic(err)
    38  	}
    39  
    40  	clientCtx, err := chainclient.NewClientContext(
    41  		network.ChainId,
    42  		senderAddress.String(),
    43  		cosmosKeyring,
    44  	)
    45  
    46  	if err != nil {
    47  		panic(err)
    48  	}
    49  
    50  	clientCtx = clientCtx.WithNodeURI(network.TmEndpoint).WithClient(tmRPC)
    51  
    52  	chainClient, err := chainclient.NewChainClient(
    53  		clientCtx,
    54  		network,
    55  		common.OptionGasPrices(client.DefaultGasPriceWithDenom),
    56  	)
    57  
    58  	if err != nil {
    59  		panic(err)
    60  	}
    61  
    62  	ctx := context.Background()
    63  
    64  	timeOutCtx, cancelFn := context.WithTimeout(ctx, 30*time.Second)
    65  	defer cancelFn()
    66  
    67  	resp, err := chainClient.GetTx(timeOutCtx, "A2B2B971C690AE7977451D24D6F450AECE6BCCB271E91E32C2563342DDA5254B")
    68  	if err != nil {
    69  		panic(err)
    70  	}
    71  
    72  	fmt.Println(resp.TxResponse)
    73  }