Initialize the ArgentTMA object with your app configuration:
constargentTMA=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:
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:
constisConnected=argentTMA.isConnected();
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.
useEffect(() => {// Call connect() as soon as the app is loaded argentTMA.connect().then((res) => {if (!res) {// Not connectedsetIsConnected(false);return; }const { account,callbackData } = res;if (account.getSessionStatus() !=="VALID") {// Session has expired or scope (allowed methods) has changed// A new connection request should be triggered// The account object is still available to get access to user's address// but transactions can't be executedconst { account } = res;setAccount(account);setIsConnected(false);return; }// The session account is returned and can be used to submit transactionssetAccount(account);setIsConnected(true);// Custom data passed to the requestConnection() method is available hereconsole.log("callback data:", callbackData); }).catch((err) => {console.error("Failed to connect", err); }); }, []);
6. Interact with Starknet using the account
You can interact with your contracts using starknet.js. For instance, you could do this: