Skip to main content
Use Quickstart with TypeScript SDK for first setup. Use this page after connection to choose client methods, signing helpers, diagnostics, path helpers, and exports. MCP users who do not already have a wallet or signing service can also use this page to set up the TypeScript SDK with viem as a local testnet signing harness for typed data prepared by Quickstart with MCP. Use literal SDK symbols exactly as exported by the package, including ApiClient, AgreementsApiError, agreementsApiPaths, and API_BASE_PATH. The package targets Node >=18.

Install

@shodai-network/agreements-protocol-evm is installed automatically as a package dependency. Install viem in your app when you use permit-signing helpers. The Agreements API client and the onchain protocol SDK are both published under the @shodai-network npm organization. The agreements-api-playground sample application uses @shodai-network/agreements-api-client for API calls and @shodai-network/agreements-protocol-evm for onchain agreement typing and signing support.

Create a client

Constructor config: If both environment and baseUrl are supplied, baseUrl wins. testnet resolves to https://test-api.shodai.network; production resolves to https://api.shodai.network. apiKey and tokenProvider are mutually exclusive. For a user-delegated provider in an installed Node.js client, follow Connect an installed TypeScript client with delegated OAuth. For key provisioning, scopes, entitlements, and 401/402/403 behavior, see Authentication.

Wallet and RPC requirements

The API key authenticates requests. Deploying agreements and submitting agreement inputs also require a wallet your integration controls because those workflows depend on EIP-712 signatures.

Create a test-only wallet client

For automated tests that only need EIP-712 signatures, create an ephemeral wallet with viem. This wallet does not need gas when it only signs permits. Do not use this pattern for production wallets, and do not commit generated private keys.
The testnet API environment supports Linea Sepolia (59141), Ethereum Sepolia (11155111), and Base Sepolia (84532) for agreement deployments. The production API environment supports Linea Mainnet (59144) and Base Mainnet (8453). Choose the chainId explicitly for deployment preflight and deploy requests, then reuse the deployed agreement record’s chainId when signing inputs. Use account.address in participant mappings when the test wallet needs to deploy an agreement or submit an input for a participant role. Before calling deployAgreementWithPermit(...) or submitAgreementInputWithPermit(...), confirm that:
  1. you have an API key for authenticated requests
  2. you have a walletClient that can sign with the intended account
  3. you have a publicClient connected to the target chain
  4. the wallet chain matches the deployment or agreement chain
  5. the signer is appropriate for the deployment or input issuer
  6. you can regenerate signatures when nonce, deadline, payload, chain, agreement JSON, or values change

Choose the right SDK surface

Main client methods

The public API returns JSON envelopes for authenticated agreement routes. SDK methods that read one resource unwrap data and return the resource directly. List methods return the list envelope so your integration can read data, pageInfo, and meta.
List filters use qs-style bracket modifiers. For example, { createdAt: { gte: '...' }, sort: { createdAt: 'desc' } } serializes as createdAt[gte]=...&sort[createdAt]=desc. Agreement lists support chainId, state, createdAt, updatedAt, limit, cursor, and one sort field from createdAt, updatedAt, or displayName. Input history supports userId, inputId, status, createdAt, updatedAt, limit, cursor, and one sort field from createdAt or updatedAt. Date filters support gt, gte, lt, and lte; limit must be between 1 and 100.

Receive webhook events

Use webhooks when your integration should react to agreement activity or notification rules without polling agreement state. Webhook subscriptions can receive agreement.transitioned and agreement.notification.triggered events for agreement records associated with the current API principal. For signing, retries, filters, and delivery behavior, see Receive webhooks. For event-family details, see Agreement activity webhooks and Notification webhooks.
Store created.secret immediately. It is returned only when the webhook is created. listWebhooks, getWebhook, updateWebhook, deleteWebhook, and testWebhook do not return the signing secret. To receive agreement.notification.triggered, include an external_webhook notification template when you deploy the agreement. The API scopes that template to the authenticated principal and deployed agreement. See Notification webhooks for supported triggers, temporal rules, recipients, interpolation, and payloads.
Use constructWebhookEvent(...) from the webhook helper export to verify signed deliveries against the exact raw request body:
Use deleteWebhook(webhookId) to disable a subscription. The API returns the disabled subscription; it does not hard-delete the subscription record.

Validate and deploy with helpers

Use deployment preflight before signing when initValues, participant mappings, or observers affect the deployment request.
Then use the high-level helper for the normal sign-and-submit path.
Participant-derived values in validation.variables are the effective values the SDK signs for deployment. Keep the same participants array in deployAgreementWithPermit(...) so hosted agreement context records the participant mappings.
When neither docUri nor permitOptions.docUri is supplied, deployAgreementWithPermit(...) generates a documentId and signs a docUri that points at GET /v0/agreements/documents/{documentId}. Pass docUri or documentId explicitly when your integration owns document addressing.

Submit signed inputs with helpers

publicClient must be connected to the target chain/RPC. Input submissions also require chainId from the deployed agreement record so the helper can fail before signing if the client is connected to the wrong chain. The signing helpers use publicClient to resolve the chain-specific AgreementFactory or agreement contract context and to read the current permit nonce before signing.

Control deadlines and low-level signing

DEFAULT_PERMIT_DEADLINE_SECONDS is 3600. computeDefaultDeadlineSeconds(offsetSeconds = 3600) returns the current Unix time plus the offset. High-level deployAgreementWithPermit(...) and submitAgreementInputWithPermit(...) default the deadline. Low-level signDeployWithPermit(...) and signAgreementInputPermit(...) require an explicit deadline. Use low-level signing helpers when your application needs to sign first and submit later, inspect the signature, or compose the request body itself. Use EIP-712 Signing Reference only when you need to construct the typed data directly or debug helper behavior.

Handle API errors

The client throws AgreementsApiError when the response status does not match the expected success status.
AgreementsApiError exposes status, bodyText, parsedBody, and errorPayload. errorPayload.error.code is stable for branching, and errorPayload.error.requestId is the value to share when you need support to trace a request.

Use raw exchange for diagnostics

Use exchangeJson() when you need response metadata or raw body text during debugging. It does not throw for HTTP error status codes.
exchangeJson() accepts DELETE, GET, PATCH, and POST. It returns status, ok, headers, bodyText, and parsedBody.

Use path helpers when composing raw calls

Path helper names are openapiJson, health, webhooks, webhook, webhookTest, agreements, agreementsValidate, agreementsValidateTemplate, agreementsDeployWithPermit, agreementDocument, agreement, agreementState, agreementInputs, and agreementInput. ID path helpers encode IDs and use API_BASE_PATH, which is /v0.

Root exports

The package root exports these values, classes, and functions:
  • ApiClient
  • AgreementsApiError
  • extractAgreementsApiErrorMessage
  • agreementsApiPaths
  • getExecutionInputIds
  • joinUrl
  • API_BASE_PATH
  • API_ENVIRONMENT_BASE_URLS
  • API_MAJOR_VERSION
  • DEFAULT_API_ENVIRONMENT
  • resolveApiBaseUrl
  • buildAgreementDocumentUri
  • createAgreementDocumentId
  • computeDefaultDeadlineSeconds
  • DEFAULT_PERMIT_DEADLINE_SECONDS
  • signDeployWithPermit
  • signAgreementInputPermit
  • deployAgreementWithPermit
  • submitAgreementInputWithPermit
The package root exports these TypeScript types:
  • AgreementInputRecord
  • AgreementDocumentResponse
  • AgreementInputListParams
  • AgreementInputListSortField
  • AgreementListParams
  • AgreementListSortField
  • AgreementRecord
  • AgreementSummary
  • AgreementStateResponse
  • ApiResponse
  • DateFilter
  • DirectDeployAgreementWithPermitRequest
  • ErrorResponse
  • HealthResponse
  • ListResponse
  • NotificationRule
  • NotificationTemplate
  • PageInfo
  • ParticipantRecord
  • ApiClientConfig
  • AgreementsApiEnvironment
  • CreateWebhookRequest
  • CreateWebhookResponse
  • DirectParticipantRecord
  • PermitSignature
  • ProcessInputRequest
  • SortDirection
  • SortFilter
  • UpdateWebhookRequest
  • ValidateDirectAgreementRequest
  • ValidateDirectAgreementResponse
  • ValidateDirectAgreementTemplateResponse
  • WebhookEventType
  • WebhookFilters
  • WebhookSubscriptionEventType
  • WebhookSubscription
  • WebhookSubscriptionStatus
  • WebhookTestResponse
  • DeployWithPermitCallParams
  • SignDeployPermitParams
  • SignDeployPermitResult
  • SignInputPermitParams
  • SignInputPermitResult
  • SubmitInputCallParams
The @shodai-network/agreements-api-client/client export provides ApiClient. The @shodai-network/agreements-api-client/webhooks export provides webhook receiver helpers and types:
  • constructWebhookEvent
  • verifyWebhookSignature
  • computeWebhookSignature
  • WebhookVerificationError
  • WebhookVerificationErrorCode
  • WebhookRawBody
  • WebhookHeaders
  • WebhookEventType
  • WebhookEventEnvelope
  • WebhookTestData
  • WebhookTestEvent
  • AgreementTransitionedWebhookData
  • AgreementTransitionedWebhookEvent
  • NotificationAttachmentStrategy
  • AgreementNotificationTriggeredWebhookData
  • AgreementNotificationTriggeredWebhookEvent
  • UnknownWebhookEvent
  • ShodaiWebhookEvent
  • VerifiedWebhookMetadata
  • ConstructWebhookEventOptions
  • WEBHOOK_ID_HEADER
  • WEBHOOK_TIMESTAMP_HEADER
  • WEBHOOK_SIGNATURE_HEADER
  • DEFAULT_WEBHOOK_TOLERANCE_SECONDS
  • WEBHOOK_API_VERSION
The Node-only @shodai-network/agreements-api-client/oauth export provides these delegated OAuth symbols used by the installed-client guide:
  • OauthDelegatedSession
  • OauthDelegatedTokenSet