Skip to main content

SendTransaction Access API Method

Loading...

Updated on
Oct 24, 2025

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
1
package main
2
3
import (
4
"context"
5
"crypto/tls"
6
"fmt"
7
"log"
8
9
"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
)
14
15
type auth struct {
16
token string
17
}
18
19
func (a *auth) GetRequestMetadata(ctx context.Context, uri ...string) (map[string]string, error) {
20
return map[string]string{
21
"x-token": a.token,
22
}, nil
23
}
24
25
func (auth) RequireTransportSecurity() bool {
26
return false
27
}
28
29
func getAccessClientWithXToken(endpoint, token string) (access.AccessAPIClient, error) {
30
target := endpoint + ".flow-mainnet.quiknode.pro:8999" // for TLS connections
31
client, err := grpc.Dial(target,
32
grpc.WithTransportCredentials(credentials.NewTLS(&tls.Config{})),
33
grpc.WithPerRPCCredentials(&auth{
34
token: token,
35
}),
36
)
37
if err != nil {
38
return nil, fmt.Errorf("Unable to dial endpoint %w", err)
39
}
40
return access.NewAccessAPIClient(client), nil
41
}
42
43
func main() {
44
token := "TOKEN_GOES_HERE"
45
ctx := context.Background()
46
47
client, err := getAccessClientWithXToken("ENDPOINT-NAME", token)
48
if err != nil {
49
log.Fatalf("Failed to create client: %v", err)
50
}
51
52
script := []byte(`
53
transaction {
54
prepare(signer: AuthAccount) {
55
log("Transaction executed")
56
}
57
}
58
`)
59
latestBlockReq := &access.GetLatestBlockRequest{IsSealed: true}
60
latestBlock, err := client.GetLatestBlock(ctx, latestBlockReq)
61
if err != nil {
62
log.Fatalf("Failed to get latest block: %v", err)
63
}
64
65
payerAddress := []byte("PAYER_ADDRESS_BYTES")
66
proposalKeyAddress := []byte("PROPOSAL_KEY_ADDRESS_BYTES")
67
authorizerAddress := []byte("AUTHORIZER_ADDRESS_BYTES")
68
69
transaction := &entities.Transaction{
70
Script: script,
71
Arguments: [][]byte{},
72
ReferenceBlockId: latestBlock.Block.Id,
73
GasLimit: 100,
74
ProposalKey: &entities.Transaction_ProposalKey{
75
Address: proposalKeyAddress,
76
KeyId: 0,
77
SequenceNumber: 0,
78
},
79
Payer: payerAddress,
80
Authorizers: [][]byte{authorizerAddress},
81
PayloadSignatures: []*entities.Transaction_Signature{
82
{
83
Address: proposalKeyAddress,
84
KeyId: 0,
85
Signature: []byte("PAYLOAD_SIGNATURE"),
86
},
87
},
88
EnvelopeSignatures: []*entities.Transaction_Signature{
89
{
90
Address: payerAddress,
91
KeyId: 0,
92
Signature: []byte("ENVELOPE_SIGNATURE"),
93
},
94
},
95
}
96
97
sendTxResp, err := client.SendTransaction(ctx, &access.SendTransactionRequest{Transaction: transaction})
98
if err != nil {
99
log.Fatalf("Failed to send transaction: %v", err)
100
}
101
102
fmt.Printf("Transaction sent successfully!\n")
103
fmt.Printf("Transaction ID: %x\n", sendTxResp.Id)
104
fmt.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