First, initialize a Web3 instance connected to the user’s wallet:
// Using MetaMask or other injected walletif (window.ethereum) { window.web3 = new Web3(window.ethereum) await window.ethereum.request({ method: 'eth_requestAccounts' })} else if (window.web3) { window.web3 = new Web3(window.web3.currentProvider)} else { // Fallback to custom provider window.web3 = new Web3(customProvider)}
2
Initialize DSA
Create a DSA instance with your Web3 instance:
import { DSA } from 'dsa-connect'const dsa = new DSA(web3)
In browser mode, the SDK automatically uses the connected wallet to sign transactions.
3
Specify Chain ID (Optional)
By default, DSA Connect uses Ethereum Mainnet (Chain ID 1). To use a different chain:
// Polygonconst dsa = new DSA(web3, 137)// Arbitrumconst dsa = new DSA(web3, 42161)// Optimismconst dsa = new DSA(web3, 10)