Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

InfuraProvider signer's PRIVATE_KEY confussion #229

Open
Mrbeyond opened this issue Jul 19, 2023 · 0 comments
Open

InfuraProvider signer's PRIVATE_KEY confussion #229

Mrbeyond opened this issue Jul 19, 2023 · 0 comments

Comments

@Mrbeyond
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant