Home

Connect to truffle dashboard using ethers.js

Truffle dashboard

Truffle dashboard helps you to connect any application on your computer to the metamask in your favorite browser. When ran, it will create a webserver and deploys a website on localhost, using which you can connect your metamask wallet.

For more info on installation and setup, visit

Connecting with ethers.js

The following code assumes that your truffle dashboard runs on the port 24012

import { ethers } from "ethers";

const DASHBOARD_PROVIDER_RPC = "http://localhost:24012/rpc"

async function main() {
  const provider = new ethers.providers.JsonRpcProvider(DASHBOARD_PROVIDER_RPC);

  const signer = provider.getSigner();

  const accounts = await provider.listAccounts();
  console.log(accounts);

  // do something with `signer` or `provider` ...
}

main()

Use the following code to get an instance of a smart contract

import { ethers } from "ethers";

const instance = new ethers.Contract(address, abi, signerOrProvider)

Are you using web3.js

Try the following (code not tested)

var provider = new Web3(new Web3.providers.HttpProvider('http://localhost:7545'));

Prefer using ethers.js



Last Updated on

Next Post: Rules vs Guidelines →

Comments