π§© 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:
User types a command:
βDeploy a token called StarCoin.β
Bot responds:
βPlease connect your wallet to proceed with deployment.β
Using
ethers.providers.Web3Provider(window.ethereum), the bot:Requests wallet connection via
eth_requestAccountsRetrieves the userβs Ethereum address
Detects the active chain ID (e.g., Goerli, Mainnet)
Instantiates a signer via
provider.getSigner()
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:
Artifacts Required:
ABIBytecode
Create Factory:
Deploy:
Track Result:
contract.addresstransaction.hashNetwork and gas used
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 returnsECO: 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:
Create contract with signer:
Prepare and send transaction:
Handle result:
Return
tx.hash, block numberReport success/failure to user
Supported Actions:
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