Skip to content

Documentation / @cashconnect-js/dapp / dapp-console

CashConnectDappConsole ​

Defined in: cashconnect-js/packages/dapp/src/dapp-console.ts:59

Extends ​

Type Parameters ​

Type ParameterDefault type
T extends TemplateTemplate

Constructors ​

Constructor ​

ts
new CashConnectDappConsole<T>(
   template, 
   chain, 
   opts, 
   allowedTokens): CashConnectDappConsole<T>;

Defined in: cashconnect-js/packages/dapp/src/dapp-console.ts:83

Parameters ​
ParameterTypeDefault value
templateTundefined
chainstring'bch:bchtest'
optsPartial<SignClientTypes.Options>{}
allowedTokensstring[][]
Returns ​

CashConnectDappConsole<T>

Overrides ​

CashConnectDapp.constructor

Methods ​

from() ​

ts
static from<T>(
   template, 
   chain, 
   opts, 
   allowedTokens): Promise<CashConnectDappConsole<T>>;

Defined in: cashconnect-js/packages/dapp/src/dapp-console.ts:62

Type Parameters ​
Type ParameterDefault type
T extends objectobject
Parameters ​
ParameterTypeDefault value
templateTundefined
chainstring'bch:bchtest'
optsPartial<SignClientTypes.Options>{}
allowedTokensstring[][]
Returns ​

Promise<CashConnectDappConsole<T>>

start() ​

ts
start(): Promise<void>;

Defined in: cashconnect-js/packages/dapp/src/dapp.ts:130

Returns ​

Promise<void>

Inherited from ​

CashConnectDapp.start

connect() ​

ts
connect(): Promise<boolean>;

Defined in: cashconnect-js/packages/dapp/src/dapp.ts:141

Returns ​

Promise<boolean>

Inherited from ​

CashConnectDapp.connect

newSession() ​

ts
newSession(): Promise<"CONNECTED" | "CANCELLED">;

Defined in: cashconnect-js/packages/dapp/src/dapp.ts:177

Returns ​

Promise<"CONNECTED" | "CANCELLED">

Inherited from ​

CashConnectDapp.newSession

reconnectSession() ​

ts
reconnectSession(silent): Promise<"CONNECTED" | "CANCELLED" | "NEW_SESSION">;

Defined in: cashconnect-js/packages/dapp/src/dapp.ts:264

Parameters ​
ParameterTypeDefault value
silentbooleanfalse
Returns ​

Promise<"CONNECTED" | "CANCELLED" | "NEW_SESSION">

Inherited from ​

CashConnectDapp.reconnectSession

disconnect() ​

ts
disconnect(): Promise<void>;

Defined in: cashconnect-js/packages/dapp/src/dapp.ts:347

Returns ​

Promise<void>

Inherited from ​

CashConnectDapp.disconnect

executeAction() ​

ts
executeAction<A>(
   actionName, 
   params, 
   opts): Promise<ActionResult<T, A>>;

Defined in: cashconnect-js/packages/dapp/src/dapp.ts:374

Type Parameters ​
Type Parameter
A extends string
Parameters ​
ParameterType
actionNameA
params{ [K in string | number | symbol]: ({ [K in string | number | symbol as T["actions"][A]["params"][K] extends { required: false } ? never : K]: ProcessVariable<T["actions"][A]["params"][K]> } & { [K in string | number | symbol as T["actions"][A]["params"][K] extends { required: false } ? K : never]?: ProcessVariable<T["actions"][A]["params"][K]> })[K] }
optsRequestOpts
Returns ​

Promise<ActionResult<T, A>>

Inherited from ​

CashConnectDapp.executeAction

getBalances() ​

ts
getBalances(): Promise<any>;

Defined in: cashconnect-js/packages/dapp/src/dapp.ts:438

Returns ​

Promise<any>

Inherited from ​

CashConnectDapp.getBalances

getTokens() ​

ts
getTokens(): Promise<any>;

Defined in: cashconnect-js/packages/dapp/src/dapp.ts:459

Returns ​

Promise<any>

Inherited from ​

CashConnectDapp.getTokens

disconnectInactiveSessions() ​

ts
disconnectInactiveSessions(): Promise<void>;

Defined in: cashconnect-js/packages/dapp/src/dapp.ts:480

Returns ​

Promise<void>

Inherited from ​

CashConnectDapp.disconnectInactiveSessions

onSessionDisconnect() ​

ts
onSessionDisconnect(): Promise<void>;

Defined in: cashconnect-js/packages/dapp/src/dapp.ts:501

Returns ​

Promise<void>

Inherited from ​

CashConnectDapp.onSessionDisconnect

onSessionUpdate() ​

ts
onSessionUpdate(): Promise<void>;

Defined in: cashconnect-js/packages/dapp/src/dapp.ts:505

Returns ​

Promise<void>

Inherited from ​

CashConnectDapp.onSessionUpdate

onSessionEvent() ​

ts
onSessionEvent(event): Promise<void>;

Defined in: cashconnect-js/packages/dapp/src/dapp.ts:509

Parameters ​
ParameterType
eventBaseEventArgs<{ event: { name: string; data: any; }; chainId: string; }>
Returns ​

Promise<void>

Inherited from ​

CashConnectDapp.onSessionEvent

on() ​

ts
on<K>(
   type, 
   listener, 
   debounceMilliseconds?): OffCallback;

Defined in: cashconnect-js/packages/core/dist/primitives.d.ts:593

Registers a listener for the specified event type.

Type Parameters ​
Type ParameterDescription
K extends keyof CashConnectDappEventsThe event type key
Parameters ​
ParameterTypeDescription
typeKThe event type to listen for
listenerListener<CashConnectDappEvents[K]>The function to call when the event is emitted
debounceMilliseconds?numberOptional debounce time in milliseconds
Returns ​

OffCallback

A callback function that can be used to unregister this listener

Example ​
typescript
const off = emitter.on('data-change', (data) => {
  console.log('Data updated:', data);
}, 300); // Debounce for 300ms

// Later, unregister the listener
off();
Inherited from ​

CashConnectDapp.on

once() ​

ts
once<K>(
   type, 
   listener, 
   debounceMilliseconds?): OffCallback;

Defined in: cashconnect-js/packages/core/dist/primitives.d.ts:611

Registers a one-time listener for the specified event type. The listener will be automatically removed after being called once.

Type Parameters ​
Type ParameterDescription
K extends keyof CashConnectDappEventsThe event type key
Parameters ​
ParameterTypeDescription
typeKThe event type to listen for
listenerListener<CashConnectDappEvents[K]>The function to call when the event is emitted
debounceMilliseconds?numberOptional debounce time in milliseconds
Returns ​

OffCallback

A callback function that can be used to unregister this listener before it fires

Example ​
typescript
emitter.once('user-login', ({ userId }) => {
  console.log(`Welcome ${userId}! This will only show once.`);
});
Inherited from ​

CashConnectDapp.once

off() ​

ts
off<K>(type, listener): void;

Defined in: cashconnect-js/packages/core/dist/primitives.d.ts:626

Removes a specific listener for the given event type.

Type Parameters ​
Type ParameterDescription
K extends keyof CashConnectDappEventsThe event type key
Parameters ​
ParameterTypeDescription
typeKThe event type to remove the listener from
listenerListener<CashConnectDappEvents[K]>The listener function to remove
Returns ​

void

Example ​
typescript
const handler = (data) => console.log(data);
emitter.on('test', handler);
emitter.off('test', handler); // Removes the listener
Inherited from ​

CashConnectDapp.off

emit() ​

ts
emit<K>(type, payload): boolean;

Defined in: cashconnect-js/packages/core/dist/primitives.d.ts:648

Emits an event of the specified type with the given payload. All registered listeners for this event type will be called.

Type Parameters ​
Type ParameterDescription
K extends keyof CashConnectDappEventsThe event type key
Parameters ​
ParameterTypeDescription
typeKThe event type to emit
payloadCashConnectDappEvents[K]The data to pass to all listeners
Returns ​

boolean

true if there were listeners for this event, false otherwise

Example ​
typescript
const hasListeners = emitter.emit('user-login', {
  userId: '123',
  timestamp: Date.now()
});

if (!hasListeners) {
  console.log('No one was listening for user-login events');
}
Inherited from ​

CashConnectDapp.emit

removeAllListeners() ​

ts
removeAllListeners(): void;

Defined in: cashconnect-js/packages/core/dist/primitives.d.ts:659

Removes all listeners for all events. This effectively resets the EventEmitter to its initial state.

Returns ​

void

Example ​
typescript
emitter.removeAllListeners();
// All previously registered listeners are now gone
Inherited from ​

CashConnectDapp.removeAllListeners

waitFor() ​

ts
waitFor<K>(
   type, 
   predicate, 
   timeoutMs?): Promise<CashConnectDappEvents[K]>;

Defined in: cashconnect-js/packages/core/dist/primitives.d.ts:685

Returns a Promise that resolves when an event of the specified type is emitted and matches the given predicate.

Type Parameters ​
Type ParameterDescription
K extends keyof CashConnectDappEventsThe event type key
Parameters ​
ParameterTypeDescription
typeKThe event type to wait for
predicate(payload) => booleanA function that determines if the event payload matches what we're waiting for
timeoutMs?numberOptional timeout in milliseconds. If specified, the promise will reject after this time
Returns ​

Promise<CashConnectDappEvents[K]>

A Promise that resolves with the event payload when the condition is met

Throws ​

If the timeout is reached before a matching event occurs

Example ​
typescript
try {
  const loginData = await emitter.waitFor(
    'user-login',
    ({ userId }) => userId === 'admin',
    5000 // Wait up to 5 seconds
  );
  console.log('Admin logged in:', loginData);
} catch (error) {
  console.log('Timeout: Admin never logged in');
}
Inherited from ​

CashConnectDapp.waitFor

Properties ​

PropertyModifierTypeDefault valueInherited fromDefined in
templatereadonlyTundefinedCashConnectDapp.templatecashconnect-js/packages/dapp/src/dapp-console.ts:84
chainreadonlystring'bch:bchtest'CashConnectDapp.chaincashconnect-js/packages/dapp/src/dapp-console.ts:85
optsreadonlyPartial<SignClientTypes.Options>{}-cashconnect-js/packages/dapp/src/dapp-console.ts:86
allowedTokensreadonlystring[][]CashConnectDapp.allowedTokenscashconnect-js/packages/dapp/src/dapp-console.ts:87
clientpublicSignClientundefinedCashConnectDapp.clientcashconnect-js/packages/dapp/src/dapp.ts:114
session?publicStructundefinedCashConnectDapp.sessioncashconnect-js/packages/dapp/src/dapp.ts:115
onConnected?public(session) => Promise<void>undefinedCashConnectDapp.onConnectedcashconnect-js/packages/dapp/src/dapp.ts:118
optionsreadonlyOptionsundefinedCashConnectDapp.optionscashconnect-js/packages/dapp/src/dapp.ts:121
dialogsreadonlyDappDialogsundefinedCashConnectDapp.dialogscashconnect-js/packages/dapp/src/dapp.ts:125