Authentication

Authenticating (connecting wallets) with a Stacks-supported wallet is a common task when building Stacks apps. On a web2 app, authentication usually means sending credentials to a central provider, which then verifies you and controls access. In web3, authentication uses a wallet and cryptographic signatures with libraries like stacks.js, letting users prove identity without a central party holding the keys.
Below is a simple example showing how to set up front-end authentication with @stacks/connect and access user data in the UI. The stacks.js monorepo contains several underlying packages specific to different use cases. The package @stacks/connect is the main connectivity package used in Stacks.
Authentication on the frontend
Using @stacks/connect on the frontend will allow our frontend app to authenticate wallets, call our contract functions, and interact with the Stacks network.
In the snippet below, you'll notice we have 3 functions setup to handle connectWallet , disconnectWallet, and for getBns . All 3 functions will be integral in how we want to display the 'Connect' and 'Disconnect' button in the UI.
The connect() method comes with the ability to configure how you want the wallet selector modal to appear for your app. You can decide which wallets to have only appear as an option or allow any wallet that follows the SIP-030 standard to appear as an available Stacks wallet.
For the complete guides check out the Stacks Connect section.
Last updated
Was this helpful?
