Package: ethereumapis
Ethereum APIsThis repository hostsPrysm's service interface definitions for the Ethereum 2.0 API. Theseprotocol bufferservice definitions supportgRPCas well as JSON over HTTP.Need assistance?More indepth descriptions of each service are available inthis sectionof our official documentation. For more general information on the functionality of gRPC and protocol buffers, see thegRPC guide. If you still have questions, feel free to stop by either ourDiscordorGitterand a member of the team or our community will be happy to assist you.Service definitionsPackageServiceVersionDescriptionethBeaconChainv1alpha1This service is used to retrieve critical data relevant to the Ethereum 2.0 phase 0 beacon chain, including the most recent head block, current pending deposits, the chain state and more.ethNodev1alpha1The Node service returns information about the Ethereum node itself, including versioning and general information as well as network sync status and a list of services currently implemented on the node.ethValidatorv1alpha1This API provides the information a validator needs to retrieve throughout its life cycle, including recieved assignments from the network, its current index in the state as well as the rewards and penalties that have been applied to it.ContributingThanks for wanting to contribute to our eth2 API! Go libraries may be generated from theethereumapis repositoryusingBazel, making it easy to make changes to the schemas needed and generate Go files from them.Python libraries can be generated usingscripts/build-py-package.py; we regularly push these libraries to PyPI asethereumapis.DependenciesHere's what you need to get started:A modern, UNIX operating systemThe latest release ofBazelinstalledThecmakepackage installedThegitpackage installedMaking API Schema ChangesSay you want to add a new endpoint to theBeaconChaingRPC service in our API schema to retrieve orphaned blocks. First, make sure the functionality you wish to add is not already covered by one of our endpoints onhttps://api.prylabs.network. Also, keep in mind making strict changes to the API schema can often times be difficult without a significant reason as this API is used by many different developers building on eth2. If you are confident in your desired changes, you can proceed by modifying the protobuf schema:serviceBeaconChain{// Retrieve orphaned blocks from the eth2 chain.rpcGetOrphanedBlocks(OrphanedBlocksRequest)returns(OrphanedBlocksResponse){option(google.api.http)={get:"/eth/v1alpha1/beacon/blocks/orphaned"};}...}messageOrphanedBlocksRequest{uint64slot=1;}messageOrphanedBlocksResponse{repeatedBeaconBlockblocks=1;}After making your changes, you can regenerate the Go libraries from the schema by running:$./scripts/update-go-pbs.shThen, open a pull request with your changes onhttps://github.com/prysmaticlabs/ethereumapis. Next, you'll be ready to implement your new changes in Prysm itself.Implementing Your Changes in PrysmEnsure you have read ourcontribution guidelinesfirst. Then, once your changes to the API schema are merged into the master branch of ethereumapis, you can update Prysm's dependency on ethereumapis to its latest version with the command:$bazelrun//:gazelle--update-reposgithub.com/prysmaticlabs/ethereumapisPrysm also utilizes generated mocks for testing gRPC requests/responses, so you will also need to regenerate the required mocks by running:$./scripts/update-mockgen.shNow, you will be able to implement your required changes in Prysm.RESTful endpoints (gRPC Transcoding)All of the gRPC services should define JSON over HTTP endpoints by specifyingHTTPRules. Developers may choose to bundle a REST service of gRPC with their client implementation binaries, or alternatively, they may use a JSON encoding proxy such asEnvoy Proxy,grpc-gateway, etc.For more information on gRPC transcoding, see the examples foundhere.Code sample:service Messaging {
    rpc GetMessage(GetMessageRequest) returns (Message) {
        option (google.api.http) = {
            get: "/v1/{name=messages/*}"
        };
    }
}
message GetMessageRequest {
    string name = 1; // Mapped to URL Path.
}
message Message {
    string text = 1; // The resource content.
}This enables an HTTP REST to gRPC mapping, as shown below:HTTPgRPCGET /v1/messages/123456GetMessage(name: "messages/123456")JSON mappingThe majority of field primitive types for Ethereum are eitherbytesoruint64. The canonical JSON mapping for those fields are a Base64 encoded string forbytes, or a string representation ofuint64. Since JavaScript loses precision for values overMAX_SAFE_INTEGER, uint64 must be a JSON string in order to accommodate those values. If the field value not changed and is still set to protobuf's default, this field will be omitted from the JSON encoding entirely.For more details on JSON mapping for other types, view the relevant section in theproto3 language guide.gRPC tooling and resourcesAwesome gRPCGoogle's API Style GuideLanguage reference for protoc3Protocol Buffer Basics: GoTranscoding gRPC to JSON/HTTP using EnvoyLicenseApache 2.0