Sui Provider (Beta)

The Tomo Telegram SDK provides the SUI provider for getting addresses, signing, and sending transactions.

// get provider 
const sui= window.tomo_sui;

Connect with the Wallet

Before using the provider, the user needs to log in to the wallet through the modal by following the method:

// connect wallet
await sui?.connectWallet();

Query Address

You can get the address of the user by one cal

const address = sui.getAddress();

Signing Methods

In Solana providers, we provide three signing methods:

  • signMessage

  • signTransaction

  • signAndExecuteTransaction

Sign message

signMessage method will create a simple signed transaction for one message and return the signed transaction in hex.

 const response = await sui.signMessage(signMsg);

Sign transaction

signTransaction supports signing arbitrary PTB transactions if they are well formed. Please check this for the general construction of transactions. We provide two examples:

// define transaction body
export const getSendSuiCoinTx = async ({
  fromAddress,
  toAddress,
  amount,
  coinType,
}: {
  fromAddress: string;
  toAddress: string;
  amount: string;
  coinType?: string;
}): Promise<{ transaction: string; bytes: Uint8Array } | null> => {
  const suiClient = getSuiClient();
  const txb = new Transaction();
  
  txb.transferObjects(
    [coinWithBalance({ balance: Number(amount), type: coinType || undefined })],
    toAddress
  );
  
  try {
    txb.setSender(fromAddress);
    const transaction = (await txb.toJSON({ client: suiClient })).toString();
    const bytes = await txb.build({ client: suiClient });
    console.log('bytes', transaction, bytes);
    return { transaction, bytes };
  } catch (e) {
    console.warn(e);
    return null;
  }
};

// create transaction body for concrete transaction
const res = await getSendSuiCoinTx({
  fromAddress: addr,
  toAddress: toAddr2,
  amount: +toValue2 * 10 ** 6 + '',
  coinType: contractAddr,
});

// create transaction
const { transaction, bytes } = res || {};

const input = {
  transactionBlock: transaction,
  chain: 'sui:mainnet',
  txBytes: bytes,
  options: {
    showEffects: true,
  },
};

// sign transaction
const signed transaction= await sui.signTransaction(input);

// or you can use sign and send transaction at the same time

const res = await sui.signAndExecuteTransaction(input);

After signing the transaction, you can send it to your client or add other signatures. In addition, you can use signAndExecuteTransaction the method to send the signed transaction directly.

Last updated