0

I am developing a Web3 App using Solidity, smart contract is working perfect, after deploying it to web server, The app is working flawless on my PC but I faced an issue on my browsers that don't have Metamask wallet.

Error:

Error: Provider not set or invalid
at Object.InvalidProvider (errors.js:39:16)
at f.send (index.js:145:32)
at s (index.js:624:42)
at a.n [as getId] (index.js:656:13)
at Web3Client.js:197:39
at f (regeneratorRuntime.js:86:17)
at Generator._invoke (regeneratorRuntime.js:66:24)
at Generator.next (regeneratorRuntime.js:117:21)
at Ne (asyncToGenerator.js:3:20)
at a (asyncToGenerator.js:25:9)

React Code:

export const init = async () => {
    let provider = window.ethereum;
    if (typeof provider !== 'undefined') {
    }
    const web3 = new Web3(provider);
    const networkId = await web3.eth.net.getId();
    erc20Contract = new web3.eth.Contract(
        erc20Abi,
        addr
    );
    isInitialized = true;
};

What is the best and minimal way to interact with Smartcontracts without Wallet?

1 Answer 1

0

Metamask uses infura for communicating with the ethereum blockchain. If you add a new network, you have to give to it an RPC provider. So, basically, you can directly use an RPC provider instead of metamask:

export const init = async () => {
    const web3 = new Web3("https://somerpcprovider.com/");
    const networkId = await web3.eth.net.getId();
    erc20Contract = new web3.eth.Contract(
        erc20Abi,
        addr
    );
    isInitialized = true;
};
0

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.