Portal Connect allows you to connect your Portal MPC Wallet to any dApp that supports WalletConnect without extra dependency bloat.
Portal
instance to connect your Portal MPC Wallet to dApps via WalletConnect. When connecting via Portal Connect, a few things happen in the background:
uri
for Portal Connect to connect withuri
portal.provider
to perform the request like normalPortalConnect
class is included in the portal-android
module, so no additional steps are required to start using PortalConnect
in your app.
PortalConnect
within your app, you’ll need to have a custom Application instance to ensure you can share the Portal
instance between Activities (Alternatively if you are using Dagger2 then you can add it as Singleton to your ApplicationComponent. Idea is that the Portal object should have the same lifecycle as your application). Once this is done, you can initialize Portal
like normal in your MainActivity
, and initialize PortalConnect
within a PortalConnectActivity.
application
node of your AndroidManifest.xml
. This will register your application class as the class that is used when your app starts.
Portal
in your ActivityPortal
, you’ll need to set the Portal
instance on the Application.
portal.createPortalConnectInstance()
.
connect(uri)
function on your PortalConnect
instance. This will initialize the WebSocket session with the WalletConnect relay and begin passing messages to your Portal Provider using your Portal MPC Wallet.
connect
and disconnect
events to get confirmation that you have successfully connected or if the user disconnects.
Session Requests
represent the initial connection request from the dApp to create a new session. These are triggered when Portal responds to the dApp after the connect(uri)
function is called. These events will be triggered with a SessionProposal
object. These objects can be used to display information about the dApp the user is connecting to and the specific permissions being requested by the dApp.
addChainsToProposal
. This can be used to add all the chains in your gateway config to the proposal object.
PortalConnect
instance.
emitGetSessionRequest
method. You will need to provide both the requestId
and the topic
.
requestId
and topic
values to successfully retrieve the session request.autoApprove
is turned off.
portal_connectError
in order to handle specific errors and warnings from Portal Connect. Check out our Portal Connect Error Codes here.
updateChainId
method.
chainId
in the gateway config with a gateway url on initialization of your Portal Object, otherwise, you can not switch chains.