1

I have designed a contract deployed on the Rinkeby with web3. I have also implemented a react app to interact with the blockchain. I want to use my application without metamask but I got this error in Chrome "No "from" address specified in neither the given options, nor the default options." when I try to send a transaction like this:

await tracker.methods
      .createAsset(name, description, manufacturer, price)
      .send({
        from: accounts[0],
        value: web3.utils.toWei(this.state.amountToStake, "ether"),
        gas: "1000000"
      });

Based on the code below can someone tell what I am doing wrong?

web3 script:

import Web3 from "web3";
let web3; 
const provider = new Web3.providers.HttpProvider( // creating my own provider
"https://rinkeby.infura.io/v3/..."
);
web3 = new Web3(provider);

export default web3;

deploy script:

const HDWalletProvider = require("truffle-hdwallet-provider");
const Web3 = require("web3");

const compiledTracker = require("./build/AssetTracker.json");

const provider = new HDWalletProvider("mnemonic",
 "https://rinkeby.infura.io/v3/...");

const web3 = new Web3(provider);

const deploy = async () => {
const accounts = await web3.eth.getAccounts();


const result = await new web3.eth.Contract(
JSON.parse(compiledTracker.interface))
    .deploy({ data: compiledTracker.bytecode })
    .send({ gas: "2000000", from: accounts[0] });

Note: Everything was working fine with MetaMask but I need to send a transaction without MetaMask that's why I defined a provider with Rinkeby.

1 Answer 1

1

You are using a direct connection to Infura.

const provider = new Web3.providers.HttpProvider( // creating my own provider
    "https://rinkeby.infura.io/v3/..."
);
web3 = new Web3(provider);

Infura doesn't provide account management. If you want to use Infura and create transaction in the client side you have to use a library to sign transaction.

You can use HDWalletProvider that will use the wallet derived from the mnemonic. For example your deploy script should work fine.

const provider = new HDWalletProvider("mnemonic", "https://rinkeby.infura.io/v3/...");
const web3 = new Web3(provider);
3
  • @Ismael if I don't use metamask or Infura, what can I do? Is it possible to use a private node and send a transaction?
    – EMANUEL
    Feb 4, 2021 at 19:33
  • @EMANUEL Yes, you can run your own ethereum client like geth, openethereum, besu, etc. In any case it is better to ask a separate question for that kind of issues.
    – Ismael
    Feb 5, 2021 at 13:06
  • If you run into any dependency issue trying to implement the HDWalletProvider, you can try the @truffle/hdwallet-provider
    – Ebuka
    Jun 2, 2022 at 10:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.