# Rayonism Hackathon: Building With Prysm By the Prysmatic Labs team, this is a document prepared for participants in the [Rayonism](https://notes.ethereum.org/@protolambda/rayonism) hackathon for Ethereum. [toc] ## Getting Started <img style="float: left; width: 400px;" src="https://storage.googleapis.com/gopherizeme.appspot.com/gophers/2cf040ad48551efccd246d8c88b9b5cf7c4d5d4a.png"> Prysm is one of the 4 eth2 implementations live today on mainnet, securing billions of dollars worth of value in Ethereum Proof of Stake. Prysm is written in Go, following in the footsteps of the go-ethereum project, and has natural interoperability with Ethereum 1.0 as a result. This document is a reference for all hackers participating in Rayonism on how to use Prysm for your projects. Some of the useful resources for Prysm development are: - [Official documentation](https://docs.prylabs.network) - [Main repo](https://github.com/prysmaticlabs/prysm) - [APIs repo](https://github.com/prysmaticlabs/ethereumapis) ## Launching a Local ETH1 <> ETH2 Merge Network We have been able to launch a local network of a Prysm beacon node running proof of stake consensus + a Go-Ethereum node executing transactions to simulate the eth1 <> eth2 merge. You can find full instructions on how to run the Prysm merge demo [here](https://hackmd.io/7hBTexswRXSRDOPhGgqNLA). ## Prysm ETH2 API Prysm exposes an http JSON API as well as a gRPC API for interacting with it remotely to retrieve or submit data to the beacon node. There is currently an [eth2 standard API](https://github.com/ethereum/eth2.0-APIs), however, Prysm does not yet fully comply with the specification. Instead, Prysm currently uses [prysmaticlabs/ethereumapis](https://github.com/prysmaticlabs/ethereumapis) in production. :::warning Heads-up Prysm's API currently returns base64-encoded strings for representing byte data in **both** request and response types. ::: You can find the detailed API endpoints along with request/response types on [swaggerhub](https://app.swaggerhub.com/apis/prysmaticlabs/prysm-ethereum-apis/v1alpha1). By default, Prysm exposes an http API endpoint at `http://localhost:3500`. You can retrieve, for example, the head of the chain by calling the `/eth/v1alpha1/beacon/chainhead` endpoint as follows: ``` curl http://127.0.0.1:3500/eth/v1alpha1/beacon/chainhead ``` If you want to interact with the API programmatically in Go for your project, we recommend using `gRPC` such as in the example script below, which gives you automatic Go types and request/response functions you can use without needing to write extra code on top of our API: ```go= package main import ( "context" "encoding/hex" "flag" ptypes "github.com/gogo/protobuf/types" pb "github.com/prysmaticlabs/ethereumapis/eth/v1alpha1" "github.com/sirupsen/logrus" "google.golang.org/grpc" ) func main() { var beaconNodeEndpoint string flag.StringVar( &beaconNodeEndpoint, "grpc-endpoint", "localhost:4000", "Specify a gRPC endpoint to a Prysm beacon node", ) flag.Parse() // Dial the beacon node. conn, err := grpc.Dial(beaconNodeEndpoint, grpc.WithInsecure()) if err != nil { panic(err) } client := pb.NewBeaconChainClient(conn) // Retrieve and log the chain head. head, err := client.GetChainHead(context.Background(), &ptypes.Empty{}) if err != nil { panic(err) } logrus.WithFields(logrus.Fields{ "HeadSlot": head.HeadSlot, "HeadRoot": hex.EncodeToString(head.HeadBlockRoot), "JustifiedEpoch": head.JustifiedEpoch, "JustifiedRoot": hex.EncodeToString(head.JustifiedBlockRoot), "FinalizedEpoch": head.FinalizedEpoch, "FinalizedRoot": hex.EncodeToString(head.FinalizedBlockRoot), }).Infof("Chain head information from %s", beaconNodeEndpoint) } ``` ## Metrics Prysm utilizes [Prometheus](https://prometheus.io/) for scraping metrics. By default, metrics can be found at `http://localhost:8080/metrics` for the beacon node `http://localhost:8081/metrics` for the validator client We recommend using [Grafana](https://grafana.com/) as the visualizer for your node metrics. :::info Sample dashboard A good grafana dashboard to start off with was prepared by one of our contributors and is explained in our documentation [here](https://docs.prylabs.network/docs/prysm-usage/monitoring/grafana-dashboard). ::: ## Prysm Development The Prysmatic Labs team uses the [Bazel](https://bazel.build/) build system to build our project. For those unfamiliar, Bazel is an advanced build language used for monorepos and projects where reproducible builds are _critical_. In eth2, it is critical we are confident our code works and that users have the same results running our code as we do. For this, Bazel makes our lives much easier. You can read more about how to build from source with Bazel [here](https://docs.prylabs.network). We understand for local development and modifying our code, Bazel can overkill. Prysm also _fully supports_ go modules, so you are able to do `go get github.com/prysmaticlabs/prysm`, run `go test` in the beacon node and even `go build` as desired. ### Running Tests Using the Go tool, you can run tests with `go test -v ./path/to/package` which will give you verbose output. Using Bazel, you can run tests with: ``` bazel test //beacon-chain/... --test_arg=-test.v --test_output=streamed ``` Which will also give you useful, verbose output for your code. ### Contributing You can contribute to the Prysm project by opening an issue or pull request on Github [here](https://github.com/prysmaticlabs/prysm). We welcome all contributions, even spelling fixes or minor improvements. Read our [contribution guide](https://docs.prylabs.network/docs/contribute/contribution-guidelines) for expectations on how the flow of contributions typically works. ## Support The Prysmatic Labs team is dedicated to helping contributors and community members. Our [Discord](https://discord.gg/prysmaticlabs)'s #contrbute channel is the main place where we all gather and will be offering dedicated time towards Rayonism contributors.