Cosmos SDK makes usage of protobuf and gRPC to define its APIs.
Using BSR and protoc(optional) we can easily generate Swift code to interact with the Cosmos blockchains. This repository contains only generated code.
Package | protoc-gen-swift | protoc-gen-grpc-swift | name | version | Commit hash |
---|---|---|---|---|---|
1.0.0 | 1.21.0 | 1.14.0 | cosmos | 0.46.11 | 4074ba39c09e4b4799271a56a053227c |
osmosis | 12.1.0 | 81ded5dc0f8f46d8b93b42b66f8b5fdf | |||
evmos | 11.0.2 | c66c6f141d044e31a4ae77f5b852bcb5 | |||
band protocol | 2.4.1 | 2d59c56 |
- Mintscan provides info about the public grpc endpoints available.
The script generate-buf-local.sh
is ready to make code generation using buf
. It downloads and generates code into Sources/CosmosSDK. To regenerate the cosmos-sdk for a custom version, update the property cosmos_commit_hash
with the target cosmos-sdk commit hash and run the script.
This step is optional and depends if you want to use remote plugins(Check Remote BSR Plugins)
- Protobuf compiler
brew install protobuf
Github- Make sure that protobuf is on the system path
protoc --version
- Make sure that protobuf is on the system path
- Swift protobuf plugin
brew install swift-protobuf
. Github- Make sure that swift protobuf plugin is on the system path
protoc-gen-swift --version
- Make sure that swift protobuf plugin is on the system path
- Swift gRPC plugin
brew install grpc-swift
. Github- Make sure that gRPC swift protobuf plugin is on the system path
protoc-gen-grpc-swift --version
- Make sure that gRPC swift protobuf plugin is on the system path
- COSMOS-SDK PROTO DOC. Cosmos uses BSR to manage their API.
- BSR: Buf Schema Registry
- COSMOS SDK PROTOS CODE GENERATION
- Pick a SDK version commit to download the protos
- Code generation can be done with local protoc tools or with remote protoc tools:
- Local tools:
- Install optional tools
- Buf export + Buf generate
- Export a specific version of a remote module to a local directory.
buf export buf.build/cosmos/cosmos-sdk:${commit} --output .
- For Cosmos v0.46.x
buf export buf.build/cosmos/cosmos-sdk:8cb30a2c4de74dc9bd8d260b1e75e176 --output .
- Export a specific version of a remote module to a local directory.
- Create a yaml named
buf-local.gen.yaml
and configure it to generate the swift code for protos and gRPC.- Check that the swift-protobuf and grpc-swift versions installed are the same than the libraries that the CosmosSDK package depends on.
protoc-gen-swift --version
protoc-gen-grpc-swift --version
- Configure yaml to run
swift-protobuf
andgrpc-swift
. Checkout Buf generate for more info
- Check that the swift-protobuf and grpc-swift versions installed are the same than the libraries that the CosmosSDK package depends on.
- Buf generate
- Generate code with local plugins
buf generate --template buf-local.gen.yaml --verbose .
- Generate code with local plugins
- Remote tools:
- Buf generate
- Create a yaml named
buf-remote.gen.yaml
and configure it to generate the swift code for protos and gRPC. - Configure yaml to run
swift-protobuf
andgrpc-swift
- Check that the swift-protobuf and grpc-swift versions defined in the yaml are the same than the libraries that the CosmosSDK package depends on.
- Use Remote BSR Plugins to avoid install local tools.
- Generate code with remote plugins
buf generate --template buf-remote.gen.yaml buf.build/cosmos/cosmos-sdk:8cb30a2c4de74dc9bd8d260b1e75e176
- Create a yaml named
- Buf generate
- Local tools:
- Code generation script. Using the
generate-cosmos-buf-local.sh
script the cosmos sdk will be generated using local tools and bsr- Change the property
cosmos_commit_hash
in the script to update the commit from where the code is being generated. - Run the script and the code will be generated on
Sources/CosmosSDK
- Change the property
- Search osmosis labs on (bsr registry)[https://buf.build/osmosis-labs/osmosis].
- Pick a commit (bsr registry commits)[https://buf.build/osmosis-labs/osmosis/commits/],
81ded5dc0f8f46d8b93b42b66f8b5fdf
- Replace commit hash on
generate-osmosis-buf-local.sh
and run it
- List available grpc enpoints
grpcurl -plaintext cosmos-grpc.polkachu.com:14990 list
- List available grpc methods for a service
grpcurl -plaintext cosmos-grpc.polkachu.com:14990 list cosmos.auth.v1beta1.Query
- Describe available grpc methods for a service
grpcurl -plaintext cosmos-grpc.polkachu.com:14990 describe cosmos.auth.v1beta1.Query
- Test/Showcase SDK API's
- Document where to find the bsr tags. How to verify them regarding github protos?
- Github actions - tests
- Doc chain registry
- doc chain registry in tests https://github.com/cosmos/chain-registry/blob/master/cosmoshub/chain.json
- or other ways to find prod/test urls
- Add support for:
- Crescent ?
- TODO: clone and generate the code locally -> Band Oracle https://github.com/bandprotocol/chain/tree/master/proto/oracle/v1
- Confio https://github.com/confio/tgrade?
- Crypto.org https://github.com/crypto-org-chain/chain-main
- Desmos https://github.com/crypto-org-chain/chain-main/blob/master/proto/buf.yaml
- Gravity https://github.com/cosmos/gravity-bridge/tree/main/module
- Iris https://github.com/irisnet/irishub/tree/master/proto
- Kava https://github.com/Kava-Labs/kava/tree/master/proto
- Sifchain https://github.com/Sifchain/sifnode/tree/master/proto/sifnode
- Starname https://github.com/iov-one/starnamed/tree/main/proto
- Stride https://github.com/Stride-Labs/stride/tree/main/proto