client

package module
v0.0.0-...-2aad2e8 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 3, 2022 License: LGPL-3.0 Imports: 9 Imported by: 0

README

go-relayer-client

Client library for go-relayer, used for submitting transactions to the relayer.

Requirements

  • go1.18+

Usage

// ... code omitted
req := &common.SubmitTransactionRequest{
	From:  from,
	To:    to,
	Value: big.NewInt(0),
	Gas:   big.NewInt(679639582),
	Nonce: nonce,
	Data:  calldata,
}

c := client.NewClient("http://localhost:8545")
resp, err := c.SubmitTransaction(req)
if err != nil {
	panic(err)
}

fmt.Println("sent tx to relayer: hash", resp.TxHash)

For a full example, see examples/main.go.

Run local example

The example in examples/main.go works with go-relayer locally.

To try it:

  1. Install and run ganache:
npm i -g ganache
ganache --deterministic --accounts=50
  1. Clone and build go-relayer:
git clone https://github.com/AthanorLabs/go-relayer
cd go-relayer
make build
./bin/relayer --dev
  1. Clone and build go-relayer-client:
git clone https://github.com/AthanorLabs/go-relayer-client
cd go-relayer-client
make build
./bin/example

You should see logs in the client as follows:

sent tx to relayer: hash 0xaaa5b2a84d1c4e4e5c251fe1ccb6059115267c6432d031615d20f5dae2771ddf
tx successful!

You should see logs in the relayer as follows:

2022-09-29T14:08:03.117-0400	INFO	cmd	cmd/main.go:132	starting relayer with ethereum endpoint http://localhost:8545 and chain ID 1337
2022-09-29T14:08:03.232-0400	INFO	cmd	cmd/main.go:208	deployed MinimalForwarder.sol to 0xe78A0F7E598Cc8b0Bb87894B0F60dD2a88d6a8Ab
2022-09-29T14:08:03.233-0400	INFO	rpc	rpc/server.go:62	starting RPC server on http://localhost:7799
2022-09-29T14:08:16.685-0400	INFO	relayer	relayer/relayer.go:109	submitted transaction 0xaaa5b2a84d1c4e4e5c251fe1ccb6059115267c6432d031615d20f5dae2771ddf

Documentation

Index

Constants

View Source
const DefaultJSONRPCVersion = "2.0"

DefaultJSONRPCVersion ...

View Source
const DefaultLocalRelayerEndpoint = "http://localhost:7799"

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

type Client struct {
	// contains filtered or unexported fields
}

func NewClient

func NewClient(endpoint string) *Client

func (*Client) SubmitTransaction

Cancel calls relayer_submitTransaction.

type ErrCode

type ErrCode int

ErrCode is a int type used for the rpc error codes

type Error

type Error struct {
	Message   string                 `json:"message"`
	ErrorCode ErrCode                `json:"code"`
	Data      map[string]interface{} `json:"data"`
}

Error is a struct that holds the error message and the error code for a error

func (*Error) Error

func (e *Error) Error() string

Error ...

type Request

type Request struct {
	JSONRPC string          `json:"jsonrpc"`
	Method  string          `json:"method"`
	Params  json.RawMessage `json:"params"`
	ID      uint64          `json:"id"`
}

Request represents a JSON-RPC request

type Response

type Response struct {
	Version string           `json:"jsonrpc"`
	Result  json.RawMessage  `json:"result"`
	Error   *Error           `json:"error"`
	ID      *json.RawMessage `json:"id"`
}

Response is the JSON format of a response

func PostRPC

func PostRPC(endpoint, method, params string) (*Response, error)

PostRPC posts a JSON-RPC call to the given endpoint.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL