Get started with DSA Connect by initializing the SDK, creating a Smart Account, and executing your first DeFi transaction
This guide will help you initialize DSA Connect, create a Smart Account, and execute your first transaction. By the end, you’ll have a working DSA integration.
First, set up your Web3 instance based on your environment:
Browser
Node.js
import Web3 from 'web3';// Connect to MetaMask or other Web3 walletif (window.ethereum) { window.web3 = new Web3(window.ethereum); // Request account access 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);}
const Web3 = require('web3');const DSA = require('dsa-connect');// Connect to Ethereum nodeconst web3 = new Web3( new Web3.providers.HttpProvider('https://eth-mainnet.g.alchemy.com/v2/YOUR_API_KEY'));
Initialize DSA with your Web3 instance and chain ID:
Browser
Node.js
Simulation Mode
import DSA from 'dsa-connect';// Simple browser initializationconst dsa = new DSA(web3);// Or with specific chain ID (1 = Ethereum Mainnet)const dsa = new DSA(web3, 1);
// Get account countconst count = await dsa.count("0xYourAddress");// Get max uint256 value (for approvals)const maxValue = dsa.maxValue;// Set origin for analyticsdsa.setOrigin("0xOriginAddress");// Encode spells without executingconst encodedData = await dsa.encodeSpells({ spells });// Estimate gas for transactionconst gasEstimate = await spells.estimateCastGas();