Skip to content

wallet_connect

Requests to connect account(s) with optional capabilities.

Request

type Request = {
  method: 'wallet_connect',
  params: [{
    /** Optional capabilities to request. */
    capabilities?: {
      /** Grant permissions. */
      grantPermissions?: PermissionsRequestCapabilities['grantPermissions']
    }
  }]
}

Capabilities:

Response

List of connected accounts.

type Response = {
  accounts: {
    /** Address of the account. */
    address: `0x${string}`,
    /** Capabilities of the account. */
    capabilities: {
      /** Permissions that were granted. */
      permissions: PermissionsResponseCapabilities['permissions']
    }
  }[]
}

Capabilities:

Example

import { Porto } from 'porto'
 
const { provider } = Porto.create()
 
const response = await provider.request({ 
  method: 'wallet_connect', 
}) 

Grant Permissions

You can grant permissions for an Application to perform actions on behalf of the account by providing the grantPermissions capability with a value.

In the example below, the Application is granted permission to perform transfer calls on the EXP ERC20 contract, with a spending limit of up to 50 EXP per minute.

import { parseEther, toHex } from 'viem'
 
const token = '0x29f45fc3ed1d0ffafb5e2af9cc6c3ab1555cd5a2'
 
const response = await provider.request({
  method: 'wallet_connect',
  params: [{
    capabilities: {
      grantPermissions: {
        expiry: Math.floor(Date.now() / 1000) + 60 * 60, // 1 hour
        permissions: {
          calls: [{ 
            signature: 'transfer(address,uint256)',
            to: token,
          }],
          spend: [{ 
            limit: toHex(parseEther('50')), // 50 EXP
            period: 'minute',
            token: token,
          }],
        },
      },
    },
  }],
})