Installation

npm install @oberton/sdk

Include from CDN

<script src="https://cdn.jsdelivr.net/npm/@oberton/sdk@1.0.7/docs/index.js"></script>

Use

import Oberton from '@oberton/sdk';

// if use CDN script, Oberton is accesible over window.Oberton

const optionalOptions = {
  skipPromoDialog: false, // show dialog with the link to webstore, if user doesn't have the Oberton extension installed
};

const oberton = new Oberton('net.ton.dev', optionalOptions);

Send Tokens

returns tmpId{String}, that is passed as an argument, when transaction sent or failed

oberton.sendTokens({
  to: '0:dc5612b47ef94b8eed1358f2d118757c66e2a120e9d3e623b148710a50661f20',
  amount: 0.5,
});

Send Tokens With Comment

oberton.sendTokens({
  to: '0:dc5612b47ef94b8eed1358f2d118757c66e2a120e9d3e623b148710a50661f20',
  amount: 0.5,
  payloadType: 'comment',
  comment: 'Hello World',
});

Send Tokens With Custom Function

oberton.sendTokens({
  to: '0:dc5612b47ef94b8eed1358f2d118757c66e2a120e9d3e623b148710a50661f20',
  amount: 0.5,
  payloadType: 'function',
  functionName: 'someFunctionName',
  abiJSON: '{...}',
  functionParams: '{...}',
});

Send Tokens With Payload

oberton.sendTokens({
  to: '0:dc5612b47ef94b8eed1358f2d118757c66e2a120e9d3e623b148710a50661f20',
  amount: 0.5,
  payloadType: 'payload',
  payload: '...',
});

Destroy

Destroys oberton instance, with all related event listeners

oberton.destroy();

Events

  • error - any error, related to interaction with extension, most common is when extension not installed, and {skipPromoDialog: true} promo dialog is hidden
  • transactionSent - when transaction initiated by oberton.sendTokens has been sent, callback argument provides transaction details
  • transactionFailed - for some reason, transaction is failed to be sent, callback argument provides fail details
import Oberton from '@oberton/sdk';

const oberton = new Oberton();

oberton

  /* extension is not installed or unreacheable
   * or transaction failed to sent */
  .on('error', (data) => console.log('error', data))

  /* transaction has been sent */
  .on('transactionSent', (data) => console.log('transactionSent', data)) // transactionSent, provides details from the @tonclient SDK

  /* transaction failed */
  .on('transactionFailed', (data) => console.log('transactionFailed', data))

  /* any response from an extension, included errors and transactions events */
  .on('response', (data) => console.log('response', data));

oberton.sendTokens({
  to: '0:4b0cc91b506e5cff29eb1cb64f0b543e0d15ac6e3a3743ec462a711abbc7aa36',
  amount: 0.5,
  payloadType: 'comment',
  comment: 'Hello World2',
});