Implementation

SDK implementation guide.

1. Import dependencies in your project

import { ArgentTMA, SessionAccountInterface } from '@argent/tma-wallet';

2. Initialize the ArgentTMA object

Initialize the ArgentTMA object with your app configuration:

const argentTMA = ArgentTMA.init({
  environment: "sepolia", // "sepolia" | "mainnet" (Whitelisting required)
  appName: "My TG Mini Test Dapp", // Your Telegram app name
  appTelegramUrl: "<https://t.me/my_telegram_bot/app_name>", // Your Telegram app URL
  sessionParams: {
    allowedMethods: [
      // List of contracts/methods allowed to be called by the session key
      {
        contract:
          "0x036133c88c1954413150db74c26243e2af77170a4032934b275708d84ec5452f", // contract address
        selector: "increment", //function selector
      }
    ],
    validityDays: 90 // session validity (in days) - default: 90
  },
});

3. Request a connection

If the user is not connected, call the requestConnection() method to open the wallet and ask the user to approve the connection. At the same time, you can ask user for token approvals:

The wallet will redirect back to your app and the account will be available from the connect() method.

4. Check connection status

You can check if the user is connected at any time using the isConnected() method:

5. Connect to the wallet

Call the connect() method when your app loads to check if the user is already connected. It is also used to fetch the account object. It is an extended starknet.js account object.

For instance, you could wrap this in a useEffect hook.

6. Interact with Starknet using the account

You can interact with your contracts using starknet.js. For instance, you could do this:

7. Check account session status

8. Request approval

It is possible to ask to user to sign new approval transactions with requestApprovals().

9. Clear session

Calling clearSession removes the session object from local storage. It is mostly used for debugging. The session would still be valid on-chain.

We could imagine doing something like this:


List of useful ressources:

Last updated

Was this helpful?