INFURA / infura

Official Public Repository for INFURA
https://infura.io
381 stars 62 forks source link

InfuraProvider signer's PRIVATE_KEY confussion #229

Open Mrbeyond opened 1 year ago

Mrbeyond commented 1 year ago

This is not an issue actually, I only need help with clarification on InfuraProvider and I can't find discussion option here.

I am just into web3 and I have to connect to the sepolia testnest through Infura. I have the contract address and the ABI ready, I am using ethers.js and metamask.

There's a confusion on what I have seen so far on the implementation.

I can deduce that I have two ways on connecting to the contract.

1) Using metamask and WebBroswerProvider of ethers.js v6 2) Uing ethers.js InfuraProvider:

I have implemented the first (WebBroswerProvider or Web3Provider) method now, I can access the current user's account and I have implemented a contract implementation:

  await window.ethereum.enable(); // Initiate metamask        
    const provider = new ethers.BrowserProvider(window.ethereum);
    const signer = await provider.getSigner();

    const contract = new ethers.Contract(PUBLIC_FACTORY_ADDRESS, contractABI, signer);

There is confusion on the second method (InfuraProvider) about the PRIVATE_KEY and its signer:

const infuraProvider = new ethers.InfuraProvider("sepolia", INFURA_API_KEY); //v6 const privateKey = 'YOUR_PRIVATE_KEY'; //Here is the confusion, const signer = new ethers.Wallet(privateKey, provider); const contract = new ethers.Contract(contractAddress, contractABI, signer);

The real concern now is that, I can personally get the private key of my wallet account and test use it like in the last snippet. But if users come to the platform, they would definitely not be doing that, how would the private be gotten the current user if the InfuraProvider is to be used, so as to create a signer for the contract?

Please I need clarifications here, I might not be able to explain clearly or missed the concept, please help clarify everything, what I basically need help with is how to connect to sepolia testnest using InfuraProvider. Thanks