Skip to main content

Description

The build() method creates a new DSA (DeFi Smart Account) on the blockchain. This method deploys a new smart contract wallet that can interact with various DeFi protocols through the Instadapp ecosystem.

Syntax

await dsa.build(params: BuildParams)

Parameters

params
BuildParams
required
Configuration object for building a new DSA account

Returns

Returns a transaction object containing the transaction hash and receipt information.

Example Usage

Browser Mode

import DSA from "dsa-connect";
import Web3 from "web3";

const web3 = new Web3(window.ethereum);
const dsa = new DSA(web3, 1); // 1 for Ethereum mainnet

// Build a new DSA with default settings
const transaction = await dsa.build({
  from: "0x...", // Your wallet address
});

console.log("DSA created! Transaction hash:", transaction.hash);

Node Mode

import DSA from "dsa-connect";
import Web3 from "web3";

const web3 = new Web3("https://mainnet.infura.io/v3/YOUR_INFURA_KEY");
const dsa = new DSA(
  {
    web3: web3,
    mode: "node",
    privateKey: "YOUR_PRIVATE_KEY",
  },
  1
);

// Build a new DSA with custom authority
const transaction = await dsa.build({
  from: "0x...",
  authority: "0x...", // Address that will control the DSA
  origin: "0x...", // Your app's address for analytics
  version: 2,
  gas: 1000000,
  gasPrice: web3.utils.toWei("50", "gwei"),
});

console.log("DSA created! Transaction hash:", transaction.hash);

With Callbacks

const transaction = await dsa.build({
  from: "0x...",
  onReceipt: (receipt) => {
    console.log("Transaction confirmed!", receipt);
  },
  onConfirmation: (confirmationNumber, receipt) => {
    console.log(`Confirmation ${confirmationNumber}`, receipt);
  },
});

Custom Authority and Version

// Create a DSA where a different address has authority
const transaction = await dsa.build({
  from: "0xYourAddress...",
  authority: "0xAuthorityAddress...", // This address will control the DSA
  version: 2,
});

Notes

  • The from address pays for the transaction gas fees
  • The authority address will have control over the DSA and can execute spells
  • By default, if no authority is specified, the from address becomes the authority
  • Version 2 is the recommended and default version for new DSAs
  • After building a DSA, you can set it as the active instance using dsa.setInstance(id)
  • The origin parameter is useful for tracking which dApp or service created the DSA for analytics purposes

Error Handling

try {
  const transaction = await dsa.build({
    from: "0x...",
  });
  console.log("DSA created successfully!");
} catch (error) {
  console.error("Failed to create DSA:", error.message);
}

Build docs developers (and LLMs) love