transact

package
v0.6.1 Latest Latest
Warning

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

Go to latest
Published: Mar 6, 2026 License: MIT Imports: 12 Imported by: 0

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

Constants

This section is empty.

Variables

View Source
var (
	// Client initialization errors
	ErrOptionsRequired    = errors.New("options is required")
	ErrCRECClientRequired = errors.New("CRECClient is required")

	// Validation errors
	ErrChannelIDRequired             = errors.New("channel_id is required")
	ErrChainSelectorRequired         = errors.New("chain_selector is required")
	ErrAddressRequired               = errors.New("address is required")
	ErrWalletOperationIDRequired     = errors.New("wallet_operation_id is required")
	ErrAtLeastOneTransactionRequired = errors.New("at least one transaction is required")
	ErrSignatureRequired             = errors.New("signature is required")

	// Not found errors
	ErrChannelNotFound   = errors.New("channel not found")
	ErrOperationNotFound = errors.New("operation not found")

	// API operation errors
	ErrCreateOperation = errors.New("failed to create operation")
	ErrGetOperation    = errors.New("failed to get operation")
	ErrListOperations  = errors.New("failed to list operations")
	ErrSendOperation   = errors.New("failed to send operation")

	// Response errors
	ErrUnexpectedStatusCode = errors.New("unexpected status code")
	ErrNilResponseBody      = errors.New("unexpected nil response body")
)

Sentinel errors

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
}

func NewClient

func NewClient(opts *Options) (*Client, error)

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,
	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.
  • 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

func (c *Client) HashOperation(op *types.Operation, chainSelector string) (common.Hash, error)

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
	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.
  • 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

type TransactionRequest struct {
	To    string
	Value string
	Data  string
}

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.

Jump to

Keyboard shortcuts

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