Documentation
¶
Overview ¶
Package relayer provides a client for the Polymarket Relayer API.
Overview ¶
The Relayer API submits EIP-712 signed transactions to the Polygon blockchain on behalf of users. It handles nonce management and transaction ordering.
Authentication ¶
Uses RELAYER_API_KEY and RELAYER_API_KEY_ADDRESS headers, or POLY_BUILDER_* headers for builder-authenticated requests.
Usage ¶
client := relayer.New(relayer.Config{
Credentials: &relayer.Credentials{
APIKey: "your-relayer-api-key",
Address: "0xYourAddress",
},
})
// Submit a signed transaction
var resp relayer.SubmitTransactionResponse
err := client.SubmitTransaction(ctx, relayer.SubmitTransactionRequest{...}, &resp)
// Check transaction status
tx := relayer.Transaction{TransactionID: "tx-id"}
err = client.GetTransaction(ctx, &tx)
// Get recent transactions
txs, err := client.GetRecentTransactions(ctx)
Index ¶
- Constants
- type APIKey
- type BuilderCredentials
- type Client
- func (c *Client) GetAPIKeys(ctx context.Context) ([]APIKey, error)
- func (c *Client) GetNonce(ctx context.Context, out *NonceResponse, nonceType ...NonceType) error
- func (c *Client) GetRecentTransactions(ctx context.Context, _ ...string) ([]Transaction, error)
- func (c *Client) GetRelayPayload(ctx context.Context, out *NonceResponse, nonceType NonceType) error
- func (c *Client) GetRelayerNonce(ctx context.Context, out *NonceResponse, nonceType ...NonceType) error
- func (c *Client) GetTransaction(ctx context.Context, out *Transaction) error
- func (c *Client) Host() string
- func (c *Client) IsSafeDeployed(ctx context.Context, out *SafeDeployedResponse) error
- func (c *Client) SubmitTransaction(ctx context.Context, req SubmitTransactionRequest, ...) error
- type Config
- type Credentials
- type NonceResponse
- type NonceType
- type SafeDeployedResponse
- type SignatureParams
- type SubmitTransactionRequest
- type SubmitTransactionResponse
- type Transaction
Constants ¶
const DefaultHost = "https://relayer-v2.polymarket.com"
DefaultHost is the production Polymarket Relayer API host.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type APIKey ¶
type APIKey struct {
// Key is the API key.
Key string `json:"apiKey"`
// Address is the owner address.
Address string `json:"address"`
// CreatedAt is the key creation timestamp.
CreatedAt pmtypes.Time `json:"createdAt"`
// UpdatedAt is the key update timestamp.
UpdatedAt pmtypes.Time `json:"updatedAt"`
}
APIKey describes a relayer API key.
type BuilderCredentials ¶
type BuilderCredentials struct {
// APIKey is the builder API key.
APIKey string
// Secret is the URL-safe base64 builder API secret.
Secret string
// Passphrase is the builder API passphrase.
Passphrase string
}
BuilderCredentials contains builder-key authentication material for relayer requests.
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client is a Polymarket Relayer API client.
func (*Client) GetAPIKeys ¶
GetAPIKeys returns all relayer API keys available to the authenticated caller.
func (*Client) GetRecentTransactions ¶
GetRecentTransactions returns recent transactions owned by the authenticated address.
func (*Client) GetRelayPayload ¶
func (c *Client) GetRelayPayload(ctx context.Context, out *NonceResponse, nonceType NonceType) error
GetRelayPayload writes the relayer address and nonce for out.Address into out.
func (*Client) GetRelayerNonce ¶
func (c *Client) GetRelayerNonce(ctx context.Context, out *NonceResponse, nonceType ...NonceType) error
GetRelayerNonce writes the relayer address and nonce for out.Address into out.
func (*Client) GetTransaction ¶
func (c *Client) GetTransaction(ctx context.Context, out *Transaction) error
GetTransaction writes a relayer transaction by out.TransactionID into out.
func (*Client) IsSafeDeployed ¶
func (c *Client) IsSafeDeployed(ctx context.Context, out *SafeDeployedResponse) error
IsSafeDeployed writes whether out.Address is deployed into out.
func (*Client) SubmitTransaction ¶
func (c *Client) SubmitTransaction(ctx context.Context, req SubmitTransactionRequest, out *SubmitTransactionResponse) error
SubmitTransaction submits a signed transaction to the relayer and writes the response into out.
type Config ¶
type Config struct {
// Host is the Relayer API host.
Host string
// HTTPClient is the client used for HTTP requests.
HTTPClient *http.Client
// UserAgent sets the User-Agent header.
UserAgent string
// Credentials configures Relayer API-key authentication.
Credentials *Credentials
// BuilderCredentials configures builder-key authentication.
BuilderCredentials *BuilderCredentials
}
Config configures a Relayer API client.
type Credentials ¶
type Credentials struct {
// APIKey is the relayer API key.
APIKey string
// Address is the owner address for APIKey.
Address string
}
Credentials contains Relayer API-key authentication headers.
type NonceResponse ¶
type NonceResponse struct {
// Nonce is the current relayer nonce.
Nonce pmtypes.String `json:"nonce"`
// Address is the associated relayer or user address when present.
Address string `json:"address,omitempty"`
}
NonceResponse is returned by nonce endpoints.
type SafeDeployedResponse ¶
type SafeDeployedResponse struct {
// Address is the Safe wallet address queried.
Address string `json:"address,omitempty"`
// Deployed is true when the Safe is deployed.
Deployed bool `json:"deployed"`
}
SafeDeployedResponse reports whether a Safe wallet is deployed.
type SignatureParams ¶
type SignatureParams struct {
// GasPrice is the Safe gas price parameter.
GasPrice string `json:"gasPrice"`
// Operation is the Safe operation parameter.
Operation string `json:"operation"`
// SafeTxGas is the Safe transaction gas parameter.
SafeTxGas string `json:"safeTxnGas"`
// BaseGas is the Safe base gas parameter.
BaseGas string `json:"baseGas"`
// GasToken is the token used for gas refunds.
GasToken string `json:"gasToken"`
// RefundReceiver is the address receiving gas refunds.
RefundReceiver string `json:"refundReceiver"`
}
SignatureParams contains Safe transaction signature parameters.
type SubmitTransactionRequest ¶
type SubmitTransactionRequest struct {
// From is the signer address.
From string `json:"from"`
// To is the target contract address.
To string `json:"to"`
// ProxyWallet is the user's Polymarket proxy wallet.
ProxyWallet string `json:"proxyWallet"`
// Data is 0x-prefixed encoded transaction calldata.
Data string `json:"data"`
// Nonce is the relayer transaction nonce.
Nonce string `json:"nonce"`
// Signature is the 0x-prefixed transaction signature.
Signature string `json:"signature"`
// SignatureParams are Safe transaction parameters.
SignatureParams SignatureParams `json:"signatureParams"`
// Type is the transaction type, typically SAFE or PROXY.
Type string `json:"type"`
// Metadata is optional caller-provided transaction metadata.
Metadata string `json:"metadata,omitempty"`
// Value is the native token value for the call when required.
Value string `json:"value,omitempty"`
}
SubmitTransactionRequest is the request body for POST /submit.
type SubmitTransactionResponse ¶
type SubmitTransactionResponse struct {
// TransactionID is the relayer transaction identifier.
TransactionID string `json:"transactionID"`
// State is the current relayer state.
State string `json:"state"`
}
SubmitTransactionResponse is returned immediately after a transaction is accepted.
type Transaction ¶
type Transaction struct {
// TransactionID is the relayer transaction identifier.
TransactionID string `json:"transactionID"`
// State is the current relayer state.
State string `json:"state"`
// TransactionHash is the on-chain hash after broadcast.
TransactionHash string `json:"transactionHash"`
// From is the signer address.
From string `json:"from"`
// To is the target contract address.
To string `json:"to"`
// ProxyWallet is the user's Polymarket proxy wallet.
ProxyWallet string `json:"proxyWallet"`
// Data is the 0x-prefixed calldata submitted to the relayer.
Data string `json:"data"`
// Nonce is the transaction nonce.
Nonce pmtypes.String `json:"nonce"`
// Value is the transaction value.
Value pmtypes.String `json:"value"`
// Signature is the 0x-prefixed transaction signature.
Signature string `json:"signature"`
// Type is the transaction type.
Type string `json:"type"`
// Owner is the transaction owner.
Owner string `json:"owner"`
// Metadata is the transaction metadata.
Metadata string `json:"metadata"`
// CreatedAt is the creation timestamp.
CreatedAt pmtypes.Time `json:"createdAt"`
// UpdatedAt is the last update timestamp.
UpdatedAt pmtypes.Time `json:"updatedAt"`
}
Transaction describes a relayer transaction.