Pular para o conteúdo principal

The window.chia provider reference

The DIG Browser (its built-in wallet) and the DIG Chrome extension (self-custody) inject a Chia wallet provider on window.chia. Any web page can ask it for the user's address, public keys, balances, coins, and NFTs, and can request signatures, transfers, and offers — the CHIP-0002 wallet-provider interface, delivered in-page instead of over WalletConnect.

This is the reference: the provider object's fields, connect, the events, and every method with its params, return shape, and error codes. For a walkthrough with the recommended detect → connect → fallback pattern, start with Using window.chia. For a typed wrapper that unifies this surface with the WalletConnect fallback, use @dignetwork/dig-sdk's ChiaProvider.

DIG is Chia mainnet-only

Every call runs against Chia mainnet. There is no testnet flow: chip0002_chainId resolves to "mainnet", and the chainId getter reads the same value once connected.

The provider object

window.chia is present synchronously on first script execution. Confirm you are talking to the DIG provider with its isDIG marker rather than the bare presence of window.chia (another Chia wallet could also claim the slot).

FieldTypeMeaning
isDIGtrueMarks the DIG provider. Key on this to target the DIG wallet specifically.
isGobytrueGoby-compatibility marker, so a page that feature-detects a Goby-style provider finds this one.
name"DIG"The provider name.
apiVersionstringSemantic version of the window.chia surface (e.g. "1.0.0").
versionstringThe wallet build version.
infoobject{ isDIG, transport: "injected" | "native", edition: "extension" | "browser", providerVersion } — how the provider is delivered and which edition injected it.
methodsstring[]The method names this provider answers (the catalogue — feature-detect against it).
errorCodesobjectThe numeric error-code enum, exposed for reference.
chainIdgetter → string"mainnet" once connected.
selectedAddressgetter → stringThe connected address (cached after connect).
isConnected()() => booleanWhether this origin is connected.

Two call styles are supported and equivalent:

  • request({ method, params }) — the EIP-1193-style entrypoint (below).
  • Direct methodsprovider.getPublicKeys(...), provider.transfer(...), provider.createOffer(...), and so on. Bare Goby/Sage-style names alias to their namespaced forms (transferchia_send, getPublicKeyschip0002_getPublicKeys), so code written for a Goby- or Sage-shaped provider works unchanged.
// Equivalent — pick whichever style your code prefers.
const keys = await window.chia.request({ method: "chip0002_getPublicKeys" });
const keys2 = await window.chia.getPublicKeys();

request({ method, params })

request takes a single { method, params } object and resolves to the bare result the wallet returns for that method, rejecting with an error on failure. A bare method name (e.g. getPublicKeys) is auto-prefixed to the chip0002_ namespace; a name already starting with chip0002_ or chia_ is used as-is. Prefer the explicit namespaced names in the tables below.

Discovering the method catalogue

Read window.chia.methods directly, or ask the provider (answered locally, no user prompt):

const methods = await window.chia.request({ method: "chip0002_getMethods" }); // string[]

connect

const ok = await window.chia.connect();                       // prompt to approve this origin
const eager = await window.chia.connect({ eager: true }); // silently reuse a prior approval

connect({ eager?, scope? }) establishes per-origin consent and resolves to a boolean (true on success). It caches the connected address and fires the connect and accountChanged events.

  • eager: true attempts a silent reconnect for an already-approved origin without prompting — use it on page load so returning users don't see a prompt.
  • scope is "full" (default) or "read-only".
  • Approval is per-origin; the user approves your site once.

You must connect() before any key, balance, coin, or signing method. Two more account helpers:

MethodReturnsNotes
requestAccounts()string[]Prompts for approval if needed, then returns the wallet's addresses.
accounts()string[]The already-approved addresses; rejects with 4900 if not connected.

Events

Subscribe with on(event, handler), unsubscribe with off(event, handler) (also aliased as removeListener):

function onAccount(addr) { /* active address changed */ }
window.chia.on("accountChanged", onAccount);
window.chia.off("accountChanged", onAccount);
EventFires when
connectThis origin is approved (including via an eager reconnect).
accountChangedThe active address changes (also emitted on connect).
chainChangedThe active chain changes. (Mainnet-only, so this does not fire in normal use.)

Read methods

Reads require a connected origin but never show an approval prompt.

MethodparamsReturns
chip0002_chainId"mainnet".
chip0002_getPublicKeysstring[] — hex public keys across both HD derivation schemes.
chia_getAddress{ address } — the wallet's receive address (bech32m xch1…).
chip0002_getAssetBalance{ type, assetId }{ confirmed, spendable, spendableCoinCount } — see below.
chip0002_getAssetCoins{ type, assetId }SpendableCoin[] — see below.
chip0002_filterUnlockedCoins{ coins }The subset of the supplied coins that are unlocked (spendable) for this wallet.
chia_getNfts (alias getNFTs)The wallet's NFTs as an array; each entry carries launcherId, coinId, and edition / royalty / URI metadata.

Selecting an asset. For getAssetBalance and getAssetCoins, pass type: null and assetId: null for native XCH; pass type: "cat" with the CAT's 32-byte TAIL assetId (hex) to select that CAT.

getAssetBalance shape. confirmed, spendable are base-unit amounts as decimal strings (mojos for XCH); spendableCoinCount is a number. confirmed === spendable.

const bal = await window.chia.request({
method: "chip0002_getAssetBalance",
params: { type: null, assetId: null }, // native XCH
});
// { confirmed: "1000000000000", spendable: "1000000000000", spendableCoinCount: 3 }

SpendableCoin shape. Each entry is:

{
coin: { parentCoinInfo: string, puzzleHash: string, amount: string },
coinName: string,
locked: boolean
}

Write methods

Each write shows an approval prompt; the user must confirm before anything is signed or broadcast. Amounts and fees are in base units (mojos for XCH).

MethodparamsReturns
chia_send (aliases transfer, send){ address | to, amount, assetId?, fee? }amount is a string or number; assetId selects a CAT (omit for XCH){ id } — the transaction id.
chia_sendTransaction{ spendBundle: { coin_spends: [...], aggregated_signature } } — broadcast an already-signed bundleTransactionResp[][{ status }]; status is a MempoolInclusionStatus (1 = success).
chia_createOffer{ offerAssets: [{ assetId?, amount }], requestAssets: [{ assetId?, amount }], fee? } — exactly one offered and one requested asset; omit assetId for XCH{ offer } — an offer1… string.
chia_takeOffer{ offer, fee? }{ id } — the transaction id.
chia_cancelOffer{ offer, fee? }{ id } — the transaction id.
chip0002_signCoinSpends{ coinSpends }string — the aggregated BLS signature (hex); your dApp broadcasts the signed bundle.
chip0002_signMessage (alias chia_signMessageByAddress){ message, publicKey? }{ signature, publicKey }.
// Send 0.25 XCH (base units = mojos). Shows an approval prompt.
const { id } = await window.chia.request({
method: "chia_send",
params: { to: "xch1…", amount: "250000000000", fee: "0" },
});

Error codes

A rejected call throws an Error carrying a numeric .code (CHIP-0002). Branch on .code, not on the message string.

CodeNameMeaning
4000INVALID_PARAMSA parameter is missing or malformed.
4001UNAUTHORIZEDNot connected, or the wallet is locked. Call connect() first.
4002USER_REJECTEDThe user declined the prompt, or a connect approval timed out.
4003SPENDABLE_BALANCE_EXCEEDEDThe spend exceeds the spendable balance.
4004METHOD_NOT_FOUNDThe method is unsupported or not implemented (see below).
4005NO_SECRET_KEYNo signing key is available for the request.
4029LIMIT_EXCEEDEDA rate/size limit was exceeded.
4900DISCONNECTEDThe provider is not connected to an approved origin.

4002 (the user said no) is distinct from 4001 (not authorized) — branch on them separately.

Unimplemented methods return 4004

Methods outside the read/write sets above — such as DID management and NFT minting / bulk-minting — are not implemented and reject with 4004 (METHOD_NOT_FOUND). Feature-detect against window.chia.methods before calling anything beyond the tables here.

Getting started

Feature-detect the provider, connect, read an address and balance, send a transfer, and branch on the error code:

async function demo() {
const dig = (typeof window !== "undefined" && window.chia?.isDIG) ? window.chia : undefined;
if (!dig) return; // Not in the DIG Browser / extension — use your WalletConnect fallback.

try {
const connected = await dig.connect(); // → true on approval
if (!connected) return;

const { address } = await dig.request({ method: "chia_getAddress" });

const balance = await dig.request({
method: "chip0002_getAssetBalance",
params: { type: null, assetId: null }, // native XCH
});

// Shows an approval prompt; amount + fee are in mojos.
const { id } = await dig.request({
method: "chia_send",
params: { to: address, amount: "1", fee: "0" },
});

return { address, balance, id };
} catch (err) {
if (err.code === 4002) return; // user declined — not an error to surface
if (err.code === 4001) { // not connected / locked
await dig.connect();
return;
}
throw err;
}
}