SendTransaction Access API Method
Parameters
transaction
object
REQUIRED
Loading...
script
string
Loading...
arguments
array
Loading...
reference_block_id
string
Loading...
gas_limit
integer
Loading...
proposal_key
object
Loading...
address
string
Loading...
key_id
integer
Loading...
sequence_number
integer
Loading...
payer
string
Loading...
authorizers
array
Loading...
payload_signatures
array
Loading...
address
string
Loading...
key_id
integer
Loading...
signature
string
Loading...
envelope_signatures
array
Loading...
address
string
Loading...
key_id
integer
Loading...
signature
string
Loading...
Returns
id
string
Loading...
metadata
object
Loading...
Request
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}
Don't have an account yet?
Create your Quicknode endpoint in seconds and start building
Get started for free