How do I connect to a gRPC access node?

Daniela
Daniela
  • Updated
To connect to a gRPC access node, you need to configure your SDK with the correct access node API URL. The specific steps can vary depending on the SDK you are using. By default, the library uses HTTP to communicate with the access nodes. An error will be returned if the host is unreachable.
 

The public Flow gRPC access nodes are accessible at:

Testnet

https://access-testnet.onflow.org 

Mainnet

https://access-mainnet.onflow.org 

 

For local development, use the Flow emulator which once started provides an HTTP access endpoint at 127.0.0.1:8888 and a gRPC access endpoint at 127.0.0.1:3569. If using the gRPC Access API, the sdk.transport configuration key must be populated, as this value defaults to the HTTP API transport. The SDK can be configured to use the gRPC API transport as follows:

import { config } from "@onflow/fcl";
import { send as transportGRPC } from "@onflow/transport-grpc";

config({
"accessNode.api": "https://access-testnet.onflow.org",
"sdk.transport": transportGRPC
});
 
Here are some examples for different SDKs:
 

JavaScript (FCL-JS): You need to specify the sdk.transport configuration key if you wish to use the gRPC API. Here is an example of how to configure the SDK to use the gRPC API transport:

 
import { config } from "@onflow/fcl"
import { send as transportGRPC } from "@onflow/transport-grpc"

config({
"accessNode.api": "https://access-testnet.onflow.org",
"sdk.transport": transportGRPC
})
 
Python: You can use the flow_client function to connect to an access node:
async with flow_client(
host="127.0.0.1", port="3569"
) as flow_client:
# do something with `flow_client`
 
Go: You can initialize a gRPC client using the grpc.NewClient function: 
 
// initialize a gPRC emulator client
flowClient, err = grpc.NewClient(grpc.EmulatorHost)
 
Swift: You can initialize a gRPC access client using the Flow.GRPCAccessAPI function:
let accessAPI = Flow.GRPCAccessAPI(chainID: .mainnet)!
let chainID = Flow.ChainID.mainnet
flow.configure(chainID: chainID, accessAPI: accessAPI)
 
Please replace the URLs and ports in the examples with the actual URLs and ports of the access nodes you want to connect to.