Establishing a Connection
To begin interacting with the Ultra Wallet, a web application must first establish a connection. This connection request will ask the user for permission to share its blockchain id and public key, indicating that they are willing to continue interacting. Once the permission is set for the first time, the web application domain will be whitelisted for future connection requests. Similarly, it is possible to terminate the connection both on the application and on the user side.
Connecting
try {
const response = await ultra.connect();
response.data.blockchainid;
// ej1vx2ft3ht4
response.data.publicKey;
// EOS7uRb72dR8jrLjNuC9UoevBBH3YbVZfNKUtYCfLkV7aPGcmDjs7
} catch (err) {
// { status: "error", message: "Connection rejected" }
}
The connect()
call will return a Promise that is resolved when the user accepts the connection request and is rejected when the user rejects the request or closes the popup.
Eagerly Connecting
After a web application connects to the Ultra Wallet for the first time, it gains a trusted status. Once this trust is established, the application can seamlessly link with Ultra Wallet during future visits or when the page is refreshed, eliminating the need to ask the user for authorization. This concept is commonly known as "eagerly connecting".
To implement this, web applications should pass an onlyIfTrusted
option into the connect()
call.
try {
await ultra.connect({onlyIfTrusted: true});
} catch (err) {
// { status: 'error', code: 4001, message: 'The user rejected the request.' }
}
Sending a referral code
An application can send its referral code to the wallet. The referral code will be used if the user signs up during the connection process.
To implement this, applications should pass the referralCode option into the connect() call.
ultra.connect({referralCode: 'ecd1f052-9d0d-4b84-8dd3-10a753d044b5'});
To get your referral code, go to the Ultra Desktop client and then to the Wallet, and look for the "My referral link" section, click on the link to copy it.
Once you copy your referral link you can get the referral code from the URL. For example, the next link https://ultra.io/register/ecd1f052-9d0d-4b84-8dd3-10a753d044b5 has the referral code ecd1f052-9d0d-4b84-8dd3-10a753d044b5
.
Disconnecting
try {
await ultra.disconnect();
} catch (err) {
// { status: "error", message: "Forbidden" }
}
The disconnect()
method revokes the connection permission that the user granted to the web application, if the application is already disconnected, the Promise will throw an error.
To handle disconnections, the app can also subscribe to disconnect events.
ultra.on('disconnect', () => {
console.log('Disconnected from Ultra Wallet');
})