Demos Wallet Provider API
Provider Interface
The injected provider exposes a small surface:
provider.request({ method, params? })
: Generic RPC-style method. Preferred for all interactions.provider.accounts() → Promise<{ code: 404|401|200, data: string|null }>
: Returns account status/address, used primarily for discovery gating.
The provider posts messages into the page. Internally, they are forwarded to the extension background and resolved back into a unified response:
export default interface DemosProviderResponse {
id: string;
type: "demosProviderResponse";
method: string; // echoes requested method
success: boolean;
data?: any;
error?: {
code: string;
message: string;
details?: any;
}
}
Supported Methods
Call each via provider.request({ method: '<name>', params: [...] })
unless noted otherwise.
connect
Params: none
Behavior: opens a connection popup; user approves/denies.
Success
data
:{ address: string }
Errors:
connectionDenied
,connectionCancelled
,TIMEOUT
sendTransaction
Params:
[payload:{recipient:string, amount:Number}]
Behavior: opens validation popup, user confirms.
Success:
data:{response, validityData
}Errors:
sendTransactionError
,sendTransactionCancelled
,TIMEOUT
,POPUP_ERROR
getXmIdentities
Params: none
Success
data
: list of identities from SDKErrors:
getXmIdentitiesError
addXmIdentity
Params:
[payload: InferFromSignaturePayload]
Behavior: infers and validates identity, then prompts user in validation popup.
Errors:
addXmIdentityError
,addXmIdentityCancelled
,TIMEOUT
removeXmIdentity
Params:
[payload: XMCoreTargetIdentityPayload]
Behavior: creates removal validity data and prompts user in validation popup.
Errors:
removeXmIdentityError
,removeXmIdentityCancelled
,TIMEOUT
getWeb2Identities
Params: none
Success
data
: identities list from SDKErrors:
getWeb2IdentitiesError
getWeb2IdentityProofPayload
Params: none
Success
data
: proof payload to be used for Web2 identity linkingErrors:
getWeb2IdentityProofPayloadError
(also returns error if user not logged in)
addTwitterIdentity
Params:
[payload: TwitterProof]
Behavior: validates and prompts user in validation popup.
Errors:
addTwitterIdentityError
,addTwitterIdentityCancelled
,TIMEOUT
removeWeb2Identity
Params:
[{ context: string, username: string }]
Behavior: constructs validity data and prompts user in validation popup.
Errors:
removeWeb2IdentityError
,removeWeb2IdentityCancelled
,TIMEOUT
Usage Examples
Connect and get address:
window.dispatchEvent(new Event('demosRequestProvider'));
window.addEventListener('demosAnnounceProvider', async (evt) => {
const provider = evt.detail.provider;
// Optional: discover account status
const accounts = await provider.accounts();
if (accounts.code !== 200) {
const res = await provider.request({ method: 'connect' });
if (!res.success) throw new Error(res.error?.message ?? 'Connect failed');
}
const result = await provider.request({ method: 'getXmIdentities' });
console.log(result.success ? result.data : result.error);
});
Send a transaction:
const tx = await provider.request({
method: 'sendTransaction',
params: [{ amount: 1 }],
});
if (!tx.success) {
// handle tx.error.code/message
}
Add a Twitter identity (shape defined by SDK TwitterProof
):
const proof = /* obtain TwitterProof via your backend/SDK */
const res = await provider.request({ method: 'addTwitterIdentity', params: [proof] });
Error Semantics
Common error codes surfaced in response.error.code
:
TIMEOUT
: popup not resolved before timeoutPOPUP_ERROR
: could not open popup...Cancelled
: user closed popup (validationCancelled
,addTwitterIdentityCancelled
, etc.)Method-specific errors (e.g.,
addGithubIdentityError
,sendTransactionError
) includedetails
when available
Notes
The extension only announces the provider after
provider.accounts()
indicates a non-404 status.Always prefer
provider.request
with the methods above for forward-compatibility.
Last updated