Documentation
¶
Overview ¶
Sending Operations ¶
Use Client.ExecuteOperation to sign and send in one step:
result, err := client.Transact.ExecuteOperation(ctx, channelID, signer, operation, chainSelector)
fmt.Printf("Operation: %s, Status: %s\n", result.OperationId, result.Status)
Or send a pre-signed operation with Client.SendSignedOperation:
result, err := client.Transact.SendSignedOperation(ctx, channelID, operation, signature, chainSelector)
Signers ¶
The package supports multiple signer implementations:
// Local private key
import "github.com/smartcontractkit/crec-sdk/transact/signer/local"
signer, _ := local.NewSigner(privateKey)
// AWS KMS
import "github.com/smartcontractkit/crec-sdk/transact/signer/kms"
signer, _ := kms.NewSigner(ctx, kms.Options{KeyID: "...", Region: "us-east-1"})
// HashiCorp Vault
import "github.com/smartcontractkit/crec-sdk/transact/signer/vault"
signer, _ := vault.NewSigner(vault.Options{Address: "...", Token: "...", KeyName: "..."})
// Privy
import "github.com/smartcontractkit/crec-sdk/transact/signer/privy"
signer, _ := privy.NewSigner(privy.Options{AppID: "...", AppSecret: "...", WalletID: "..."})
Operation Management ¶
List and retrieve operations:
// List operations
ops, hasMore, err := client.Transact.ListOperations(ctx, ListOperationsInput{
ChannelID: channelID,
})
// Get a specific operation
op, err := client.Transact.GetOperation(ctx, channelID, operationID)
Operation Lifecycle ¶
Operations progress through these states:
- pending: Created, waiting to be sent
- sent: Submitted to the blockchain
- confirmed: Successfully executed on-chain
- failed: Execution failed
Error Handling ¶
All errors can be inspected with errors.Is:
if errors.Is(err, ErrChannelNotFound) {
// Handle missing channel
}
if errors.Is(err, ErrOperationNotFound) {
// Handle missing operation
}
if errors.Is(err, ErrSignOperation) {
// Handle signing failure
}
Index ¶
- Variables
- type Client
- func (c *Client) CreateOperation(ctx context.Context, input CreateOperationInput) (*uuid.UUID, error)
- func (c *Client) ExecuteOperation(ctx context.Context, channelID uuid.UUID, operationSigner signer.Signer, ...) (*apiClient.Operation, error)
- func (c *Client) ExecuteTransactions(ctx context.Context, channelID uuid.UUID, operationSigner signer.Signer, ...) (*apiClient.Operation, error)
- func (c *Client) GetOperation(ctx context.Context, channelID uuid.UUID, operationID uuid.UUID) (*apiClient.Operation, error)
- func (c *Client) HashOperation(op *types.Operation, chainSelector string) (common.Hash, error)
- func (c *Client) ListOperations(ctx context.Context, input ListOperationsInput) ([]apiClient.Operation, bool, error)
- func (c *Client) SendSignedOperation(ctx context.Context, channelID uuid.UUID, op *types.Operation, ...) (*apiClient.Operation, error)
- func (c *Client) SignOperation(ctx context.Context, op *types.Operation, signer signer.Signer, ...) (common.Hash, []byte, error)
- func (c *Client) SignOperationHash(ctx context.Context, opHash common.Hash, signer signer.Signer) ([]byte, error)
- type CreateOperationInput
- type ListOperationsInput
- type Options
- type TransactionRequest
Constants ¶
This section is empty.
Variables ¶
var ( // ErrOptionsRequired is returned when the options parameter is nil. ErrOptionsRequired = errors.New("options is required") // ErrCRECClientRequired is returned when the CREC client is nil in options. ErrCRECClientRequired = errors.New("CRECClient is required") // ErrChannelIDRequired is returned when the channel ID is nil. ErrChannelIDRequired = errors.New("channel_id is required") // ErrChainSelectorRequired is returned when the chain selector is empty or zero. ErrChainSelectorRequired = errors.New("chain_selector is required") // ErrAddressRequired is returned when the address is empty. ErrAddressRequired = errors.New("address is required") // ErrWalletOperationIDRequired is returned when the wallet operation ID is empty. ErrWalletOperationIDRequired = errors.New("wallet_operation_id is required") // ErrAtLeastOneTransactionRequired is returned when the transactions list is empty. ErrAtLeastOneTransactionRequired = errors.New("at least one transaction is required") // ErrSignatureRequired is returned when the signature is empty. ErrSignatureRequired = errors.New("signature is required") // ErrChannelNotFound is returned when the channel does not exist (404 response). ErrChannelNotFound = errors.New("channel not found") // ErrOperationNotFound is returned when the operation does not exist (404 response). ErrOperationNotFound = errors.New("operation not found") // ErrCreateOperation is returned when creating an operation fails. ErrCreateOperation = errors.New("failed to create operation") // ErrGetOperation is returned when fetching an operation fails. ErrGetOperation = errors.New("failed to get operation") // ErrListOperations is returned when listing operations fails. ErrListOperations = errors.New("failed to list operations") // ErrSendOperation is returned when sending an operation fails. ErrSendOperation = errors.New("failed to send operation") // ErrInvalidDeadline is returned when the operation deadline is negative or overflows int64. ErrInvalidDeadline = errors.New("invalid deadline: must be a non-negative value that fits in int64") // ErrUnexpectedStatusCode is returned when the API returns an unexpected HTTP status code. ErrUnexpectedStatusCode = errors.New("unexpected status code") // ErrNilResponseBody is returned when the API response body is nil. ErrNilResponseBody = errors.New("unexpected nil response body") )
Functions ¶
This section is empty.
Types ¶
type Client ¶
type Client struct {
// EIP712Handler provides hashing and signing operations for CREC operations.
EIP712Handler *eip712.Handler
// contains filtered or unexported fields
}
Client provides operations for creating, signing, and sending CREC operations. It embeds an EIP712Handler for hashing and signing operations.
func NewClient ¶
NewClient creates a new CREC transact client with the provided CREC client and options. Returns a pointer to the Client and an error if any issues occur during initialization.
- opts: Options for configuring the CREC transact client, see Options for details.
func (*Client) CreateOperation ¶
func (c *Client) CreateOperation(ctx context.Context, input CreateOperationInput) (*uuid.UUID, error)
CreateOperation creates a new operation in the specified channel. The operation will contain one or more transactions to be executed atomically.
Parameters:
- ctx: The context for the request.
- input: The operation creation parameters.
Returns the operation ID or an error if the operation fails.
func (*Client) ExecuteOperation ¶
func (c *Client) ExecuteOperation( ctx context.Context, channelID uuid.UUID, operationSigner signer.Signer, operation *types.Operation, chainSelector string, ) (*apiClient.Operation, error)
ExecuteOperation signs and sends an operation to the CREC system.
- ctx: The context for the request.
- channelID: The UUID of the channel to send the operation to.
- operationSigner: The signer to use for signing the operation.
- operation: The operation to execute.
- chainSelector: The chain selector of the blockchain network in which the operation is being executed.
func (*Client) ExecuteTransactions ¶
func (c *Client) ExecuteTransactions( ctx context.Context, channelID uuid.UUID, operationSigner signer.Signer, executorAccount common.Address, txs []types.Transaction, deadline *big.Int, chainSelector string, ) (*apiClient.Operation, error)
ExecuteTransactions executes a list of transactions using the provided signer and executor account. It bundles the transactions into an operation, signs it, and sends it to the CREC system.
- ctx: The context for the request.
- channelID: The UUID of the channel to send the operation to.
- operationSigner: The signer to use for signing the operation.
- executorAccount: The account to use for executing the operation.
- txs: The transactions to execute.
- deadline: The deadline timestamp for the operation (0 means no expiration).
- chainSelector: The chain selector of the blockchain network in which the transactions are being executed.
func (*Client) GetOperation ¶
func (c *Client) GetOperation(ctx context.Context, channelID uuid.UUID, operationID uuid.UUID) (*apiClient.Operation, error)
GetOperation retrieves a specific operation by its ID within a channel.
Parameters:
- ctx: The context for the request.
- channelID: The UUID of the channel containing the operation.
- operationID: The UUID of the operation to retrieve.
Returns the operation or an error if the operation fails or is not found.
func (*Client) HashOperation ¶
HashOperation computes the EIP-712 digest of the given operation. This method delegates to the embedded EIP712Handler.
- op: The operation to hash.
- chainSelector: chainSelector of the blockchain network in which the operation is being executed.
Fetches chainID corresponding to the chain selector from smartcontractkit/chain-selectors package.
func (*Client) ListOperations ¶
func (c *Client) ListOperations(ctx context.Context, input ListOperationsInput) ([]apiClient.Operation, bool, error)
ListOperations retrieves a list of operations for a channel.
Parameters:
- ctx: The context for the request.
- input: The list parameters including filters and pagination.
Returns a list of operations and a boolean indicating if there are more results.
func (*Client) SendSignedOperation ¶
func (c *Client) SendSignedOperation( ctx context.Context, channelID uuid.UUID, op *types.Operation, signature []byte, chainSelector string, ) (*apiClient.Operation, error)
SendSignedOperation sends a signed operation to the CREC system via the specified channel.
- ctx: The context for the request.
- channelID: The UUID of the channel to send the operation to.
- op: The operation to send, which must be signed.
- signature: The signature of the operation, to be verified by the onchain smart account.
- chainSelector: The chain selector of the blockchain network in which the operation is being executed.
func (*Client) SignOperation ¶
func (c *Client) SignOperation( ctx context.Context, op *types.Operation, signer signer.Signer, chainSelector string, ) (common.Hash, []byte, error)
SignOperation signs the given operation using the provided signer, returning the operation hash and the signature over the hash. This method delegates to the embedded EIP712Handler.
- ctx: The context for the request.
- op: The operation to sign.
- signer: The signer to use for signing the operation. See signer.Signer for details.
- chainSelector: chainSelector of the blockchain network in which the operation is being executed.
Fetches chainID corresponding to the chain selector from smartcontractkit/chain-selectors package.
func (*Client) SignOperationHash ¶
func (c *Client) SignOperationHash( ctx context.Context, opHash common.Hash, signer signer.Signer, ) ([]byte, error)
SignOperationHash signs the given operation hash using the provided signer, returning the signature. This method delegates to the embedded EIP712Handler.
- ctx: The context for the request.
- opHash: The operation hash to sign.
- signer: The signer to use for signing the operation. See signer.Signer for details.
type CreateOperationInput ¶
type CreateOperationInput struct {
ChannelID uuid.UUID
ChainSelector string
Address string
WalletOperationID string
Deadline int64
Transactions []TransactionRequest
Signature string
}
CreateOperationInput defines the input parameters for creating a new operation.
- ChannelID: The UUID of the channel where the operation will be created.
- ChainSelector: The chain selector to identify the chain where the operation will be executed.
- Address: The account address performing the operation.
- WalletOperationID: Unique identifier for the wallet operation.
- Deadline: The deadline timestamp for the operation (0 means no expiration).
- Transactions: List of transactions to execute (at least one required).
- Signature: EIP-712 signature of the operation.
type ListOperationsInput ¶
type ListOperationsInput struct {
ChannelID uuid.UUID
Status *[]apiClient.OperationStatus
ChainSelector *string
Address *string
WalletID *uuid.UUID
Limit *int
Offset *int64
}
ListOperationsInput defines the input parameters for listing operations.
- ChannelID: The UUID of the channel to list operations from.
- Status: Optional filter for operation status.
- ChainSelector: Optional filter for chain selector.
- Address: Optional filter for account address.
- WalletID: Optional filter for wallet ID.
- Limit: Maximum number of operations to return (1-100, default: 20).
- Offset: Number of operations to skip for pagination (default: 0).
type Options ¶
type Options struct {
Logger *slog.Logger
CRECClient *apiClient.ClientWithResponses
}
Options defines the options for creating a new CREC transact client used to send operations to the CREC system. It includes a logger for logging messages and a chain ID for the blockchain network.
- Logger: Optional logger instance.
- CRECClient: A client instance for interacting with the CREC system (required).
type TransactionRequest ¶
TransactionRequest represents a single transaction in an operation.
- To: The target contract address.
- Value: The amount of native currency to send (as string).
- Data: The encoded calldata for the transaction.
Directories
¶
| Path | Synopsis |
|---|---|
|
Package eip712 provides functionality for computing EIP-712 hashes and signatures for CREC operations without requiring network connectivity or API client dependencies.
|
Package eip712 provides functionality for computing EIP-712 hashes and signatures for CREC operations without requiring network connectivity or API client dependencies. |
|
Package signer provides signing interfaces for the CREC SDK.
|
Package signer provides signing interfaces for the CREC SDK. |
|
fireblocks
Package fireblocks provides a signer.Signer implementation using Fireblocks' custody infrastructure.
|
Package fireblocks provides a signer.Signer implementation using Fireblocks' custody infrastructure. |
|
kms
Package kms provides a signer using AWS Key Management Service.
|
Package kms provides a signer using AWS Key Management Service. |
|
local
Package local provides a signer using local ECDSA private keys.
|
Package local provides a signer using local ECDSA private keys. |
|
privy
Package privy provides a signer using Privy's wallet-as-a-service platform.
|
Package privy provides a signer using Privy's wallet-as-a-service platform. |
|
vault
Package vault provides a signer using HashiCorp Vault Transit secrets engine.
|
Package vault provides a signer using HashiCorp Vault Transit secrets engine. |
|
Package types provides data structures for CREC transact operations.
|
Package types provides data structures for CREC transact operations. |