Documentation
¶
Index ¶
- Variables
- type AccountDeploymentData
- type BuildTransactionRequest
- type BuildTransactionResponse
- type CairoVersion
- type Call
- type ExecutableUserInvoke
- type ExecutableUserTransaction
- type ExecuteTransactionRequest
- type ExecuteTransactionResponse
- type FeeEstimate
- type FeeMode
- type FeeModeType
- type Paymaster
- func (p *Paymaster) BuildTransaction(ctx context.Context, request *BuildTransactionRequest) (BuildTransactionResponse, error)
- func (p *Paymaster) ExecuteTransaction(ctx context.Context, request *ExecuteTransactionRequest) (ExecuteTransactionResponse, error)
- func (p *Paymaster) GetSupportedTokens(ctx context.Context) ([]TokenData, error)
- func (p *Paymaster) IsAvailable(ctx context.Context) (bool, error)
- func (p *Paymaster) TrackingIDToLatestHash(ctx context.Context, trackingID *felt.Felt) (TrackingIDResponse, error)
- type RPCError
- type StringErrData
- type TimeBounds
- type TipPriority
- type TipPriorityEnum
- type TokenData
- type TrackingIDResponse
- type TxnExecutionErrData
- type TxnStatus
- type UserInvoke
- type UserParamVersion
- type UserParameters
- type UserTransaction
- type UserTxnType
Constants ¶
This section is empty.
Variables ¶
var ( ErrInvalidAddress = &RPCError{ Code: 150, Message: "An error occurred (INVALID_ADDRESS)", } ErrTokenNotSupported = &RPCError{ Code: 151, Message: "An error occurred (TOKEN_NOT_SUPPORTED)", } ErrInvalidSignature = &RPCError{ Code: 153, Message: "An error occurred (INVALID_SIGNATURE)", } ErrMaxAmountTooLow = &RPCError{ Code: 154, Message: "An error occurred (MAX_AMOUNT_TOO_LOW)", } ErrClassHashNotSupported = &RPCError{ Code: 155, Message: "An error occurred (CLASS_HASH_NOT_SUPPORTED)", } ErrTransactionExecutionError = &RPCError{ Code: 156, Message: "An error occurred (TRANSACTION_EXECUTION_ERROR)", Data: &TxnExecutionErrData{}, } ErrInvalidTimeBounds = &RPCError{ Code: 157, Message: "An error occurred (INVALID_TIME_BOUNDS)", } ErrInvalidDeploymentData = &RPCError{ Code: 158, Message: "An error occurred (INVALID_DEPLOYMENT_DATA)", } ErrInvalidClassHash = &RPCError{ Code: 159, Message: "An error occurred (INVALID_ADDRESS)", } ErrInvalidID = &RPCError{ Code: 160, Message: "An error occurred (INVALID_ID)", } ErrUnknownError = &RPCError{ Code: 163, Message: "An error occurred (UNKNOWN_ERROR)", Data: StringErrData(""), } )
Paymaster-specific errors based on SNIP-29 specification
Functions ¶
This section is empty.
Types ¶
type AccountDeploymentData ¶
type AccountDeploymentData struct {
// The expected address to be deployed, used to double check
Address *felt.Felt `json:"address"`
// The hash of the deployed contract's class
ClassHash *felt.Felt `json:"class_hash"`
// The salt used for the contract address calculation
Salt *felt.Felt `json:"salt"`
// The parameters passed to the constructor
Calldata []*felt.Felt `json:"calldata"`
// Optional array of felts to be added to the signature
SignatureData []*felt.Felt `json:"sigdata,omitempty"`
// The Cairo version of the account contract. Cairo 0 is not supported.
Version CairoVersion `json:"version"`
}
Data required to deploy an account at an address.
type BuildTransactionRequest ¶
type BuildTransactionRequest struct {
// The transaction to be executed by the paymaster
Transaction UserTransaction `json:"transaction"`
// Execution parameters to be used when executing the transaction
Parameters UserParameters `json:"parameters"`
}
BuildTransactionRequest is the request to build a transaction for the paymaster (transaction + parameters).
type BuildTransactionResponse ¶
type BuildTransactionResponse struct {
// The type of the transaction
Type UserTxnType `json:"type"`
// The deployment data for `deploy` and `deploy_and_invoke` transaction types.
// It's `nil` for `invoke` transaction types.
Deployment *AccountDeploymentData `json:"deployment,omitempty"`
// Execution parameters to be used when executing the transaction
Parameters *UserParameters `json:"parameters"`
// The typed data for for `invoke` and `deploy_and_invoke` transaction types.
// It's `nil` for `deploy` transaction types.
TypedData *typeddata.TypedData `json:"typed_data,omitempty"`
// The fee estimation for the transaction
Fee *FeeEstimate `json:"fee"`
}
BuildTransactionResponse is the response from the `paymaster_buildTransaction` method. It contains the transaction data required for the paymaster to execute, along with an estimation of the fee.
type CairoVersion ¶
type CairoVersion int
An enum representing the Cairo version of the account contract to be deployed. Cairo 0 is not supported.
const ( // Represents the Cairo 1 version Cairo1 CairoVersion = 1 )
type Call ¶
type Call struct {
// The address of the contract to invoke
To *felt.Felt `json:"to"`
// The selector of the function to invoke
Selector *felt.Felt `json:"selector"`
// The parameters passed to the function
Calldata []*felt.Felt `json:"calldata"`
}
The object that defines an invocation of a function in a contract
type ExecutableUserInvoke ¶
type ExecutableUserInvoke struct {
// The address of the user account
UserAddress *felt.Felt `json:"user_address"`
// Typed data returned by the endpoint paymaster_buildTransaction
TypedData *typeddata.TypedData `json:"typed_data"`
// Signature of the associated Typed Data
Signature []*felt.Felt `json:"signature"`
}
ExecutableUserInvoke is a signed typed data of an invoke transaction ready to be executed by the paymaster service.
type ExecutableUserTransaction ¶
type ExecutableUserTransaction struct {
// The type of the transaction to be executed by the paymaster
Type UserTxnType `json:"type"`
// The deployment data for the transaction, used for `deploy` and
// `deploy_and_invoke` transaction types.
// Should be `nil` for `invoke` transaction types.
Deployment *AccountDeploymentData `json:"deployment,omitempty"`
// Invoke data signed by the user to be executed by the paymaster service, used for`invoke` and
// `deploy_and_invoke` transaction types.
// Should be `nil` for `deploy` transaction types.
Invoke *ExecutableUserInvoke `json:"invoke,omitempty"`
}
ExecutableUserTransaction is a user transaction ready for execution (deploy, invoke, or both).
type ExecuteTransactionRequest ¶
type ExecuteTransactionRequest struct {
// Typed data build by calling paymaster_buildTransaction signed by the
// user to be executed by the paymaster service
Transaction ExecutableUserTransaction `json:"transaction"`
// Execution parameters to be used when executing the transaction
Parameters UserParameters `json:"parameters"`
}
ExecuteTransactionRequest is the request to execute a transaction via the paymaster (transaction + parameters).
type ExecuteTransactionResponse ¶
type ExecuteTransactionResponse struct {
// A unique identifier used to track an execution request of a user. Its purpose is to track
// possibly different transactions sent by the paymaster and which are associated with a same
// user request. Such cases can happen during congestion, where a fee or tip bump may be needed
// in order for a transaction to enter a block
TrackingID *felt.Felt `json:"tracking_id"`
TransactionHash *felt.Felt `json:"transaction_hash"`
}
ExecuteTransactionResponse is the response from executing a transaction (tracking ID and transaction hash).
type FeeEstimate ¶
type FeeEstimate struct {
GasTokenPriceInStrk *felt.Felt `json:"gas_token_price_in_strk"`
EstimatedFeeInStrk *felt.Felt `json:"estimated_fee_in_strk"`
EstimatedFeeInGasToken *felt.Felt `json:"estimated_fee_in_gas_token"`
SuggestedMaxFeeInStrk *felt.Felt `json:"suggested_max_fee_in_strk"`
SuggestedMaxFeeInGasToken *felt.Felt `json:"suggested_max_fee_in_gas_token"`
}
FeeEstimate is a detailed fee estimation (in STRK and gas token, with suggested max).
type FeeMode ¶
type FeeMode struct {
// The fee mode type to use for the transaction
Mode FeeModeType `json:"mode"`
// The gas token to use for the transaction. Should be omitted for `sponsored` fee mode
GasToken *felt.Felt `json:"gas_token,omitempty"`
// Relative tip priority or a custom tip value. If not provided/is `nil`,
// the paymaster will use the `normal` tip priority by default.
Tip *TipPriority `json:"tip,omitempty"`
}
Specify how the transaction should be paid. Either by the user specifying a gas token or through sponsorship
type FeeModeType ¶
type FeeModeType int
An enum representing the fee mode to use for the transaction
const ( // Specify that the transaction should be sponsored. This argument does not // guaranteed sponsorship and will depend on the paymaster provider. // Represents the "sponsored" string value. FeeModeSponsored FeeModeType = iota + 1 // Default fee mode where the transaction is paid by the user in the given gas token. // Represents the "default" string value. FeeModeDefault )
func (FeeModeType) MarshalJSON ¶
func (fee FeeModeType) MarshalJSON() ([]byte, error)
MarshalJSON marshals the FeeModeType to JSON.
func (FeeModeType) String ¶
func (fee FeeModeType) String() string
String returns the string representation of the FeeModeType.
func (*FeeModeType) UnmarshalJSON ¶
func (fee *FeeModeType) UnmarshalJSON(b []byte) error
UnmarshalJSON unmarshals the JSON data into a FeeModeType.
type Paymaster ¶
type Paymaster struct {
// contains filtered or unexported fields
}
Paymaster is a client for interacting with a paymaster service via the SNIP-29 API. It provides methods to build and execute transactions, check service status, and track transaction status.
func New ¶
Creates a new paymaster client for the given service URL. Additional options can be passed to the client to configure the connection.
Parameters:
- url: The URL of the paymaster service
- options: Additional options to configure the client
Returns:
- *Paymaster: A new paymaster client instance
- error: An error if the client creation fails
func (*Paymaster) BuildTransaction ¶
func (p *Paymaster) BuildTransaction( ctx context.Context, request *BuildTransactionRequest, ) (BuildTransactionResponse, error)
BuildTransaction receives the transaction the user wants to execute. Returns the typed data along with the estimated gas cost and the maximum gas cost suggested to ensure execution
Parameters:
- ctx: The context.Context object for controlling the function call
- request: The BuildTransactionRequest containing the transaction and parameters
Returns:
- *BuildTransactionResponse: The response containing typed data and fee estimate
- error: An error if the request fails
func (*Paymaster) ExecuteTransaction ¶
func (p *Paymaster) ExecuteTransaction( ctx context.Context, request *ExecuteTransactionRequest, ) (ExecuteTransactionResponse, error)
ExecuteTransaction sends the signed typed data to the paymaster service for execution
Parameters:
- ctx: The context.Context object for controlling the function call
- request: The signed typed data of the transaction to be executed by the paymaster service
Returns:
- *ExecuteTransactionResponse: The hash of the transaction broadcasted by the paymaster and the tracking ID corresponding to the user `execute` request
- error: An error if any error occurs
func (*Paymaster) GetSupportedTokens ¶
Get a list of the tokens that the paymaster supports, together with their prices in STRK
Parameters:
- ctx: The context.Context object for controlling the function call
Returns:
- []TokenData: An array of token data
- error: An error if any
func (*Paymaster) IsAvailable ¶
IsAvailable returns the status of the paymaster service. If the paymaster service is correctly functioning, return true. Else, return false
Parameters:
- ctx: The context.Context object for controlling the function call
Returns:
- bool: True if the paymaster service is correctly functioning, false otherwise
- error: An error if any
func (*Paymaster) TrackingIDToLatestHash ¶
func (p *Paymaster) TrackingIDToLatestHash( ctx context.Context, trackingID *felt.Felt, ) (TrackingIDResponse, error)
TrackingIDToLatestHash gets the latest transaction hash and status for a given tracking ID. Returns a TrackingIdResponse.
Parameters:
- ctx: The context.Context object for controlling the function call
- trackingID: A unique identifier used to track an execution request of a user. This identitifier is returned by the paymaster after a successful call to `execute`. Its purpose is to track the possibly different transaction hashes in the mempool which are associated with a same user request.
Returns:
- *TrackingIDResponse: The hash of the latest transaction broadcasted by the paymaster corresponding to the requested ID and the status of the ID.
- error: An error if any
type StringErrData ¶
type StringErrData = rpcerr.StringErrData
type TimeBounds ¶
type TimeBounds struct {
// A lower bound after which an outside call is valid in UNIX timestamp format
ExecuteAfter string `json:"execute_after"`
// An upper bound before which an outside call is valid in UNIX timestamp format
ExecuteBefore string `json:"execute_before"`
}
Object containing timestamps corresponding to `Execute After` and `Execute Before`
type TipPriority ¶
type TipPriority struct {
// The relative tip priority
Priority TipPriorityEnum `json:"-"`
// A custom tip value
Custom *uint64 `json:"custom,omitempty"`
}
Relative tip priority or a custom tip value.
The user must specify either the priority or the custom tip value. If both fields are omitted (or TipPriority is `nil`), the paymaster will use the `normal` tip priority by default.
func (*TipPriority) MarshalJSON ¶
func (t *TipPriority) MarshalJSON() ([]byte, error)
MarshalJSON marshals the TipPriority to JSON.
func (*TipPriority) UnmarshalJSON ¶
func (t *TipPriority) UnmarshalJSON(b []byte) error
UnmarshalJSON unmarshals the JSON data into a TipPriority.
type TipPriorityEnum ¶
type TipPriorityEnum int
An enum representing the desired tip priority for the paymster transaction.
const ( // Slow tip priority (represents the "slow" string value) TipPrioritySlow TipPriorityEnum = iota + 1 // Normal tip priority (represents the "normal" string value) TipPriorityNormal // Fast tip priority (represents the "fast" string value) TipPriorityFast )
func (TipPriorityEnum) MarshalJSON ¶
func (tip TipPriorityEnum) MarshalJSON() ([]byte, error)
MarshalJSON marshals the TipPriorityEnum to JSON.
func (TipPriorityEnum) String ¶
func (tip TipPriorityEnum) String() string
String returns the string representation of the TipPriorityEnum.
func (*TipPriorityEnum) UnmarshalJSON ¶
func (tip *TipPriorityEnum) UnmarshalJSON(b []byte) error
UnmarshalJSON unmarshals the JSON data into a TipPriorityEnum.
type TokenData ¶
type TokenData struct {
// Token contract address
TokenAddress *felt.Felt `json:"token_address"`
// The number of decimals of the token
Decimals uint8 `json:"decimals"`
// Price in STRK (in FRI units)
PriceInStrk string `json:"price_in_strk"` // u256 as a hex string
}
Object containing data about the token: contract address, number of decimals and current price in STRK
type TrackingIDResponse ¶
type TrackingIDResponse struct {
// The hash of the most recent tx sent by the paymaster and corresponding to the ID
TransactionHash *felt.Felt `json:"transaction_hash"`
// The status of the transaction associated with the ID
Status TxnStatus `json:"status"`
}
TrackingIDResponse is the response for the `paymaster_trackingIdToLatestHash` method.
type TxnExecutionErrData ¶
type TxnExecutionErrData struct {
ExecutionError string `json:"execution_error"`
}
TxnExecutionErrData represents the structured data for TRANSACTION_EXECUTION_ERROR
func (TxnExecutionErrData) ErrorMessage ¶
func (t TxnExecutionErrData) ErrorMessage() string
ErrorMessage implements the RPCData interface
type TxnStatus ¶
type TxnStatus int
An enum representing the status of the transaction associated with a tracking ID
const ( // Indicates that the latest transaction associated with the ID is not yet // included in a block but is still being handled and monitored by the paymaster. // Represents the "active" string value. TxnStatusActive TxnStatus = iota + 1 // Indicates that a transaction associated with the ID has been accepted on L2. // Represents the "accepted" string value. TxnStatusAccepted // Indicates that no transaction associated with the ID managed to enter a block // and the request has been dropped by the paymaster. // Represents the "dropped" string value. TxnStatusDropped )
func (TxnStatus) MarshalJSON ¶
MarshalJSON marshals the TxnStatus to JSON.
func (*TxnStatus) UnmarshalJSON ¶
UnmarshalJSON unmarshals the JSON data into a TxnStatus.
type UserInvoke ¶
type UserInvoke struct {
// The address of the user account
UserAddress *felt.Felt `json:"user_address"`
// The sequence of calls that the user wishes to perform
Calls []Call `json:"calls"`
}
Calls to be executed by the paymaster and the user account address that will be called
type UserParamVersion ¶
type UserParamVersion int
An enum representing the version of the execution parameters
const ( // Represents the v1 of the execution parameters ("0x1") UserParamV1 UserParamVersion = iota + 1 )
func (UserParamVersion) MarshalJSON ¶
func (u UserParamVersion) MarshalJSON() ([]byte, error)
MarshalJSON marshals the UserParamVersion to JSON.
func (UserParamVersion) String ¶
func (u UserParamVersion) String() string
String returns the string representation of the UserTxnType.
func (*UserParamVersion) UnmarshalJSON ¶
func (u *UserParamVersion) UnmarshalJSON(b []byte) error
UnmarshalJSON unmarshals the JSON data into a UserParamVersion.
type UserParameters ¶
type UserParameters struct {
// Version of the execution parameters which is not tied to the 'execute from outside' version.
Version UserParamVersion `json:"version"`
// Fee mode to use for the execution
FeeMode FeeMode `json:"fee_mode"`
// Optional. Time constraint on the execution
TimeBounds *TimeBounds `json:"time_bounds"`
}
Execution parameters to be used when executing the transaction through the paymaster
type UserTransaction ¶
type UserTransaction struct {
// The type of the transaction to be executed by the paymaster
Type UserTxnType `json:"type"`
// The deployment data for the transaction, used for `deploy` and
// `deploy_and_invoke` transaction types.
// Should be `nil` for `invoke` transaction types.
Deployment *AccountDeploymentData `json:"deployment,omitempty"`
// The invoke data for the transaction, used for `invoke` and
// `deploy_and_invoke` transaction types.
// Should be `nil` for `deploy` transaction types.
Invoke *UserInvoke `json:"invoke,omitempty"`
}
UserTransaction represents a user transaction (deploy, invoke, or deploy_and_invoke).
type UserTxnType ¶
type UserTxnType int
An enum representing the type of the transaction to be executed by the paymaster
const ( // Represents a deploy transaction ("deploy" tag) UserTxnDeploy UserTxnType = iota + 1 // Represents an invoke transaction ("invoke" tag) UserTxnInvoke // Represents a deploy and invoke transaction ("deploy_and_invoke" tag) UserTxnDeployAndInvoke )
func (UserTxnType) MarshalJSON ¶
func (u UserTxnType) MarshalJSON() ([]byte, error)
MarshalJSON marshals the UserTxnType to JSON.
func (UserTxnType) String ¶
func (u UserTxnType) String() string
String returns the string representation of the UserTxnType.
func (*UserTxnType) UnmarshalJSON ¶
func (u *UserTxnType) UnmarshalJSON(b []byte) error
UnmarshalJSON unmarshals the JSON data into a UserTxnType.