Skip to main content

Get user wallet addresses

Overview

This guide explains how to fetch a user's Ronin addresses from using connector from Tanto Connect.

Get user addresses

To obtain the current account's addresses, you can use two methods:

  • connector.requestAccounts()
  • connector.getAccounts()

connector.requestAccounts

The connector.requestAccounts method requests the user to approve a session between your app and wallet. If the user rejects the session, an error is returned. If the user approves the session, the method resolves the list of the user's approved addresses.

const requestSession = async () => {
try {
const approvedAddress = await connector.requestAccounts()
return addresses
} catch (error) {
alert("User has rejected the request.")
}

}

requestSession()

connector.getAccounts

The connector.getAccounts method resolves with the list user addresses only. If the wallet is locked or there is no session between your app and wallet, the method returns an empty array.

const getUserAddresses = async () => {
const addresses = await connector.getAccounts()

return addresses
}

getUserAddresses()

Detect account change

Users can change their account when using Ronin Wallet. The provider emits the accountChanged event upon changing accounts.

const listenToAccountChange = async () => {
const addresses = connector.on(ConnectorEvent.ACCOUNTS_CHANGED, newAddresses => {
console.log("Account is changed to: ", newAddresses[0])
})
}

listenToAccountChange()

The ConnectorEvent is an enum from Tanto Connect that contains all the events emitted by the provider.