import { ArgentWebWallet, SessionAccountInterface } from 'webwallet-sdk';
3. Initialize the web wallet object with your app configuration:
const argentWebWallet = ArgentWebWallet.init({
environment: "sepolia", // "sepolia" | "mainnet" (Whitelisting required)
appName: "My App", // Your app name
sessionParams: {
allowedMethods: [
// List of contracts/methods allowed to be called by the session key
{
contract:
"0x036133c88c1954413150db74c26243e2af77170a4032934b275708d84ec5452f", // contract address
selector: "increment", //function selector
}
],
validityDays: 90 // optional - session validity (in days) - default: 90
},
});
To use session keys on mainnet, you will need to whitelist your contract with us. Please reach out.
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:
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(() => {
argentWebWallet
.connect() // call connect as soon as the app is loaded
.then((res) => {
if (!res) {
console.log("Not connected");
return;
}
console.log("Connected to Argent Web Wallet", res);
const { account, callbackData, approvalTransactionHash } = res; // extract useful objects
if (account.getSessionStatus() !== "VALID") {
console.log("Session is not valid");
return;
}
setAccount(account);
console.log("Callback data", callbackData); // -- custom_callback_string
console.log("Approval transaction hash", approvalTransactionHash); // -- custom_callback_string
})
.catch((err) => {
console.error("Failed to connect to Argent Web Wallet", err);
});
}, []);
6. Interact with Starknet using the account
You can interact with your contracts using starknet.js. For instance, you could do this:
Calling clearSession removes the session object from local storage. It is mostly used for debugging. The session would still be valid on-chain. In terms of UX, this pretty much looks like a disconnect feature.