Skip to content

The entry point for the Anvil SDK.

Create one instance per session (per wallet connection) and pass it to <AnvilProvider sdk={sdk}>. Implements SDKContext so it can be passed directly to internal action functions.

Organized into submodules for namespaced access:

  • sdk.loc.* — LOC queries and workflow builders
  • sdk.vault.* — Vault balances, deposits, withdrawals
  • sdk.pricing.* — Oracle prices and feed IDs
  • sdk.tokens.* — Token metadata and balances

Root methods handle cross-cutting concerns (signer, chain, addresses).

Examples

Read-only instance (no wallet) against Sepolia, using a profile

// No walletClient: queries, validation, and workflow building all work;
// only executing a workflow needs a signer.
const sdk = new AnvilSDK({
publicClient: createPublicClient({
chain: sepolia,
transport: http('https://your-rpc-url'),
}),
profile: testnetProfile,
});
// A direct contract read; no wallet and no subgraph involved.
const loc = await sdk.loc.getOutstandingLetterOfCredit({ id: 1n });
console.log(loc);

With a wallet: validate, build, then execute a workflow

const transport = http('https://your-rpc-url');
const account = privateKeyToAccount(
'0x0000000000000000000000000000000000000000000000000000000000000001'
);
const sdk = new AnvilSDK({
profile: mainnetProfile,
publicClient: createPublicClient({ chain: mainnet, transport }),
walletClient: createWalletClient({
account,
chain: mainnet,
transport,
}),
subgraphUrl: 'https://your-subgraph-url',
});
const params: CreateStaticLOCParams = {
beneficiary: '0x1111111111111111111111111111111111111111',
// 1,000 USDC (6 decimals), in the token's smallest unit.
tokenAmount: {
tokenAddress: '0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48',
amount: 1_000_000_000n,
},
expirationTimestampSeconds: BigInt(Math.floor(Date.now() / 1000) + 30 * 86_400),
};
// Validation touches no wallet; an empty array means the params are valid.
const issues = await sdk.loc.validateCreateStatic(params);
if (issues.length === 0) {
const workflow = await sdk.loc.buildCreateStaticWorkflow(params);
// Approvals, deposit, and creation run in order, each a wallet prompt.
await workflow.execute();
}

Implements

Constructors

Constructor

new AnvilSDK(deps): AnvilSDK;

Parameters

ParameterTypeDescription
depsAnvilDependenciesThe clients and configuration this instance uses; see AnvilDependencies. Shallow-copied into instance-owned state at construction, so the reactive setters below never mutate the object you pass in — they mutate this instance’s private copy, which submodules and actions read lazily at call time.

Returns

AnvilSDK

Throws

A ConfigError if deps is missing or is not a non-null object, if its required profile is missing or is not a non-null object, if the retired address-only dependency key is present, or if oracleConfig.maxPriceAgeSeconds is outside its supported domain.

Properties

deps

readonly deps: AnvilDependencies;

The instance-owned shallow copy of the dependencies this instance was constructed with. Mutating it (via updateAccountAddress or updateWalletClient) never affects the object the caller passed to the constructor.

Implementation of

SDKContext.deps


loc

readonly loc: LOCModule;

LOC queries and workflow builders.


pricing

readonly pricing: PricingModule;

Oracle prices, feed IDs, and update fees.


tokens

readonly tokens: TokenModule;

Token metadata and account balances.


vault

readonly vault: VaultModule;

Vault balances, deposits, withdrawals, and allowance signatures.

Accessors

locConfig

Get Signature

get locConfig(): LOCConfig | undefined;

The LOCConfig this instance was constructed with, if any.

Returns

LOCConfig | undefined


logger

Get Signature

get logger(): Logger;

The instance logger; console-backed with an [AnvilSDK] prefix. warn and error reach the console; info, log, and debug are no-ops, since those levels are where request/response payloads get logged. See SDKContext.logger.

Returns

Logger

Sink for the SDK’s diagnostic output. AnvilSDK supplies a console-backed logger that prefixes every line with [AnvilSDK]; there is no public way to replace it today. That default only surfaces warn and error — info, log, and debug are no-ops, since those are the levels request/response payloads log at.

Implementation of

SDKContext.logger

Methods

buildCancelLOCsAndWithdrawWorkflow()

buildCancelLOCsAndWithdrawWorkflow(params): Promise<WalletOperationWorkflow>;

Parameters

ParameterType
paramsCancelLOCsAndWithdrawParams

Returns

Promise<WalletOperationWorkflow>

Deprecated

Use sdk.loc.buildCancelAndWithdrawWorkflow instead, which takes the same arguments. This alias will be removed in a future release.


buildCancelLOCWorkflow()

buildCancelLOCWorkflow(params): Promise<WalletOperationWorkflow>;

Parameters

ParameterType
paramsCancelLOCParams

Returns

Promise<WalletOperationWorkflow>

Deprecated

Use sdk.loc.buildCancelWorkflow instead, which takes the same arguments. This alias will be removed in a future release.


buildCreateDynamicLOCWorkflow()

buildCreateDynamicLOCWorkflow(params): Promise<WalletOperationWorkflow>;

Parameters

ParameterType
paramsCreateDynamicLOCParams

Returns

Promise<WalletOperationWorkflow>

Deprecated

Use sdk.loc.buildCreateDynamicWorkflow instead, which takes the same arguments. This alias will be removed in a future release.


buildCreateStaticLOCWorkflow()

buildCreateStaticLOCWorkflow(params): Promise<WalletOperationWorkflow>;

Parameters

ParameterType
paramsCreateStaticLOCParams

Returns

Promise<WalletOperationWorkflow>

Deprecated

Use sdk.loc.buildCreateStaticWorkflow instead, which takes the same arguments. This alias will be removed in a future release.


buildDepositToVaultWorkflow()

buildDepositToVaultWorkflow(params): Promise<WalletOperationWorkflow>;

Parameters

ParameterType
paramsDepositToVaultParams

Returns

Promise<WalletOperationWorkflow>

Deprecated

Use sdk.vault.buildDepositWorkflow instead, which takes the same arguments. This alias will be removed in a future release.


buildExtendLOCWorkflow()

buildExtendLOCWorkflow(params): Promise<WalletOperationWorkflow>;

Parameters

ParameterType
paramsExtendLOCParams

Returns

Promise<WalletOperationWorkflow>

Deprecated

Use sdk.loc.buildExtendWorkflow instead, which takes the same arguments. This alias will be removed in a future release.


buildModifyLOCCollateralWorkflow()

buildModifyLOCCollateralWorkflow(params): Promise<WalletOperationWorkflow>;

Parameters

ParameterType
paramsModifyLOCCollateralParams

Returns

Promise<WalletOperationWorkflow>

Deprecated

Use sdk.loc.buildModifyCollateralWorkflow instead, which takes the same arguments. This alias will be removed in a future release.


buildRedeemLOCsWorkflow()

buildRedeemLOCsWorkflow(params): Promise<WalletOperationWorkflow>;

Parameters

ParameterType
paramsRedeemLOCsParams

Returns

Promise<WalletOperationWorkflow>

Deprecated

Use sdk.loc.buildRedeemWorkflow instead, which takes the same arguments. This alias will be removed in a future release.


buildWithdrawFromVaultWorkflow()

buildWithdrawFromVaultWorkflow(params): Promise<WalletOperationWorkflow>;

Parameters

ParameterType
paramsWithdrawFromVaultParams

Returns

Promise<WalletOperationWorkflow>

Deprecated

Use sdk.vault.buildWithdrawWorkflow instead, which takes the same arguments. This alias will be removed in a future release.


getChainId()

getChainId(): Promise<bigint>;

Chain ID of publicClient as a bigint, fetched live from the RPC on every call (not cached).

Returns

Promise<bigint>

Throws

ProviderConnectionError if the RPC call fails.


getCollateralTokens()

getCollateralTokens(params?, options?): Promise<CollectionPage<CollateralToken>>;

Parameters

ParameterTypeDescription
paramsGetCollateralTokensParamsPaging and filter options for the collection.
optionsReadExecutionOptionsCancellation controls for this page read.

Returns

Promise<CollectionPage<CollateralToken>>

Deprecated

Use sdk.loc.getCollateralTokens instead, which takes the same arguments. This alias will be removed in a future release.


getContractAddress()

getContractAddress(contract): Promise<`0x${string}`>;

Address of a protocol contract on the current chain, resolved from the required profile’s address-and-ABI binding. Multicall3 is the one deterministic static exception.

Parameters

ParameterType
contractAnvilContract

Returns

Promise<`0x${string}`>

Throws

ConfigError if the profile disagrees with the connected chain.


getEnsName()

getEnsName(params): Promise<string | null>;

Primary ENS name for an address, or null when none is set. ENS uses the mainnetRpcUrl client when configured.

Parameters

ParameterType
paramsGetEnsNameParams

Returns

Promise<string | null>

Throws

ProviderConnectionError only on RPC failure.


getERC20Allowance()

getERC20Allowance(params): Promise<bigint>;

ERC-20 allowance(owner, spender) in the token’s smallest unit; owner defaults to the signer address.

Parameters

ParameterType
paramsGetERC20AllowanceParams

Returns

Promise<bigint>


getOraclePriceUpdate()

getOraclePriceUpdate(params): Promise<OraclePriceUpdate>;

Parameters

ParameterType
paramsGetOraclePriceUpdateParams

Returns

Promise<OraclePriceUpdate>

Deprecated

Use sdk.pricing.getOraclePriceUpdate instead, which takes the same arguments. This alias will be removed in a future release.

Throws

StalePythPriceError If Hermes returns a price outside oracleConfig.maxPriceAgeSeconds.


getSignerAddress()

getSignerAddress(): Promise<`0x${string}`>;

Address the SDK treats as the current account: accountAddress if set, otherwise the wallet client’s account.

Returns

Promise<`0x${string}`>

Throws

WalletNotConnectedError when neither is configured.


resolveAddress()

resolveAddress(value): Promise<`0x${string}` | undefined>;

Resolve a hex address or ENS name to a checksummed address; undefined when the string is neither, or is a name with no address set. ENS uses the mainnetRpcUrl client when configured.

Parameters

ParameterType
valuestring

Returns

Promise<`0x${string}` | undefined>

Throws

ProviderConnectionError only on RPC failure — “no such name” is undefined, not an error.


updateAccountAddress()

updateAccountAddress(address): void;

Update the connected account address for read operations.

Parameters

ParameterType
address`0x${string}` | undefined

Returns

void


updateWalletClient()

updateWalletClient(walletClient): void;

Update the wallet client for signing and sending transactions.

Parameters

ParameterType
walletClient| { } | undefined

Returns

void