API
Initialization
To setup the client you need to configure it with your projectId
which you can obtain from Reown Cloud.
Furthermore you may need to configure the domain
and isLimited
parameters:
domain
defaults towindow.location.host
and must be set to the domain setup in Cloud Setup. For exampleapp.example.com
. Do not add the scheme (https://
).allApps
determines if your app has access to all of the user’s subscriptions, or only the ones that the app is hosted on. By setting it totrue
, it enables settingdomain
to a value other thanwindow.location.host
. SettingallApps: true
can be useful during development to allow your localhost-deployed app to access the subscriptions for the domain you setup. Note that most apps do not need to set this in production environments, as they only need access to their own subscriptions. When enabled, the user has to sign a SIWE message granting your app more permissions, and this requires additional consideration from the user.
References
- projectId: Your WalletConnect project ID
- domain (Optional): Your app’s domain. Defaults to
window.location.host
. - allApps (Optional): Set to
true
to request access to all of the user’s notification subscriptions for all apps, instead of onlydomain
. Defaults tofalse
. - logLevel (Optional): Increase verbosity of console logging. Defaults to
error
. Can be set toerror
,info
, ordebug
.
Managing Account
Setting account for web3inbox
References
- data: CAIP-10 account currently active in Web3Inbox
- setAccount: Change actively managed account in Web3Inbox. Does not need to be used as you can set the account directly in the params.
- isRegistered: A boolean of whether or not the account currently set is registered
- identityKey: Currently set account’s identity key
- error: A string, representing possible error of setting an account.
- isLoading: A boolean, representing if an account is being set
Registering an account
Note: EIP-1271 signatures coming from smart wallets are supported in version 1.1.0
and above.
References
- isRegistered: A boolean of whether or not the account currently set is registered
- prepareRegistration: Prepare registration params
- register: Register using a signature and register params
- isLoading: A boolean, representing if an account is being registered
Some suggested methods of signing the message:
@wagmi/core
signMessage
method- The
useSignMessage
hook in@wagmi
- Ethers.js
Wallet.signMessage
method
Managing Subscription
Subscribe, Unsubscribe, Get Subscription, Check if Subscribed.
When using differentAccount
, the passed account needs to be previously registered.
This use case is for Dapps that have multiple active accounts or wallets with multiple active accounts.
differentAccount
can be used for all the below hooks and functions that accept account
References
- account (Optional): CAIP-10 account
- domain (Optional): dapp domain
- subscribe: Function to subscribe to current dApp
() => void
- unsubscribe: Function to unsubscribe to current dApp
() => void
- isSubscribed: Reactive state, checking if subscribed to dApp
Boolean
- isSubscribing: If
subscribe()
is in-progress and has not finished yet - isUnsubscribing: If
unsubscribe()
is in-progress and has not finished yet - subscription: Reactive state, returning current subscription information, of type:
- subscriptions: Reactive state, returning array of current subscriptions
Managing Notifications
References
- useNotifications()
- notificationsPerPage: Number representing how many notifications to get per fetch
- isInfiniteScroll: Whether or not to keep already fetched notifications when getting next page
- params: (optional) Additional parameters
- unreadFirst: (optional, default
true
, since 1.3.0) Whether or not unread messages should be sorted at the top, regardless of timestamp
- nextPage: A function to be called to fetch the next page of notifications
- notifications: Array of notifications, of type
- notification.read: Mark the notification as read
- markNotificationsAsRead: Takes an array of notification IDs and marks them as read. Max 1000 IDs
- markAllNotificationsAsRead: Mark all notifications as read.
Notification Types
References
- update:
(enabledScopeNames: string[]) -> void
- types: Map of scopes (Notification types)
Registering for Device Push Notifications
If you wish to receive live push notifications to your React Native or Web app, you must integrate with Firebase Messaging. More information about how to integrate with Firebase can be found here.
Your integration will obtain a token from Firebase and you will need to pass this token to the Web3Inbox SDK using the registerWithPushServer()
function.
References
registerWithPushServer
:(token: string, platform: 'fcm' | 'apns' = 'fcm') => void
Either APNs or FCM can be used to receive push notifications to the device. The token
you provide may be a token from either platform, provided the platform
argument matches.
Listening For Events
This can be used to listen to, for example, messages received in realtime.
References
message
: Notification of type: