Documentation
¶
Overview ¶
Package erpc provides a context-aware Go client for ERPC JSON-RPC, REST, server-sent events, and WebSocket subscriptions.
Index ¶
- Constants
- Variables
- type AccountClient
- type BatchCall
- type BinaryUpdate
- type Client
- type CloudCatalogClient
- type CloudClient
- type CloudConfig
- type CloudCredit
- type CloudCreditClient
- type CloudOffering
- type CloudOfferingBilling
- type CloudResource
- type CloudResourceStatus
- type CloudResourceStatusBilling
- type CloudResourcesClient
- type Config
- type Error
- type ErrorKind
- type EthereumClient
- type EthereumRPCClient
- func (c *EthereumRPCClient) BlockNumber(ctx context.Context) (string, error)
- func (c *EthereumRPCClient) Call(ctx context.Context, transaction any, block string) (string, error)
- func (c *EthereumRPCClient) ChainID(ctx context.Context) (string, error)
- func (c *EthereumRPCClient) GetBalance(ctx context.Context, address, block string) (string, error)
- func (c *EthereumRPCClient) GetBlockByNumber(ctx context.Context, block string, fullTransactions bool) (json.RawMessage, error)
- func (c *EthereumRPCClient) SendRawTransaction(ctx context.Context, transaction string) (string, error)
- type EthereumSubscriptions
- type MonthlyAPIKeyChainUsage
- type MonthlyAPIKeyMethodUsage
- type MonthlyAPIKeyUsage
- type MonthlyAPIKeyUsageEntry
- type ParsedPriceUpdate
- type PendingRequest
- type PriceClient
- func (c *PriceClient) GetLatestPriceUpdates(ctx context.Context, options PriceUpdateOptions) (PriceUpdateResponse, error)
- func (c *PriceClient) GetPriceFeeds(ctx context.Context, queryText, assetType string) ([]PriceFeedMetadata, error)
- func (c *PriceClient) GetPriceUpdatesAtTimestamp(ctx context.Context, publishTime int64, options PriceUpdateOptions) (PriceUpdateResponse, error)
- func (c *PriceClient) StreamPriceUpdates(ctx context.Context, options PriceStreamOptions) (*PriceStream, error)
- type PriceFeedMetadata
- type PricePoint
- type PriceStream
- type PriceStreamEvent
- type PriceStreamOptions
- type PriceUpdateOptions
- type PriceUpdateResponse
- type RPCNamespace
- func (n *RPCNamespace) Batch(ctx context.Context, calls []BatchCall) ([]json.RawMessage, error)
- func (n *RPCNamespace) Endpoint() string
- func (n *RPCNamespace) Raw(ctx context.Context, method string, params any, result any) error
- func (n *RPCNamespace) Request(ctx context.Context, method string, params any, result any) error
- type SolanaClient
- type SolanaContext
- type SolanaContextResult
- type SolanaRPCClient
- func (c *SolanaRPCClient) GetAccountInfo(ctx context.Context, address string, options ...any) (SolanaContextResult[json.RawMessage], error)
- func (c *SolanaRPCClient) GetBalance(ctx context.Context, address string, options ...any) (SolanaContextResult[uint64], error)
- func (c *SolanaRPCClient) GetLatestBlockhash(ctx context.Context, options ...any) (json.RawMessage, error)
- func (c *SolanaRPCClient) GetSlot(ctx context.Context, params ...any) (uint64, error)
- func (c *SolanaRPCClient) GetTransaction(ctx context.Context, signature string, options ...any) (json.RawMessage, error)
- func (c *SolanaRPCClient) SendTransaction(ctx context.Context, transaction string, options ...any) (string, error)
- func (c *SolanaRPCClient) SimulateTransaction(ctx context.Context, transaction string, options ...any) (json.RawMessage, error)
- type SolanaSubscriptions
- func (c *SolanaSubscriptions) AccountSubscribe(ctx context.Context, address string, options ...any) (*Subscription, error)
- func (c *SolanaSubscriptions) Endpoint() string
- func (c *SolanaSubscriptions) Raw(ctx context.Context, method string, params, result any) error
- func (c *SolanaSubscriptions) RawSubscribe(ctx context.Context, method string, params any, unsubscribeMethod string) (*Subscription, error)
- func (c *SolanaSubscriptions) TransactionSubscribe(ctx context.Context, filter any, options ...any) (*Subscription, error)
- type Subscription
- type TokenBalance
- type UsageClient
Constants ¶
const ( DefaultEndpoint = "https://edge.erpc.global" DefaultAccountEndpoint = "https://solana-rpc.erpc.global" DefaultUserEndpoint = "https://user-api.erpc.global" DefaultTimeout = 30 * time.Second )
Variables ¶
var EthereumRPCMethods = []string{
"eth_accounts", "eth_baseFee", "eth_blobBaseFee", "eth_blockNumber", "eth_call", "eth_callMany",
"eth_capabilities", "eth_chainId", "eth_createAccessList", "eth_estimateGas", "eth_feeHistory", "eth_gasPrice",
"eth_getAccount", "eth_getBalance", "eth_getBlockByHash", "eth_getBlockByNumber", "eth_getBlockReceipts",
"eth_getBlockTransactionCountByHash", "eth_getBlockTransactionCountByNumber", "eth_getCode",
"eth_getFilterChanges", "eth_getFilterLogs", "eth_getLogs", "eth_getProof", "eth_getRawTransactionByHash",
"eth_getStorageAt", "eth_getTransactionByBlockHashAndIndex", "eth_getTransactionByBlockNumberAndIndex",
"eth_getTransactionByHash", "eth_getTransactionBySenderAndNonce", "eth_getTransactionCount",
"eth_getTransactionReceipt", "eth_getUncleCountByBlockHash", "eth_getUncleCountByBlockNumber",
"eth_maxPriorityFeePerGas", "eth_newBlockFilter", "eth_newFilter", "eth_newPendingTransactionFilter",
"eth_sendRawTransaction", "eth_signTransaction", "eth_simulateV1", "eth_submitWork", "eth_syncing",
"eth_uninstallFilter", "net_listening", "net_peerCount", "net_version", "txpool_content", "txpool_contentFrom",
"txpool_inspect", "txpool_status", "web3_clientVersion", "web3_sha3",
}
var EthereumSubscriptionMethods = []string{"eth_subscribe", "eth_unsubscribe"}
var SolanaAnalyticsMethods = []string{"jetEpochSummary", "jetProgramStats", "jetSlotStats", "jetTopPrograms", "jetTpsTimeseries"}
var SolanaDASMethods = []string{
"getAsset", "getAssetBatch", "getAssetProof", "getAssetProofBatch", "getAssetsByAuthority",
"getAssetsByCreator", "getAssetsByGroup", "getAssetsByOwner", "getNftEditions", "getSignaturesForAsset",
"getTokenAccounts", "getTokensByDelegate", "getTokensByOwner", "searchAssets",
}
var SolanaEnhancedSubscriptionMethods = []string{"accountSubscribe", "accountUnsubscribe", "transactionSubscribe", "transactionUnsubscribe"}
var SolanaHistoryMethods = []string{"getTransactionsForAddress", "getTransfersByAddress"}
var SolanaLeaderMethods = []string{"getLeaderSlots", "getValidatorsInformation"}
var SolanaRPCMethods = []string{
"getAccountInfo", "getBalance", "getBlock", "getBlockCommitment", "getBlockHeight",
"getBlockProduction", "getBlockTime", "getBlocks", "getBlocksWithLimit", "getClusterNodes",
"getEpochInfo", "getEpochSchedule", "getFeeForMessage", "getFirstAvailableBlock", "getGenesisHash",
"getHealth", "getHighestSnapshotSlot", "getIdentity", "getInflationGovernor", "getInflationRate",
"getInflationReward", "getLargestAccounts", "getLatestBlockhash", "getLeaderSchedule", "getMaxRetransmitSlot",
"getMaxShredInsertSlot", "getMinimumBalanceForRentExemption", "getMultipleAccounts", "getParsedTransaction",
"getPriorityFeeEstimate", "getProgramAccounts", "getProgramAccountsV2", "getRecentPerformanceSamples",
"getRecentPrioritizationFees", "getSignatureStatuses", "getSignaturesForAddress", "getSlot", "getSlotLeader",
"getSlotLeaders", "getStakeMinimumDelegation", "getSupply", "getTokenAccountBalance",
"getTokenAccountsByDelegate", "getTokenAccountsByOwner", "getTokenLargestAccounts", "getTokenSupply",
"getTransaction", "getTransactionCount", "getVersion", "getVoteAccounts", "isBlockhashValid",
"minimumLedgerSlot", "requestAirdrop", "sendTransaction", "simulateTransaction",
}
Method catalogs mirror the wire-compatible method names exposed by ERPC.
Functions ¶
This section is empty.
Types ¶
type AccountClient ¶
type AccountClient struct {
// contains filtered or unexported fields
}
AccountClient provides account and token-balance APIs.
func (*AccountClient) GetTokenBalance ¶
func (c *AccountClient) GetTokenBalance(ctx context.Context) (TokenBalance, error)
type BinaryUpdate ¶
type Client ¶
type Client struct {
Solana *SolanaClient
Ethereum *EthereumClient
Price *PriceClient
Account *AccountClient
Usage *UsageClient
}
Client groups all API namespaces backed by one API key.
type CloudCatalogClient ¶
type CloudCatalogClient struct {
// contains filtered or unexported fields
}
func (*CloudCatalogClient) List ¶
func (c *CloudCatalogClient) List(ctx context.Context) ([]CloudOffering, error)
type CloudClient ¶
type CloudClient struct {
Catalog *CloudCatalogClient
Credit *CloudCreditClient
Resources *CloudResourcesClient
Usage *UsageClient
}
CloudClient uses a scoped access token and never accepts refresh credentials.
func NewCloudClient ¶
func NewCloudClient(config CloudConfig) (*CloudClient, error)
type CloudConfig ¶
type CloudCredit ¶
type CloudCredit struct {
AlertLevel string `json:"alertLevel"`
BalanceCents int64 `json:"balanceCents"`
BurnRateCentsPerHour uint64 `json:"burnRateCentsPerHour"`
QuoteExpiresAt string `json:"quoteExpiresAt"`
QuoteTimestamp string `json:"quoteTimestamp"`
TimeToZeroHours *float64 `json:"timeToZeroHours"`
}
type CloudCreditClient ¶
type CloudCreditClient struct {
// contains filtered or unexported fields
}
func (*CloudCreditClient) Get ¶
func (c *CloudCreditClient) Get(ctx context.Context) (CloudCredit, error)
type CloudOffering ¶
type CloudOffering struct {
Billing *CloudOfferingBilling `json:"billing,omitempty"`
Capabilities []string `json:"capabilities"`
Compute map[string]string `json:"compute,omitempty"`
Description string `json:"description"`
ID string `json:"id"`
Kind string `json:"kind"`
Mode string `json:"mode,omitempty"`
Name string `json:"name"`
Regions []string `json:"regions"`
Solana map[string]string `json:"solana,omitempty"`
}
type CloudOfferingBilling ¶
type CloudResource ¶
type CloudResourceStatus ¶
type CloudResourceStatus struct {
Billing *CloudResourceStatusBilling `json:"billing,omitempty"`
ID string `json:"id"`
Status string `json:"status"`
}
type CloudResourcesClient ¶
type CloudResourcesClient struct {
// contains filtered or unexported fields
}
func (*CloudResourcesClient) Get ¶
func (c *CloudResourcesClient) Get(ctx context.Context, resourceID string) (CloudResource, error)
func (*CloudResourcesClient) GetStatus ¶
func (c *CloudResourcesClient) GetStatus(ctx context.Context, resourceID string) (CloudResourceStatus, error)
func (*CloudResourcesClient) List ¶
func (c *CloudResourcesClient) List(ctx context.Context) ([]CloudResource, error)
type Config ¶
type Config struct {
APIKey string
Endpoint string
AccountEndpoint string
UserEndpoint string
Headers http.Header
Timeout time.Duration
HTTPClient *http.Client
}
Config configures Client. APIKey is retained in memory but never returned by Endpoint methods or SDK errors.
type ErrorKind ¶
type ErrorKind string
ErrorKind identifies an SDK failure without exposing request credentials.
type EthereumClient ¶
type EthereumClient struct {
RPC *EthereumRPCClient
Subscriptions *EthereumSubscriptions
}
EthereumClient groups standard RPC and subscriptions.
type EthereumRPCClient ¶
type EthereumRPCClient struct{ *RPCNamespace }
EthereumRPCClient provides Ethereum JSON-RPC and typed common methods.
func (*EthereumRPCClient) BlockNumber ¶
func (c *EthereumRPCClient) BlockNumber(ctx context.Context) (string, error)
func (*EthereumRPCClient) ChainID ¶
func (c *EthereumRPCClient) ChainID(ctx context.Context) (string, error)
func (*EthereumRPCClient) GetBalance ¶
func (*EthereumRPCClient) GetBlockByNumber ¶
func (c *EthereumRPCClient) GetBlockByNumber(ctx context.Context, block string, fullTransactions bool) (json.RawMessage, error)
func (*EthereumRPCClient) SendRawTransaction ¶
func (c *EthereumRPCClient) SendRawTransaction(ctx context.Context, transaction string) (string, error)
SendRawTransaction is attempted exactly once. The SDK never retries it.
type EthereumSubscriptions ¶
type EthereumSubscriptions struct {
// contains filtered or unexported fields
}
func (*EthereumSubscriptions) Endpoint ¶
func (c *EthereumSubscriptions) Endpoint() string
func (*EthereumSubscriptions) Subscribe ¶
func (c *EthereumSubscriptions) Subscribe(ctx context.Context, subscription string, options ...any) (*Subscription, error)
type MonthlyAPIKeyChainUsage ¶
type MonthlyAPIKeyChainUsage struct {
Chain string `json:"chain"`
Count float64 `json:"count"`
Credits float64 `json:"credits"`
Methods []MonthlyAPIKeyMethodUsage `json:"methods"`
UpdatedAt *string `json:"updatedAt"`
}
type MonthlyAPIKeyUsage ¶
type MonthlyAPIKeyUsage struct {
APIKeys []MonthlyAPIKeyUsageEntry `json:"apiKeys"`
Chains []MonthlyAPIKeyChainUsage `json:"chains"`
HasStrandedUsage bool `json:"hasStrandedUsage"`
KeyCount float64 `json:"keyCount"`
TotalCount float64 `json:"totalCount"`
TotalCredits float64 `json:"totalCredits"`
UpdatedAt *string `json:"updatedAt"`
YearMonth string `json:"yearMonth"`
}
type MonthlyAPIKeyUsageEntry ¶
type MonthlyAPIKeyUsageEntry struct {
APIKeyLast4 string `json:"apiKeyLast4"`
APIKeyLength float64 `json:"apiKeyLength"`
Chains []MonthlyAPIKeyChainUsage `json:"chains"`
Count float64 `json:"count"`
Credits float64 `json:"credits"`
KeyID *float64 `json:"keyId"`
UpdatedAt *string `json:"updatedAt"`
}
MonthlyAPIKeyUsageEntry only contains the last four API-key characters.
type ParsedPriceUpdate ¶
type ParsedPriceUpdate struct {
EMAPrice PricePoint `json:"ema_price"`
ID string `json:"id"`
Metadata *json.RawMessage `json:"metadata,omitempty"`
Price PricePoint `json:"price"`
}
type PendingRequest ¶
type PendingRequest[T any] struct { // contains filtered or unexported fields }
PendingRequest is an inert typed request. I/O starts when Send is called.
func NewRequest ¶
func NewRequest[T any](namespace *RPCNamespace, method string, params any) *PendingRequest[T]
NewRequest creates a typed pending JSON-RPC request.
type PriceClient ¶
type PriceClient struct {
// contains filtered or unexported fields
}
func (*PriceClient) GetLatestPriceUpdates ¶
func (c *PriceClient) GetLatestPriceUpdates(ctx context.Context, options PriceUpdateOptions) (PriceUpdateResponse, error)
func (*PriceClient) GetPriceFeeds ¶
func (c *PriceClient) GetPriceFeeds(ctx context.Context, queryText, assetType string) ([]PriceFeedMetadata, error)
func (*PriceClient) GetPriceUpdatesAtTimestamp ¶
func (c *PriceClient) GetPriceUpdatesAtTimestamp(ctx context.Context, publishTime int64, options PriceUpdateOptions) (PriceUpdateResponse, error)
func (*PriceClient) StreamPriceUpdates ¶
func (c *PriceClient) StreamPriceUpdates(ctx context.Context, options PriceStreamOptions) (*PriceStream, error)
type PriceFeedMetadata ¶
type PricePoint ¶
type PriceStream ¶
type PriceStream struct {
// contains filtered or unexported fields
}
PriceStream is a streaming SSE response. Call Close when abandoning it.
func (*PriceStream) Close ¶
func (s *PriceStream) Close() error
func (*PriceStream) Next ¶
func (s *PriceStream) Next() (PriceStreamEvent, error)
Next blocks until the next data-bearing SSE event.
type PriceStreamEvent ¶
type PriceStreamEvent struct {
Data PriceUpdateResponse
Event string
ID string
}
type PriceStreamOptions ¶
type PriceStreamOptions struct {
PriceUpdateOptions
AllowUnordered *bool
BenchmarksOnly *bool
}
type PriceUpdateOptions ¶
type PriceUpdateResponse ¶
type PriceUpdateResponse struct {
Binary BinaryUpdate `json:"binary"`
Parsed []ParsedPriceUpdate `json:"parsed,omitempty"`
}
type RPCNamespace ¶
type RPCNamespace struct {
// contains filtered or unexported fields
}
RPCNamespace provides generic and batch JSON-RPC access.
func (*RPCNamespace) Batch ¶
func (n *RPCNamespace) Batch(ctx context.Context, calls []BatchCall) ([]json.RawMessage, error)
Batch sends exactly one JSON-RPC batch and returns results in caller order. The transport never silently splits a batch.
func (*RPCNamespace) Endpoint ¶
func (n *RPCNamespace) Endpoint() string
Endpoint returns the public endpoint without credentials, query, or fragment.
type SolanaClient ¶
type SolanaClient struct {
RPC *SolanaRPCClient
DAS *RPCNamespace
History *RPCNamespace
Leaders *RPCNamespace
Analytics *RPCNamespace
Subscriptions *SolanaSubscriptions
}
SolanaClient groups standard and extended Solana APIs.
type SolanaContext ¶
type SolanaContext struct {
APIVersion string `json:"apiVersion,omitempty"`
Slot uint64 `json:"slot"`
}
SolanaContext is standard response context metadata.
type SolanaContextResult ¶
type SolanaContextResult[T any] struct { Context SolanaContext `json:"context"` Value T `json:"value"` }
SolanaContextResult wraps a value with standard response context metadata.
type SolanaRPCClient ¶
type SolanaRPCClient struct{ *RPCNamespace }
SolanaRPCClient provides standard Solana JSON-RPC and typed common methods.
func (*SolanaRPCClient) GetAccountInfo ¶
func (c *SolanaRPCClient) GetAccountInfo(ctx context.Context, address string, options ...any) (SolanaContextResult[json.RawMessage], error)
func (*SolanaRPCClient) GetBalance ¶
func (c *SolanaRPCClient) GetBalance(ctx context.Context, address string, options ...any) (SolanaContextResult[uint64], error)
func (*SolanaRPCClient) GetLatestBlockhash ¶
func (c *SolanaRPCClient) GetLatestBlockhash(ctx context.Context, options ...any) (json.RawMessage, error)
func (*SolanaRPCClient) GetTransaction ¶
func (c *SolanaRPCClient) GetTransaction(ctx context.Context, signature string, options ...any) (json.RawMessage, error)
func (*SolanaRPCClient) SendTransaction ¶
func (c *SolanaRPCClient) SendTransaction(ctx context.Context, transaction string, options ...any) (string, error)
SendTransaction is attempted exactly once. The SDK never retries a state-changing request automatically.
func (*SolanaRPCClient) SimulateTransaction ¶
func (c *SolanaRPCClient) SimulateTransaction(ctx context.Context, transaction string, options ...any) (json.RawMessage, error)
type SolanaSubscriptions ¶
type SolanaSubscriptions struct {
// contains filtered or unexported fields
}
func (*SolanaSubscriptions) AccountSubscribe ¶
func (c *SolanaSubscriptions) AccountSubscribe(ctx context.Context, address string, options ...any) (*Subscription, error)
func (*SolanaSubscriptions) Endpoint ¶
func (c *SolanaSubscriptions) Endpoint() string
func (*SolanaSubscriptions) RawSubscribe ¶
func (c *SolanaSubscriptions) RawSubscribe(ctx context.Context, method string, params any, unsubscribeMethod string) (*Subscription, error)
func (*SolanaSubscriptions) TransactionSubscribe ¶
func (c *SolanaSubscriptions) TransactionSubscribe(ctx context.Context, filter any, options ...any) (*Subscription, error)
type Subscription ¶
type Subscription struct {
ID json.RawMessage
// contains filtered or unexported fields
}
Subscription is an active JSON-RPC subscription.
func (*Subscription) Unsubscribe ¶
func (s *Subscription) Unsubscribe(ctx context.Context) (bool, error)
Unsubscribe is idempotent after a successful server response.
type TokenBalance ¶
type TokenBalance struct {
MaxTokens uint64 `json:"max_tokens"`
NextRefillAt *string `json:"next_refill_at"`
Plan string `json:"plan"`
RemainingTokens uint64 `json:"remaining_tokens"`
}
TokenBalance is the current account token balance.
type UsageClient ¶
type UsageClient struct {
// contains filtered or unexported fields
}
func (*UsageClient) GetMonthlyAPIKeyUsage ¶
func (c *UsageClient) GetMonthlyAPIKeyUsage(ctx context.Context, yearMonth string) (MonthlyAPIKeyUsage, error)