0

I've been working on a front end for a project and have been trying to understand ethers. My problem is that I need to Mint a coin to the persons wallet who has chosen to mint it on the front end. I cannot get my head around how to accomplish this bc of ethers wallet creation. It requires a private key to create a wallet and a wallet is the only way that I have found to be able to sign transactions in ether and proceed with the transaction successfully. How would I create a wallet using the current connected metamask wallet to sign the transaction. I dont want to ask for their private key for security reasons. Is there something that I am missing?

const signer = provider.getSigner(accounts[0]);
    contract = contract.connect(signer);
    
    
    const estGas = await contract.estimateGas.AddToWhitelist(['0x353f4592E1f131CaC58c369fA9758ea37283DAf6'],['1']);
    const item = await contract.populateTransaction.AddToWhitelist(['0x353f4592E1f131CaC58c369fA9758ea37283DAf6'],['1']);
    item.gasLimit = estGas;
    item.gasPrice = await provider.getGasPrice();
    item.nonce = await provider.getTransactionCount(wallet.address);
    
    const signed = await signer.signTransaction(item);
    const submitted = await provider.sendTransaction(signed);
    const approveReceipt = await submitted.wait();

The above code is an example where the signer is not able to sign the transaction because of an error stating "signing transactions is unsupported".

1 Answer 1

0

in order to connect to MetaMask you should use:

const provider = new ethers.providers.Web3Provider(window.ethereum)
const signer = provider.getSigner()

take a look at the ethers doc

1
  • Ty for your help but that is not the problem at hand. I am able to get a signer just fine. The problem is that a signer does not seem able to sign a transaction when I attempt to do so, instead it gives me a message "signing transactions is unsupported" when using "signer.signTransaction()". creating a wallet is the only way that has worked for me to sign transactions. Sep 22, 2022 at 14:25

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.