So I have a conundrum. In order for me to get the user to sign a transaction web3.eth.accounts.signTransaction() wants the private key as input. I want metamask/the wallet to handle all this and never want to handle the private key if I can possibly avoid it (I don’t even like the idea of having it in memory)
Here is some code
const handleSubmit = (e) => {
e.preventDefault()
const transfer =aetokenContract.methods.safeTransferFrom(sendFrom, sendTo, "0", sendAmount, [])
const encodedABI = transfer.encodeABI()
const tx = {
from: "sendFrom",
to: sendTo,
gas: 2000000,
data: encodedABI
};
web3.eth.accounts.signTransaction(tx, "It wants the private key here").then(signed => {
var tran = web3.eth.sendSignedTransaction(signed.rawTransaction);
tran.on('confirmation', (confirmationNumber, receipt) => {
console.log('confirmation: ' + confirmationNumber);
});
tran.on('transactionHash', hash => {
console.log('hash');
console.log(hash);
});
tran.on('receipt', receipt => {
console.log('reciept');
console.log(receipt);
});
tran.on('error', console.error);
});
}