SDK Configuration

This page enumerates every constructor option exposed by the root crec SDK package. All options follow the functional-options pattern.

NewClient

import crec "github.com/smartcontractkit/crec-sdk"

func NewClient(baseURL, apiKey string, opts ...crec.Option) (*crec.Client, error)
ParameterRequiredNotes
baseURLyesEnvironment-specific base URL (e.g. https://cre-connect.api.chain.link/v1). Returns ErrBaseURLRequired if empty.
apiKeyyesOrganisation API key. Sent internally as Authorization: Apikey <key>. Returns ErrAPIKeyRequired if empty.
optsnoZero or more of the options below.

NewClient validates the event-verification config (ErrInvalidEventVerificationConfig) and constructs every sub-client (Channels, Events, Transact, Wallets, Watchers, Queries).

Example

client, err := crec.NewClient(
    os.Getenv("CREC_BASE_URL"),
    os.Getenv("CREC_API_KEY"),
    crec.WithLogger(slog.Default()),
    crec.WithOrgID(orgID),
)
if err != nil { return err }

Defaults

DefaultConstant / valueNotes
HTTP clienthttp.DefaultClientOverride with WithHTTPClient.
Loggerslog.Default()Override with WithLogger.
Min required signaturescrec.DefaultMinRequiredSignatures (= 4)F+1 where F = 3 (production DON Byzantine fault tolerance).
Valid signerscrec.DefaultValidSigners10 production DON node addresses (Zone A).
Event verificationenabledDisable with WithoutEventVerification() (test only).
CRE tenant IDevents.CreMainlineTenantID (= "1")Override with WithCRETenantID.

Options

WithHTTPClient(c *http.Client)

Override the default HTTP client. Use this to configure timeouts, proxies, or instrumentation.

crec.WithHTTPClient(&http.Client{ Timeout: 10 * time.Second })

WithLogger(l *slog.Logger)

Inject a custom slog.Logger. Defaults to slog.Default().

crec.WithLogger(slog.New(slog.NewJSONHandler(os.Stdout, nil)))

WithDONConfig(creTenantID string, minRequiredSignatures int, validSigners []string)

Configure event verification for your organisation's DON as one atomic unit: the CRE tenant ID (used for workflow-owner derivation), the signature threshold, and the signer set. These values are provided at onboarding; they are not SDK constants.

crec.WithDONConfig("3", 2, []string{
    "0x4d6cfd44f94408a39fb1af94a53c107a730ba161",
    // … your DON's signer list …
})

The unit must be complete: NewClient returns crec.ErrIncompleteDONConfig if the tenant ID is empty, the signer list is empty, or the threshold is not positive. If you combine WithDONConfig with the granular options below, the last applied option wins per field; once WithDONConfig is used, the completeness requirement applies regardless of option order.

WithEventVerification(min int, signers []string)

Deprecated: use WithDONConfig instead, which configures the CRE tenant ID, signature threshold, and signer set as one unit.

Override both the minimum required signatures and the set of valid signer addresses used by events.Client.Verify.

crec.WithEventVerification(4, []string{
    "0xff9b062fccb2f042311343048b9518068370f837",
    // …
})

WithoutEventVerification()

Skip the default signer-set backfill: the client ends up with no signers, and verification calls fail with events.ErrVerificationNotConfigured. This does not override explicitly configured signers: those set via WithEventVerification or WithDONConfig still apply.

crec.WithoutEventVerification()

WithOrgID(orgID string)

Set the default organisation ID for events.Client.Verify and events.Client.VerifyOperationStatus. With this option, you can call those methods without passing orgID explicitly. For multi-org applications, omit this option and use VerifyWithOrgID / VerifyOperationStatusWithOrgID.

WithWorkflowOwner(owner string)

Set the default workflow-owner address for verification. Use VerifyWithWorkflowOwner / VerifyOperationStatusWithWorkflowOwner for per-call overrides.

WithCRETenantID(tenant string)

Deprecated: use WithDONConfig instead, which sets the CRE tenant ID together with the threshold and signer set.

Override the CRE tenant ID used for workflow-owner address derivation. Defaults to events.CreMainlineTenantID ("1"). Use a different tenant ID when targeting a non-mainline CRE environment.

WithWatcherPolling(pollInterval, eventualConsistencyWindow time.Duration)

Tune the watchers client's polling behaviour:

  • pollInterval: wait between polls when waiting for a watcher state change.
  • eventualConsistencyWindow: how long to tolerate 404 responses immediately after creating a watcher.
crec.WithWatcherPolling(2*time.Second, 30*time.Second)

Constants exposed by crec

const DefaultMinRequiredSignatures = 4

DefaultMinRequiredSignatures = F + 1 where F = 3 (production DON Byzantine fault tolerance). The DON only transmits once at least F+1 signatures are gathered, so verification will always succeed at this default for production events.

DefaultValidSigners is the production DON node set on Ethereum Mainnet (Zone A), exported as a []string of 10 addresses. These keys rarely change; when they do, update the SDK to pick up the new set.

Node OperatorPublic Key
Chainlayer0xff9b062fccb2f042311343048b9518068370f837
CLP0xe55fcaf921e76c6bbcf9415bba12b1236f07b0c3
Dextrac0x4d6cfd44f94408a39fb1af94a53c107a730ba161
Fiews0xde5cd1dd4300a0b4854f8223add60d20e1dfe21b
Inotel0xf3baa9a99b5ad64f50779f449bac83baac8bfdb6
LinkForest0xd7f22fb5382ff477d2ff5c702cab0ef8abf18233
LinkPool0xcdf20f8ffd41b02c680988b20e68735cc8c1ca17
LinkRiver0x4d7d71c7e584cfa1f5c06275e5d283b9d3176924
PierTwo0xedf4bc027a750d1a88b8ca3ec5e8a5506f6019be
SimplyVC0x4f99b550623e77b807df7cbed9c79d55e1163b48

Errors

ErrorReturned by
crec.ErrBaseURLRequiredNewClient / NewAPIClient when baseURL == "".
crec.ErrAPIKeyRequiredNewClient / NewAPIClient when apiKey == "".
crec.ErrInvalidEventVerificationConfigNewClient when validSigners is set but minRequiredSignatures <= 0.
crec.ErrIncompleteDONConfigNewClient when WithDONConfig was used but the DON unit is incomplete: empty tenant ID, empty signer list, or non-positive threshold.

Sub-client construction

If you only need one sub-client (e.g. just channels), construct an APIClient and pass it explicitly:

api, err := crec.NewAPIClient(baseURL, apiKey)
if err != nil { return err }

channelsClient, err := channels.NewClient(&channels.Options{ APIClient: api })

This pattern is useful in services that import the SDK as a thin transport layer.

See also

Get the latest Chainlink content straight to your inbox.