Usage
This section provides instructions on how to initialize the StarTowerWalletKit client, approve sessions with supported namespaces, and respond to session requests, enabling easy integration of Web3 wallets with dapps through a simple and intuitive interface.
Content​
Links to sections on this page. Some sections are platform specific and are only visible when the platform is selected. To view a summary of useful platform specific topics, check out Extra (Platform Specific) under this section.
Initialization: Creating a new StarTowerWalletKit instance and initializing it with a projectId from Cloud.
Session: Connection between a dapp and a wallet.
Namespace Builder: Namespace Builder is a helper utility that greatly reduces the complexity of parsing the required and optional namespaces. It accepts as parameters a session proposal along with your user's chains/methods/events/accounts and returns a ready-to-use object
Session Approval: Approving a session sent from a dapp
Session Rejection: Rejecting a session sent from a dapp
Responding to Session Requests: Responding to session requests sent from a dapp
Updating a Session: Updating a session sent between a dapp and wallet
Extending a Session: Extending a session between a dapp and wallet
Session Disconnect: Disconnecting a session between a dapp and wallet
Register Device Token Enabling Wallet Push Notifications by registering a device token.
Subscribe for WalletKit Publishers Publishers available to subscribe to for StarTowerWalletKit
Don't have a project ID?
Head over to Reown Cloud and create a new project now!
Initialization​
Confirm you have configured the Network Client first.
Starting from StarTower SDK version 1.9.5, the redirect
field in the AppMetadata
object is mandatory. Ensure that the provided value matches your app's URL scheme to prevent redirection-related issues.
Once you're done, in order to initialize a client just call a configure
method from the StarTowerWalletKit instance wrapper
In order to allow users to receive push notifications you have to communicate with Apple Push Notification service and receive unique device token. Register that token with following method:
Session​
A session is a connection between a dapp and a wallet. It is established when a user approves a session proposal from a dapp. A session is active until the user disconnects from the dapp or the session expires.
Namespace Builder​
AutoNamespaces
is a helper utility that greatly reduces the complexity of parsing the required and optional namespaces. It accepts as parameters a session proposal along with your user's chains/methods/events/accounts and returns ready-to-use SessionNamespace
object.
Example usage
EVM methods & events​
In @walletconnect/ethereum-provider, (our abstracted EVM SDK for apps) we support by default the following Ethereum methods and events:
Session Approval​
When session is successfully approved sessionsPublishers
will publish a Session
Session
object represents an active session connection with a dapp. It contains dapp’s metadata (that you may want to use for displaying an active session to the user), namespaces, and expiry date. There is also a topic property that you will use for linking requests with related sessions.
You can always query settled sessions from the client later with:
Connect Clients​
Your Wallet should allow users to scan a QR code generated by dapps. You are responsible for implementing it on your own. For testing, you can use our test dapp at: https://react-app.walletconnect.com/, which is v2 protocol compliant. Once you derive a URI from the QR code call pair
method:
if everything goes well, you should handle following event:
Session proposal is a handshake sent by a dapp and it's purpose is to define a session rules. Handshake procedure is defined by CAIP-25. Session.Proposal
object conveys set of required and optional ProposalNamespaces
that contains blockchains methods and events. Dapp requests with methods and wallet will emit events defined in namespaces.
VerifyContext
provides a domain verification information about Session.Proposal
and Request
. It consists of origin of a Dapp from where the request has been sent, validation enum that says whether origin is unknown, valid or invalid and verify URL server.
To enable or disable verification find the Verify SDK toggle in your project cloud.
The user will either approve the session proposal (with session namespaces) or reject it. Session namespaces must at least contain requested methods, events and accounts associated with proposed blockchains.
Accounts must be provided according to CAIP10 specification and be prefixed with a chain identifier. chain_id + : + account_address. You can find more on blockchain identifiers in CAIP2. Our Account
type meets the criteria.
Accounts sent in session approval must at least match all requested blockchains.
Example proposal namespaces request:
Example session namespaces response:
Track Sessions​
When your StarTowerWalletKit
instance receives requests from a peer it will publish a related event. Set a subscription to handle them.
To track sessions subscribe to sessionsPublisher
publisher
Session Rejection​
Responding to Session requests​
After the session is established, a dapp will request your wallet's users to sign a transaction or a message. Requests will be delivered by the following publisher.
When a wallet receives a session request, you probably want to show it to the user. It’s method will be in scope of session namespaces. And it’s params are represented by AnyCodable
type. An expected object can be derived as follows:
Now, your wallet (as it owns your user’s private keys) is responsible for signing the transaction. After doing it, you can send a response to a dapp.
Updating a Session​
If you want to update user session's chains, accounts, methods or events you can use session update method.
Last updated