Session keys and permissions provide a secure way to allow applications to perform actions on behalf of users without requiring constant authentication. This is particularly useful for games and applications that need to execute transactions automatically.
interface Permissions { approvedTargets: string[]; // Contract addresses startDate: Date; // When permissions become active endDate: Date; // When permissions expire nativeTokenLimitPerTransaction: number; // ETH limit per tx // Additional ERC-20 token limits can be added}
For gaming applications, you might need broader permissions:
Copy
Ask AI
function GamePermissions() { const gamePermissions = { approvedTargets: [ "0x...", // Game contract "0x...", // NFT marketplace "0x...", // Token contract ], startDate: new Date(), endDate: new Date(Date.now() + 7 * 24 * 60 * 60 * 1000), // 7 days nativeTokenLimitPerTransaction: 0.001, // Small ETH limit for gas }; return ( <div className="game-permissions"> <h3>Grant Game Permissions</h3> <p>Allow this game to perform actions on your behalf for 7 days</p> <RequestPermissionsButton chain={b3Chain} sessionKeyAddress="0x..." permissions={gamePermissions} onSuccess={() => { // Redirect to game or update UI console.log("Game permissions granted!"); }} onError={(error) => { console.error("Failed to grant game permissions:", error); }} /> </div> );}