SendTransaction Access API Method
पैरामीटर
लेन-देन
वस्तु
आवश्यक
लोड हो रहा है...
script
डोरी
लोड हो रहा है...
arguments
सरणी
लोड हो रहा है...
reference_block_id
डोरी
लोड हो रहा है...
gas_limit
पूर्णांक
लोड हो रहा है...
proposal_key
वस्तु
लोड हो रहा है...
पता
डोरी
लोड हो रहा है...
key_id
पूर्णांक
लोड हो रहा है...
sequence_number
पूर्णांक
लोड हो रहा है...
payer
डोरी
लोड हो रहा है...
authorizers
सरणी
लोड हो रहा है...
payload_signatures
सरणी
लोड हो रहा है...
पता
डोरी
लोड हो रहा है...
key_id
पूर्णांक
लोड हो रहा है...
signature
डोरी
लोड हो रहा है...
envelope_signatures
सरणी
लोड हो रहा है...
पता
डोरी
लोड हो रहा है...
key_id
पूर्णांक
लोड हो रहा है...
signature
डोरी
लोड हो रहा है...
रिटर्न
पहचान
डोरी
लोड हो रहा है...
metadata
वस्तु
लोड हो रहा है...
अनुरोध
1package main23import (4"context"5"crypto/tls"6"fmt"7"log"89"github.com/onflow/flow/protobuf/go/flow/access"10"github.com/onflow/flow/protobuf/go/flow/entities"11"google.golang.org/grpc"12"google.golang.org/grpc/credentials"13)1415type auth struct {16token string17}1819func (a *auth) GetRequestMetadata(ctx context.Context, uri ...string) (map[string]string, error) {20return map[string]string{21"x-token": a.token,22}, nil23}2425func (auth) RequireTransportSecurity() bool {26return false27}2829func getAccessClientWithXToken(endpoint, token string) (access.AccessAPIClient, error) {30target := endpoint + ".flow-mainnet.quiknode.pro:8999" // for TLS connections31client, err := grpc.Dial(target,32grpc.WithTransportCredentials(credentials.NewTLS(&tls.Config{})),33grpc.WithPerRPCCredentials(&auth{34token: token,35}),36)37if err != nil {38return nil, fmt.Errorf("Unable to dial endpoint %w", err)39}40return access.NewAccessAPIClient(client), nil41}4243func main() {44token := "TOKEN_GOES_HERE"45ctx := context.Background()4647client, err := getAccessClientWithXToken("ENDPOINT-NAME", token)48if err != nil {49log.Fatalf("Failed to create client: %v", err)50}5152script := []byte(`53transaction {54prepare(signer: AuthAccount) {55log("Transaction executed")56}57}58`)59latestBlockReq := &access.GetLatestBlockRequest{IsSealed: true}60latestBlock, err := client.GetLatestBlock(ctx, latestBlockReq)61if err != nil {62log.Fatalf("Failed to get latest block: %v", err)63}6465payerAddress := []byte("PAYER_ADDRESS_BYTES")66proposalKeyAddress := []byte("PROPOSAL_KEY_ADDRESS_BYTES")67authorizerAddress := []byte("AUTHORIZER_ADDRESS_BYTES")6869transaction := &entities.Transaction{70Script: script,71Arguments: [][]byte{},72ReferenceBlockId: latestBlock.Block.Id,73GasLimit: 100,74ProposalKey: &entities.Transaction_ProposalKey{75Address: proposalKeyAddress,76KeyId: 0,77SequenceNumber: 0,78},79Payer: payerAddress,80Authorizers: [][]byte{authorizerAddress},81PayloadSignatures: []*entities.Transaction_Signature{82{83Address: proposalKeyAddress,84KeyId: 0,85Signature: []byte("PAYLOAD_SIGNATURE"),86},87},88EnvelopeSignatures: []*entities.Transaction_Signature{89{90Address: payerAddress,91KeyId: 0,92Signature: []byte("ENVELOPE_SIGNATURE"),93},94},95}9697sendTxResp, err := client.SendTransaction(ctx, &access.SendTransactionRequest{Transaction: transaction})98if err != nil {99log.Fatalf("Failed to send transaction: %v", err)100}101102fmt.Printf("Transaction sent successfully!\n")103fmt.Printf("Transaction ID: %x\n", sendTxResp.Id)104fmt.Printf("Reference Block ID: %x\n", latestBlock.Block.Id)105}
1package main23import (4"context"5"crypto/tls"6"fmt"7"log"89"github.com/onflow/flow/protobuf/go/flow/access"10"github.com/onflow/flow/protobuf/go/flow/entities"11"google.golang.org/grpc"12"google.golang.org/grpc/credentials"13)1415type auth struct {16token string17}1819func (a *auth) GetRequestMetadata(ctx context.Context, uri ...string) (map[string]string, error) {20return map[string]string{21"x-token": a.token,22}, nil23}2425func (auth) RequireTransportSecurity() bool {26return false27}2829func getAccessClientWithXToken(endpoint, token string) (access.AccessAPIClient, error) {30target := endpoint + ".flow-mainnet.quiknode.pro:8999" // for TLS connections31client, err := grpc.Dial(target,32grpc.WithTransportCredentials(credentials.NewTLS(&tls.Config{})),33grpc.WithPerRPCCredentials(&auth{34token: token,35}),36)37if err != nil {38return nil, fmt.Errorf("Unable to dial endpoint %w", err)39}40return access.NewAccessAPIClient(client), nil41}4243func main() {44token := "TOKEN_GOES_HERE"45ctx := context.Background()4647client, err := getAccessClientWithXToken("ENDPOINT-NAME", token)48if err != nil {49log.Fatalf("Failed to create client: %v", err)50}5152script := []byte(`53transaction {54prepare(signer: AuthAccount) {55log("Transaction executed")56}57}58`)59latestBlockReq := &access.GetLatestBlockRequest{IsSealed: true}60latestBlock, err := client.GetLatestBlock(ctx, latestBlockReq)61if err != nil {62log.Fatalf("Failed to get latest block: %v", err)63}6465payerAddress := []byte("PAYER_ADDRESS_BYTES")66proposalKeyAddress := []byte("PROPOSAL_KEY_ADDRESS_BYTES")67authorizerAddress := []byte("AUTHORIZER_ADDRESS_BYTES")6869transaction := &entities.Transaction{70Script: script,71Arguments: [][]byte{},72ReferenceBlockId: latestBlock.Block.Id,73GasLimit: 100,74ProposalKey: &entities.Transaction_ProposalKey{75Address: proposalKeyAddress,76KeyId: 0,77SequenceNumber: 0,78},79Payer: payerAddress,80Authorizers: [][]byte{authorizerAddress},81PayloadSignatures: []*entities.Transaction_Signature{82{83Address: proposalKeyAddress,84KeyId: 0,85Signature: []byte("PAYLOAD_SIGNATURE"),86},87},88EnvelopeSignatures: []*entities.Transaction_Signature{89{90Address: payerAddress,91KeyId: 0,92Signature: []byte("ENVELOPE_SIGNATURE"),93},94},95}9697sendTxResp, err := client.SendTransaction(ctx, &access.SendTransactionRequest{Transaction: transaction})98if err != nil {99log.Fatalf("Failed to send transaction: %v", err)100}101102fmt.Printf("Transaction sent successfully!\n")103fmt.Printf("Transaction ID: %x\n", sendTxResp.Id)104fmt.Printf("Reference Block ID: %x\n", latestBlock.Block.Id)105}
अब तक कोई खाता नहीं है?
कुछ ही सेकंड में अपना क्विकनोड एंडपॉइंट बनाएं और निर्माण शुरू करें।
मुफ़्त में शुरुआत करें