1

I've finished my dapp by deploying the contract to Remix, and it works well in Ganache.

Now I wanna connect my dapp to Rinkeby by web3.js. I deployed my contract in Remix, and when I wanna interact with contract, the metamask show the page of paying.

However, when I connect metamask to my dapp page and interact with contract by it, the paying page of metamask didn't show up.

And I also use metamask legacy-web3, the console shows:

enter image description here

I've confused of where should I deploy it, and how to connect it? Should I deploy my contract by geth rather than Remix?

the following is my code of web3.js

// Initialize Web3
web3 = new Web3(web3.currentProvider);

// Set Account
web3.eth.defaultAccount = 'my account on metamask';

// Set Contract Abi
var ABI = [abi];

// Set Contract Address
var contractAddress = 'the address I deployed in Remix';

// Set the Contract
var contract = new web3.eth.Contract(ABI, contractAddress);

1 Answer 1

2

In Contracts folder in Remix, make a new file (By clicking on Contracts folder and then clicking on folders above paper shaped icon).

Copy your contract and paste it in the file you made.

Compile the contract.

Change network of Metamask into Rinkeby.

In deployment page, instead of JavaScript VM (London) use Injected Web3. If it does not work, unlock Metamask and try it again.

Now just deploy the contract and wait for confirmation.

Edit:

I don't know much about web3.js (I use ethers.js) but it should be something like this:

const startFunction = async () => {
    await ethereum.request({ method: 'eth_requestAccounts'});
    await ethereum.request({ method: 'wallet_switchEthereumChain', params:[{chainId: '0x4'}]});
    web3.setProvider(window.ethereum);
}
startFunction();
6
  • I've create new file and deploy it in the same way and install metamask legacy-web3, but I encountered the same problem. The paying page not appeared. Maybe there's another function or module I need to add to make it interact with metamask?
    – ginwei
    Commented Sep 18, 2021 at 8:28
  • No, on Remix you do not need any other modules or functions. It is automatic. Commented Sep 22, 2021 at 13:23
  • what I wanna do is to connect the html web and my contract on remix. The problem I faced now is that my html web can't connect to the contract. My remix has connected to metamask but the web hasn't.
    – ginwei
    Commented Sep 27, 2021 at 7:20
  • I can't figure exactly what you want to do and what you mean by 'My remix has connected to metamask but the web hasn't'. Do you have a website and you want to connect it to Remix?! Commented Sep 27, 2021 at 8:19
  • I wanna let my web to connect to the contract on Remix, and I can interact with my contract by metamask(when I need to pay the gas, the metamask will jump out to ask me whether I wanna pay for it).
    – ginwei
    Commented Oct 4, 2021 at 0:27

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.