Request prompt for transaction confirmation [HELP]

How do I request a user to send eth from an account via a prompt in MetaMask? Example: I have wallet A and wallet B, how do I request wallet B to send some eth to wallet A using a MetaMask prompt

This is what I have till now:

const ethers = require(‘ethers’);

// Infura Sepolia testnet endpoint
const providerUrl = ‘XXXXX’;
const provider = new ethers.JsonRpcProvider(providerUrl);

const privateKey = ‘xxxxxxxxxxxxxxxxxx’;
const walletA = new ethers.Wallet(privateKey, provider);

const amountToRequest = ethers.parseEther(‘0.00000003’);
const walletB = ‘0x154B2676Fcd23601cef1d7983e7fcD3Eeb61c940’;

// Get the next nonce for Wallet A
provider.getTransactionCount(walletA.address)
.then((nonce) => {
const txRequest = {
to: walletB,
value: 0, // Set value to 0 to request Ether
nonce: nonce,
data: ethers.hexlify(ethers.toUtf8Bytes(Please send ${ethers.formatEther(amountToRequest)} ETH)), // Optional data field
gasLimit: 50000, // Increase the gas limit
};

return walletA.sendTransaction(txRequest);

})
.then(async (tx) => {
console.log(‘Request sent:’, tx.hash);
const resolvedTx = await ethers.resolveProperties(tx);
console.log(‘Resolved Transaction:’, resolvedTx);
const receipt = await tx.wait();
console.log(‘Request confirmed:’, receipt.transactionHash);
})
.catch((error) => {
console.error(‘Error sending request:’, error);
});

The above is only resulting in 0 eth being sent to B instead of a request for transfer out of B’s wallet

Hi have you tried using eth_sendTransaction Send transactions | MetaMask developer documentation

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.