2

This might be a stupid question, but I am struggling to figure out what exactly gRPC does. I have this endpoing access-mainnet-beta.onflow.org:9000 (https://docs.onflow.org/access-api/)

that I would love to access, but I do not necessarily want to download their SDK.

I've never used rpc only REST and websocket APIs, so I am struggling to understand how to get gRPC going. All the 'basic introductions' to gRPC don't make any sense to me unfortunately and I've not found a tutorial on how to request data from gRPC endpoint.

Any help would be great, even if its a link to a tutorial that can explain it to me.

Regards,

Allan
  • 21
  • 2
  • Maybe you need read toutal of how to use grpc, you can reference [grpc-java-sample](https://github.com/helloworlde/grpc-java-sample) – HelloWood Aug 05 '21 at 02:33

1 Answers1

2

gRPCurl is a useful tool for interacting with gRPC servers.

The are significant differences between REST and gRPC:

  1. gRPC uses HTTP2 (REST generally uses HTTP1.1)
  2. gRPC requires a schema (generally a protobuf)

If the gRPC service supports reflection, you'll be able to grpcurl [host:port] list. If it doesn't, you'll need to grab a copy of the schema (protobuf) so that gRPCurl can interact with the server.

I was unable to connect to access-mainnet-beta.onflow.org:9000 but:

grpcurl \
-plaintext \
access.devnet.nodes.onflow.org:9000 \
  list
Failed to list services: server does not support the reflection API

So, it appears you'll need to grab the protos and pass these to grpcurl.

And:

# list
grpcurl flow-testnet.g.alchemy.com:443 list
flow.access.AccessAPI

# list methods for the above service
grpcurl flow-testnet.g.alchemy.com:443 list flow.access.AccessAPI
flow.access.AccessAPI.ExecuteScriptAtBlockHeight
flow.access.AccessAPI.ExecuteScriptAtBlockID
flow.access.AccessAPI.ExecuteScriptAtLatestBlock
flow.access.AccessAPI.GetAccount
flow.access.AccessAPI.GetAccountAtBlockHeight
flow.access.AccessAPI.GetAccountAtLatestBlock
flow.access.AccessAPI.GetBlockByHeight
flow.access.AccessAPI.GetBlockByID
flow.access.AccessAPI.GetBlockHeaderByHeight
flow.access.AccessAPI.GetBlockHeaderByID
flow.access.AccessAPI.GetCollectionByID
flow.access.AccessAPI.GetEventsForBlockIDs
flow.access.AccessAPI.GetEventsForHeightRange
flow.access.AccessAPI.GetLatestBlock
flow.access.AccessAPI.GetLatestBlockHeader
flow.access.AccessAPI.GetLatestProtocolStateSnapshot
flow.access.AccessAPI.GetNetworkParameters
flow.access.AccessAPI.GetTransaction
flow.access.AccessAPI.GetTransactionResult
flow.access.AccessAPI.Ping
flow.access.AccessAPI.SendTransaction

# describe `Ping`
grpcurl flow-testnet.g.alchemy.com:443 describe flow.access.AccessAPI.Ping
flow.access.AccessAPI.Ping is a method:
rpc Ping ( .flow.access.PingRequest ) returns ( .flow.access.PingResponse );

# invoke `Ping`
grpcurl flow-testnet.g.alchemy.com:443 flow.access.AccessAPI.Ping
ERROR:
  Code: Unauthenticated
  Message: Missing api_key in metadata

I guess you need an API key to proceed.

DazWilkin
  • 32,823
  • 5
  • 47
  • 88