🧩 Functional Roles of ethers.js in Dialect AI

πŸ” 1. Wallet Integration

Dialect AI uses ethers.js to facilitate user wallet connections in the browser via:

  • MetaMask (browser extension)

  • WalletConnect (mobile wallets via QR)

  • Injected Web3 Providers (e.g., Brave, Coinbase Wallet)

Workflow:

  1. User types a command:

    β€œDeploy a token called StarCoin.”

  2. Bot responds:

    β€œPlease connect your wallet to proceed with deployment.”

  3. Using ethers.providers.Web3Provider(window.ethereum), the bot:

    • Requests wallet connection via eth_requestAccounts

    • Retrieves the user’s Ethereum address

    • Detects the active chain ID (e.g., Goerli, Mainnet)

    • Instantiates a signer via provider.getSigner()

  4. The signer is stored in memory for secure transaction signing during the session.


πŸ—οΈ 2. Smart Contract Deployment

When a Solidity contract is compiled (via solc-js), ethers.js is used to deploy it using the signer’s wallet.

Process:

  1. Artifacts Required:

    • ABI

    • Bytecode

  2. Create Factory:

  3. Deploy:

  4. Track Result:

    • contract.address

    • transaction.hash

    • Network and gas used

  5. Bot response to user:

    βœ… β€œYour contract has been deployed at: 0xAbc...DEF Transaction Hash: 0x123...789”


πŸ“– 3. Calling View / Pure Functions

For read-only operations like balance checks, token metadata, or event queries, the bot uses ethers.Contract with a connected provider (no signing required).

Examples:

These calls:

  • Are instantaneous (from RPC)

  • Require no gas

  • Do not prompt the user to sign

Example Commands:

β€œWhat’s my balance of ECO tokens?” β†’ Calls balanceOf(address) and returns ECO: 10,000


πŸ’Έ 4. Sending Transactions (Write Functions)

For state-changing operations like transfer(), mint(), or DAO vote() commands, ethers.js allows Dialect AI to send signed transactions via the connected wallet.

Steps:

  1. Create contract with signer:

  2. Prepare and send transaction:

  3. Handle result:

    • Return tx.hash, block number

    • Report success/failure to user

Supported Actions:

Action
Function Called

Transfer tokens

transfer(address,uint256)

Mint tokens

mint(address,uint256) (if enabled)

Approve spending

approve(spender, amount)

Send ETH

signer.sendTransaction({...})

Interact with dApps

Custom function calls to other contracts

Last updated