Provider API

Introduce

By accessing the ton provider, you will get a tonconnect object:

const tonConnect = window.naboxTon.tonconnect();

interface TonConnectBridge {
    deviceInfo: DeviceInfo;
    walletInfo?: WalletInfo;
    protocolVersion: number;
    connect(protocolVersion: number, message: ConnectRequest): Promise<ConnectEvent>;
    restoreConnection(): Promise<ConnectEvent>;
    send(message: AppRequest): Promise<WalletResponse>;
    listen(callback: (event: WalletEvent) => void): () => void;
};

deviceInfo (device information)

{
    platform: 'browser', // Current Environment
    appName: 'Nabox Wallet', // wallet
    appVersion: '1.2.19', // Current version number
    maxProtocolVersion: 2, // Supported protocol types, currently 2
    features: [ // Features currently supported by the wallet
      'SendTransaction',
      {
        name: 'SendTransaction',
        maxMessages: 4,
      },
    ],
}

walletInfo(wallet info)

{
    name: 'Nabox Wallet', // wallet name
    app_name: 'naboxTon', // wallet symbol
    image: '', // wallet logo
    about_url: '', // wallet introduce
    platforms: ['chrome'] // Currently supported platforms
}

protocolVersion

Currently supported protocol versions

connect(connect wallet)

const protocolVersion = 2;
const connectItems = { name: 'ton_addr' }; // Connect to the wallet and get the current address
const connectItems1 = { name: 'ton_proof', payload: 'hello' }; // Signing Messages

const messgae = {
    manifestUrl: 'https://example.com/manifest.json';
    items: [connectItems, connectItems1]
};
// Only obtain the user's address, public key and other information:
const result = await naboxTon.tonconnect.connect(protocolVersion, {
    manifestUrl: 'https://example.com/manifest.json',
    items: [connectItems]
})

if (result.event === 'connect') {
    console.log(result.payload.items[0].address)
} else {
    console.log(result.payload.message)
}
// Get the user address, public key and other information, and verify the wallet signature:
const result1 = await window.okxTonWallet.tonconnect.connect(protocolVersion, {
    manifestUrl: 'https://example.com/manifest.json',
    items: [
        connectItems,
        connectItems1
    ]
})

if(result.event === 'connect') {
    console.log(result1.payload.items[0].address)
    console.log(result1.payload.items[1].proof)
} else {
    console.log(result1.payload.message)
}

restoreConnection (restore connection, often used for a second connection after a previous connection)

const result = await window.okxTonWallet.tonconnect.restoreConnection();

if(result.event === 'connect') {
    console.log(result.payload.items[0].address)
} else {
    console.log(result.payload.message)
}

send(send transaction/disconnect)

const message = {
    method: ''; // Method Name
    params: []; // Method Parameters
    id: '1'; // Incremental ID
};

// sendTransaction message success
const { boc, id } = window.naboxTon.send({
    method: 'sendTransaction',
    params: [<transaction-payload>],
    id: '1'
});
// sendTransaction message failed
const { error, id } = window.naboxTon.send({
    method: 'sendTransaction',
    params: [<transaction-payload>],
    id: '1'
});

// disconnect message success
const { result, id } = window.naboxTon.send({
    method: 'disconnect',
    params: [],
    id: '1'
});
// disconnect message failed
const { error, id } = window.naboxTon.send({
    method: 'disconnect',
    params: [],
    id: '1'
});

listen

interface WalletEvent {
    event: WalletEventName;
    id: number; 
    payload: <event-payload>; // parameter
}

type WalletEventName = 'connect' | 'connect_error' | 'disconnect';

// Returns a function to cancel the monitoring.

Last updated