SendTransaction Access API Method
Parameter
Transaktion
Objekt
ERFORDERLICH
Wird geladen...
Skript
Zeichenkette
Wird geladen...
arguments
Array
Wird geladen...
reference_block_id
Zeichenkette
Wird geladen...
gas_limit
Ganzzahl
Wird geladen...
proposal_key
Objekt
Wird geladen...
Adresse
Zeichenkette
Wird geladen...
key_id
Ganzzahl
Wird geladen...
sequence_number
Ganzzahl
Wird geladen...
payer
Zeichenkette
Wird geladen...
authorizers
Array
Wird geladen...
payload_signatures
Array
Wird geladen...
Adresse
Zeichenkette
Wird geladen...
key_id
Ganzzahl
Wird geladen...
Unterschrift
Zeichenkette
Wird geladen...
envelope_signatures
Array
Wird geladen...
Adresse
Zeichenkette
Wird geladen...
key_id
Ganzzahl
Wird geladen...
Unterschrift
Zeichenkette
Wird geladen...
Rücksendungen
id
Zeichenkette
Wird geladen...
metadata
Objekt
Wird geladen...
Anfrage
1Paket Hauptteil23import (4„Kontext“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)1415Typ auth Struktur {16token string17}1819func (a *auth) GetRequestMetadata(ctx Kontext.Context, uri ...Zeichenkette) (map[Zeichenkette]Zeichenkette, Fehler) {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}
1Paket Hauptteil23import (4„Kontext“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)1415Typ auth Struktur {16token string17}1819func (a *auth) GetRequestMetadata(ctx Kontext.Context, uri ...Zeichenkette) (map[Zeichenkette]Zeichenkette, Fehler) {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}
Haben Sie noch kein Konto?
Erstellen Sie Ihren Quicknode-Endpunkt in Sekundenschnelle und legen Sie los
Kostenlos loslegen