rpc

package
v0.6.4 Latest Latest
Warning

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

Go to latest
Published: Feb 19, 2025 License: GPL-3.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var RPCendpoint = map[string]RPCMethod{
	"ClientVersion":       {"web3_clientVersion", "GET"},
	"Sha3":                {"web3_sha3", "POST"},
	"NetworkId":           {"net_id", "GET"},
	"MostRecentBlock":     {"eth_blockNumber", "POST"},
	"GetBalance":          {"eth_getBalance", "POST"},
	"GetStorageAt":        {"eth_getStorageAt", "GET"},
	"GetTransactionCount": {"eth_getTransactionCount", "GET"},
	"GetCode":             {"eth_getCode", "GET"},
	"GetBlockByHash":      {"eth_getBlockByHash", "GET"},

	"Sign":                             {"eth_sign", "POST"},
	"SignTransaction":                  {"eth_signTransaction", "POST"},
	"SendTransaction":                  {"eth_sendTransaction", "POST"},
	"SendRawTransaction":               {"eth_sendRawTransaction", "POST"},
	"GasPrice":                         {"eth_gasPrice", "GET"},
	"Coinbase":                         {"eth_coinbase", "GET"},
	"GetTransactionByHash":             {"eth_getTransactionByHash", "POST"},
	"GetBlockReceipts":                 {"eth_getBlockReceipts", "POST"},
	"GetTransactionReceipt":            {"eth_getTransactionReceipt", "POST"},
	"Call":                             {"eth_call", "POST"},
	"Account":                          {"eth_accounts", "GET"},
	"EstimateGas":                      {"eth_estimateGas", "GET"},
	"GetBlockTransactionCountByNumber": {"eth_getBlockTransactionCountByNumber", "GET"},
	"GetBlockByNumber":                 {"eth_getBlockByNumber", "GET"},
	"GetProof":                         {"eth_getProof", "GET"},
	"GetBlockTransactionCountByHash":   {"eth_getBlockTransactionCountByHash", "GET"},
	"FeeHistory":                       {"eth_feeHistory", "GET"},
}

https://ethereum.github.io/execution-apis/api-documentation/

Functions

This section is empty.

Types

type ContractCreationTr added in v0.6.0

type ContractCreationTr struct {
	From  string `json:"from"`
	Value string `json:"value"`
	Input string `json:"data"`
}

Represent the transaction to create a contract When creating a contract, the TO field should be absent

type Endpoint

type Endpoint struct {
	ParsedURL *url.URL
	// contains filtered or unexported fields
}

represent the endpoint used as the entry point to the network. This can be a public endpoint as well as a personal node

func ConnectEndpoint

func ConnectEndpoint(Rawurl string) (*Endpoint, error)

Initialize the endpoint.

func ConnectLocalEndpoint added in v0.6.2

func ConnectLocalEndpoint() (*Endpoint, error)

return by default the IPC endpoint created when running geth locally

func (*Endpoint) Call

func (ep *Endpoint) Call(tr Transaction) (*RPCResponse, error)

func (*Endpoint) ClientVersion

func (ep *Endpoint) ClientVersion() (*RPCResponse, error)

func (*Endpoint) DeployContract added in v0.6.0

func (ep *Endpoint) DeployContract(sender string, contractByteCodePath string) (*TransactionReceiptResponse, error)

DeployContract deploy a contract to the blockchain it takes the account which is deploying the contract as first argument The second argument is the path to the compiled contract it return a TransactionReceipt struct (which contain the contract address) upon successfull completion if an error occur, return nil and an error

func (*Endpoint) EstimateGas added in v0.6.2

func (ep *Endpoint) EstimateGas(tr Transaction) (*RPCResponse, error)

func (*Endpoint) FeeHistory added in v0.6.2

func (ep *Endpoint) FeeHistory(blockCount string, newestBlock string, rewardPercentile []float32) (*RPCResponse, error)

func (*Endpoint) GetAccounts added in v0.6.2

func (ep *Endpoint) GetAccounts() (*RPCResponse, error)

func (*Endpoint) GetBalance

func (ep *Endpoint) GetBalance(address string) (*RPCResponse, error)

func (*Endpoint) GetBlockByNumber added in v0.6.2

func (ep *Endpoint) GetBlockByNumber(blockNumber string) (*RPCResponse, error)

func (*Endpoint) GetBlockReceipts

func (ep *Endpoint) GetBlockReceipts(blockNumber string) (*RPCResponse, error)

func (*Endpoint) GetBlockTransactionCountByHash added in v0.6.2

func (ep *Endpoint) GetBlockTransactionCountByHash(blockHash string) (*RPCResponse, error)

APPAREMENT C EST PAS REQUIRE LE BLOCKHASH ??

func (*Endpoint) GetBlockTransactionCountByNumber added in v0.6.2

func (ep *Endpoint) GetBlockTransactionCountByNumber(blockNumber string) (*RPCResponse, error)

func (*Endpoint) GetCode

func (ep *Endpoint) GetCode(address string) (*RPCResponse, error)

func (*Endpoint) GetCoinbase

func (ep *Endpoint) GetCoinbase() (*RPCResponse, error)

func (*Endpoint) GetGasPrice

func (ep *Endpoint) GetGasPrice() (*RPCResponse, error)

func (*Endpoint) GetProof added in v0.6.2

func (ep *Endpoint) GetProof(address string, storageKey []string, blockNumber string) (*RPCResponse, error)

func (*Endpoint) GetStorageAt

func (ep *Endpoint) GetStorageAt(contractAdress string, storageAddr int) (*RPCResponse, error)

func (*Endpoint) GetTransactionByHash

func (ep *Endpoint) GetTransactionByHash(transactionHash string) (*RPCResponse, error)

func (*Endpoint) GetTransactionCount

func (ep *Endpoint) GetTransactionCount(address string) (*RPCResponse, error)

func (*Endpoint) GetTransactionReceipt

func (ep *Endpoint) GetTransactionReceipt(transactionHash string) (*TransactionReceiptResponse, error)

GetTransactionReceipt query the receipt of a transaction based on the hash of the transaction. Upon successful completion, it return a pointer to a TransactionReceiptResponse struct In case of failure, return nil and an appropriate error

func (*Endpoint) HttpRequest

func (ep *Endpoint) HttpRequest(httpMethod string, RPCjson []byte) (*RPCResponse, error)

* Used when connecting to the endpoint via http * return an RPCResponse if everything goes well and nil and an error otherwise

func (*Endpoint) MostRecentBlock

func (ep *Endpoint) MostRecentBlock() (*RPCResponse, error)

func (*Endpoint) NetworkId added in v0.2.0

func (ep *Endpoint) NetworkId() (*RPCResponse, error)

func (*Endpoint) Request added in v0.3.0

func (ep *Endpoint) Request(Params []Parameters, rpcDetail RPCMethod) (*RPCResponse, error)

func (*Endpoint) SendRawTransaction

func (ep *Endpoint) SendRawTransaction(rawSignedTransaction string) (*RPCResponse, error)

func (*Endpoint) SendToken added in v0.6.2

func (ep *Endpoint) SendToken(amount string, from string, to string) (*RPCResponse, error)

wrapper around sendTransaction to facilitate the sending of token the two arguments are value, the amount in wei to send from the sender of the amount to the address to send the amount to

func (*Endpoint) SendTransaction

func (ep *Endpoint) SendTransaction(transaction interface{}) (*RPCResponse, error)

func (*Endpoint) Sha3

func (ep *Endpoint) Sha3(data string) (*RPCResponse, error)

func (*Endpoint) SignTransaction

func (ep *Endpoint) SignTransaction(transaction Transaction) (*RPCResponse, error)

func (*Endpoint) UnixSocketRequest added in v0.3.0

func (ep *Endpoint) UnixSocketRequest(RPCjson []byte) (*RPCResponse, error)

* Used when trying to dialog with the node via UnixSocket * Return an RPCResponse structure with the structure or an error if something went wrong * note that if the RPC request went wrong, this function return a RPCResponse with an RPCERROR in it

type Parameters

type Parameters interface{}

Represent the parameters to allow multiple type

type RPCError added in v0.3.0

type RPCError struct {
	Code    int    `json:"code"`
	Message string `json:"message"`
}

type RPCMethod

type RPCMethod struct {
	Method     string
	HTTPMethod string
}

type RPCResponse added in v0.3.0

type RPCResponse struct {
	Jsonrpc string    `json:"jsonrpc"`
	Id      int       `json:"id"`
	Result  any       `json:"result"`
	Error   *RPCError `json:"error"`
}

type RPCTransaction

type RPCTransaction struct {
	Jsonrpc string       `json:"jsonrpc"`
	Method  string       `json:"method"`
	Params  []Parameters `json:"params"`
	Id      int          `json:"id"` //not sure what this is used for, seems like it can be anything.
}

The structure of the RPC call made to the endpoint

type Transaction

type Transaction struct {
	From  string `json:"from"`
	To    string `json:"to"`
	Value string `json:"value"`
	Input string `json:"data"`
}

Represent the transaction

func BuildTransaction

func BuildTransaction(from string, to string, value string, input string) Transaction

type TransactionReceiptResponse added in v0.6.0

type TransactionReceiptResponse struct {
	BlockHash         string `json:"blockHash"`
	BlockNumber       string `json:"blockNumber"`
	ContractAddress   string `json:"contractAddress"`
	CumulativeGasUser string `json:"cumulativeGasUser"`
	EffectiveGasPrice string `json:"effectiveGasPrice"`
	From              string `json:"from"`
	GasUsed           string `json:"gasUsed"`
	LogsBloom         string `json:"logsBloom"`
	Status            string `json:"status"`
	To                string `json:"to"`
	TransactionHash   string `json:"transactionHash"`
	TransactionIndex  string `json:"transactionIndex"`
	Type              string `json:"type"`
}

TransactionReceiptResponse represent the Response when querying the receipt of a transaction

Jump to

Keyboard shortcuts

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