Mobile Dapp Provider

Sender injects a global JavaScript API into websites visited by its users using the window.sender.ton provider object. This API allows websites to request users' Ton accounts, read data from blockchains the user is connected to, and suggest that the user sign messages and transactions.

Properties

deviceInfo

Developer can get deviceInfo from window.sender.ton object.

// Some code
export declare interface DeviceInfo {
  platform: 'iphone' | 'ipad' | 'android' | 'windows' | 'mac' | 'linux' | 'browser';
  appName: string;
  appVersion: string;
  maxProtocolVersion: number;
  features: Feature[];
}

protocolVersion

This is protocol version number, and current protocol version is 2

isWalletBrowser

Check current Provider API if it's wallet browser, the default value is true

Methods

connect

// Connect method
interface TonAddressItem {
  name: 'ton_addr';
}

interface TonProofItem {
  name: 'ton_proof';
  payload: string;
}

type ConnectItem = TonAddressItem | TonProofItem;

interface ConnectEventError {
    event: 'connect_error';
    id: number;
    payload: {
        code: CONNECT_EVENT_ERROR_CODES;
        message: string;
    };
}

interface ConnectEventSuccess {
    event: 'connect';
    id: number;
    payload: {
        items: ConnectItemReply[];
        device: DeviceInfo;
    };
}

type ConnectEvent = ConnectEventSuccess | ConnectEventError;

export declare interface ConnectRequest {
  manifestUrl: string;
  items: ConnectItem[];
}

const protocolVersion = 2;

const request = {
  items: [{ name: 'ton_addr' }],
  manifestUrl: 'https://megaton.fi/tonconnect-manifest.json?v=1',
};

await window.sender.ton.connect(protocolVersion, request);

The third dapp can use connect method to connect Sender Wallet. And this method will respond a ConnectEvent object.

restoreConnection

// Example
await window.sender.ton.restoreConnection();

This method can restore app connection automatically if dapp is connected before, so that user don't need to connect dapp again. And this method will respond a ConnectEvent object.

disconnect

// Disconnect dapp
await window.sender.ton.disconnect();

send

// Send transaction by wallet
interface SendTransactionRpcRequest {
  method: 'sendTransaction';
  params: [string];
  id: string;
}

interface SignDataRpcRequest {
  method: 'signData';
  params: [
    {
      schema_crc: number;
      cell: string;
    }
  ];
  id: string;
}

interface DisconnectRpcRequest {
  method: 'disconnect';
  params: [];
  id: string;
}

type RpcRequests = {
  sendTransaction: SendTransactionRpcRequest;
  signData: SignDataRpcRequest;
  disconnect: DisconnectRpcRequest;
};

type RpcMethod = 'disconnect' | 'sendTransaction' | 'signData';

const request = {
  sendTransaction: { ... },
  signData: { ... },
  disconnect: { ... },
}

await window.sender.ton.send(request);

This method can be used as sendTransaction or signData method, and dapp can use send method to send transaction or sign data.

Last updated