Skip to content
On this page

API Reference

provider.version

  • Type: string

Returns the current provider version in the Semver format

js
const currentInstalledVersion = provider.version; // 2.6.1

provider.connect()

  • Type: function
  • Returning: Promise<{ address: string, publicKey: string }>

Requests the user's permission to use the wallet on a site.

Permissions need to be requested for each account separately.
If a permission has already been granted, or if you have previously called the provider.disconnect method, then this method will not cause the confirmation window to reappear but rather will immediately return the account's information.

Returning { address: string, publicKey: string }:

  • address - address of the connected account in hex format with lead 0x
  • publicKey - address of the connected account in hex format with lead 0x

Throws an error if the user did not allow access or closed the window { error: number, message: string }:

  • code - error code, like 403
  • message - error message, like Rejected by user
js
try {
  const account = await provider.connect();
  console.log(account);
  /*
    {
      address: "0x797b0209c...15e63e",
      publicKey: "0xf7498703...1ee4e4"
    }
  */
} catch (e) {
  console.log(e); // { code: 403, message: 'Rejected by user' }
}

provider.isConnected()

  • Type: function
  • Returning: Promise<boolean>

Returns the current wallet connection status.

Returning boolean:

  • true - connected
  • false - not connected
js
const currentConnectionStatus = await provider.isConnected(); // true or false

provider.disconnect()

  • Type: function
  • Returning: Promise<void>

Disconnects the wallet from the current site.

TIP

This method does not remove the entry about allowing access; it only disables the wallet from receiving any updates - for example, provider.onAccountChange, provider.onNetworkChange.

To reconnect the wallet, call the provider.connect method. Calling the connect method after disconnect will not cause the user confirmation screen to appear.

js
await provider.disconnect();

provider.onChangeAccount(callback)

  • Type: function
  • Returning: () => void
  • Arguments:
    • callback: (address: string | undefined) => void A callback that takes as an argument the new current wallet address after it has been changed by the user through the wallet UI.

Subscribes to account switch events in the wallet.

Each time the current account changes, calls the passed callback.
If the account was changed to one that the current site does not have access to, it will return undefined.

Returns a function that unsubscribes from updates.

js
const unsubscribe = await provider.onChangeAccount((address) => {
  if(address) {
    console.log(`New address: ${address}`)
  } else {
    console.log(`No access to current account`)
  }
})
...
// unsubscribe from updates
unsubscribe()

provider.onChangeNetwork(callback)

  • Type: function
  • Returning: () => void
  • Arguments:
    • callback: (network: { name: string, api: string, chainId: string }) => void A callback that takes as an argument the new current network after it has been changed by the user through the wallet UI.

Subscribes to network switch events in the wallet.
Calls the passed callback each time the current network is changed.

Returns a function that unsubscribes from updates.

  • name - network name, like Aptos mainnet, Aptos testnet
  • api - url to fullnode api like https://fullnode.testnet.aptoslabs.com/v1/
  • chainId - network chain id, like 1, 2
js
const unsubscribe = await provider.onChangeNetwork((network) => {
  console.log(`New network: ${network}`); // { name: 'Aptos testnet', api: 'https://fullnode.testnet.aptoslabs.com/v1/', chainId: '2' }
})
...
// unsubscribe from updates
unsubscribe()

provider.network()

  • Type: function
  • Returning: Promise<{ name: string, api: string, chainId: string }>

Returns the current network.
Returning { name: string, api: string, chainId: string }:

  • name - network name, like Aptos mainnet, Aptos testnet
  • api - url to fullnode api like https://fullnode.testnet.aptoslabs.com/v1/
  • chainId - network chain id, like 1, 2

Throws an error if the user did not allow access { error: number, message: string }:

  • code - error code, like 401
  • message - error message, like Access denied
js
try {
  const network = await provider.network();
  console.log(network);
  /*
    {
      name: 'Aptos testnet',
      api: 'https://fullnode.testnet.aptoslabs.com/v1/',
      chainId: '2'
    }
  */
} catch (e) {
  console.log(e); // { code: 401, message: 'Access denied' }
}

provider.chainId()

  • Type: function
  • Returning: Promise<string>

Returns the chainId of current network.

Throws an error if the user did not allow access { error: number, message: string }:

  • code - error code, like 401
  • message - error message, like Access denied
js
try {
  const chainId = await provider.chainId();
  console.log(chainId); // 1
} catch (e) {
  console.log(e); // { code: 401, message: 'Access denied' }
}

provider.account()

  • Type: function
  • Returning: Promise<string>

Returns the address of the connected account in hex format with lead 0x.

Throws an error if the user did not allow access { error: number, message: string }:

  • code - error code, like 401
  • message - error message, like Access denied
js
try {
  const account = await provider.account();
  console.log(account); // 0x797b0209c...15e63e
} catch (e) {
  console.log(e); // { code: 401, message: 'Access denied' }
}

provider.publicKey()

  • Type: function
  • Returning: Promise<string>

Returns the public key of the connected account in hex format with lead 0x.

Throws an error if the user did not allow access { error: number, message: string }:

  • code - error code, like 401
  • message - error message, like Access denied
js
try {
  const publicKey = await provider.publicKey();
  console.log(publicKey); // 0x797b0209c...15e63e
} catch (e) {
  console.log(e); // { code: 401, message: 'Access denied' }
}

provider.signAndSubmit(payload, ?options)

  • Type: function
  • Returning: Promise<{payload: EntryFunctionPayload, result: PendingTransaction}>
  • Arguments:
    • payload: EntryFunctionPayload see Aptos SDK docs
    • options: Not required tx options.
    • options.max_gas_amount: number - optional. The maximum gas value that will be used when sending a transaction. If the value is not set, the wallet will automatically simulate the transaction and take the amount of gas used + 20% to avoid minor changes in the cost of the transaction.
    • options.gas_unit_price: number - optional, default: 100. Gas price.
    • options.sequence_number: number - optional, default: current sequence_number + 1. The serial number of the transaction.
    • options.expiration_timestamp_secs: number - optional, default: Date.now() + 2 minutes. The amount of time after which the transaction will be considered expired.

Sign and send the payload transaction to the blockchain.
Returns object with properties:

  • payload - EntryFunctionPayload type. Payload that you passed as the first argument
  • result - PendingTransaction type. See Aptos SDK docs

Throws an error if the user did not allow access { error: number, message: string }:

  • code - error code, like 401
  • message - error message, like Access denied
js
const tx = {
  function: '0x1::coin::transfer',
  type_arguments: ['0x1::aptos_coin::AptosCoin'],
  arguments: [
    '0xeb442855143ce3e26babc6152ad98e9da7db7f0820f08be3d006535b663a6292',
    '100'
  ]
}

try {
  const result = await provider.signAndSubmit(tx)
} catch (e) {
  console.log(e);
}

⚡️ TypedArray support

You can also pass TypedArray objects such as Uint8Array, Int8Array objects as arguments.

js
const typedArgument = new Uint8Array([0x01, 0x02, 0x03, 0x04, 0x05])
const result = await provider.signAndSubmit({
  function: '0x1::coin::transfer',
  type_arguments: ['0x1::aptos_coin::AptosCoin'],
  arguments: [
    typedArgument,
    '100'
  ]
})

provider.signTransaction(payload, ?options)

  • Type: function
  • Returning: Promise<{ payload: EntryFunctionPayload, result: Uint8Array }>
  • Arguments:
    • payload: EntryFunctionPayload see Aptos SDK docs
    • options: Not required tx options.
    • options.sender: string - optional. Commonly used to generate multisig transactions.
    • options.max_gas_amount: number - optional. The maximum gas value that will be used when sending a transaction. If the value is not set, the wallet will automatically simulate the transaction and take the amount of gas used + 20% to avoid minor changes in the cost of the transaction.
    • options.gas_unit_price: number - optional, default: 100. Gas price.
    • options.sequence_number: number - optional, default: current sequence_number + 1. The serial number of the transaction.
    • options.expiration_timestamp_secs: number - optional, default: Date.now() + 2 minutes. The time when the transaction will be considered expired.

Sign the payload transaction.
Returns object with properties:

  • payload - EntryFunctionPayload type. Payload that you passed as the first argument
  • result - signature in Uint8Array object.

Throws an error if the user did not allow access { error: number, message: string }:

  • code - error code, like 401
  • message - error message, like Access denied
js
const tx = {
  function: '0x1::coin::transfer',
  type_arguments: ['0x1::aptos_coin::AptosCoin'],
  arguments: [
    '0xeb442855143ce3e26babc6152ad98e9da7db7f0820f08be3d006535b663a6292',
    '100'
  ]
}

try {
  const result = await provider.signTransaction(tx, { sender: '0xeb442855143ce3e26babc6152ad98e9da7db7f0820f08be3d006535b663a6292' })
} catch (e) {
  console.log(e);
}

⚡️ TypedArray support

It also supports arguments in the TypedArray view. See provider.signAndSubmit method

provider.signMessage(payload, ?options)

  • Type: function
  • Returning:
ts
Promise<{
  result: {
    address: false | string,
    application: false | string,
    chainId: false | string,
    fullMessage: string,
    message: string | Uint8Array,
    nonce: string,
    prefix: string,
    signature: string
  }
}>
  • Arguments:
    • payload: Object with specific properties.

    • payload.address: boolean - optional, default: false. If true, adds the signer address to the message.

    • payload.application: boolean - optional, default: false. If true, adds the name of the application to the message.

    • payload.chainId: boolean - optional, default: false. If true, adds the chainId of the current network to the message.

    • payload.message: string | Uint8Array - required. This is the message you want to be signed.

    • payload.nonce: string | number - a numeric value, required. This is a random nonce used to ensure that an otherwise identical message has a different signature.

    • options.useNewFormat: boolean - optional, default: false. The use of this parameter affects the order of the data when signing a message in Aptos.

      The order if options.useNewFormat is not specified:

      Address: 0x000001
      application: badsite.firebase.google.com
      chain_id: 7
      Message: Welcome to dapp!
      nonce: 1234034
      

      Order if options.useNewFormat is true

      Address: 0x000001
      chain_id: 7
      application: badsite.firebase.google.com
      nonce: 1234034
      Message: Welcome to dapp!
      

Forms and signs a message.
Returns object with properties:

  • result.address - if true is passed to payload.address, it will return the address of the signer, otherwise false.
  • result.application - if true is passed to payload.application, it will return the name of the application, otherwise false.
  • result.chainId - if true is passed to payload.chainId, it will return the chainId of the current network, otherwise false.
  • result.message - message from payload.message.
  • result.fullMessage - contains the complete message that was signed by the user.
  • result.nonce - nonce from payload.nonce.
  • result.prefix - special prefix for message signing. Always APTOS.
  • result.signature - signature of the signed message.

Throws an error if the user did not allow access { error: number, message: string }:

  • code - error code, like 401
  • message - error message, like Access denied
js
try {
  const message = 'Welcome to Pontem Wallet documentation'
  return await provider.value.signMessage({
    address: false,
    application: true,
    chainId: true,
    message,
    nonce: '123456'
  })
} catch (e) {
  console.log(e);
}

Example response:

js
{
  address: false
  application: "https://pontem.network"
  chainId: 1
  fullMessage: "APTOS\nchain_id: 1\napplication: https://pontem.network\nnonce: 123456\nmessage: Welcome to Pontem Wallet documentation"
  message: "Welcome to Pontem Wallet documentation"
  nonce: "123456"
  prefix: "APTOS"
  signature: "0xdc7bdd524d465e44d91ef07de3c7dcc26340e2d6b5078e6dbd46bf6f6e8744842d6a30d4a29fe16e864f15dfac5a8cd884abf8bc4eb9398e88a6efd3649ae808"
}

provider.switchNetwork(chainId)

  • Type: function
  • Returning:Promise<boolean>
  • Arguments:
    • chainId: Aptos chain id as number.

Available chainId:

  • Aptos Mainnet - 1.
  • Aptos Testnet - 2.
  • Aptos Devnet - 67.
  • Lumio - 100.

Throws an error if the user did not allow access { error: number, message: string }:

  • code - error code, like 401
  • message - error message, like Access denied

Throws an error if passed wrong chain id format { error: number, message: string }:

  • code - error code, like 422
  • message - error message, like Wrong chain id format

Example:

js
try {
  await provider.switchNetwork(2)
} catch (e) {
  console.log(e);
}

Example response:

js
true