I got an error at sendSignedTransaction is : Project ID is required. Can you please let me know that what is the actual problem?
This is my code:
try {
const ethereumUri = 'https://ropsten.infura.io/API_KEY'; //process.env.API_URL
var web3 = new Web3(new Web3.providers.HttpProvider(ethereumUri));
const keystore = web3.eth.accounts.encrypt(req.body.privateKey, 'Drc@1234');
const privateKey = new Buffer.from(req.body.privateKey.substr(2), 'hex')
const decryptedAccount = web3.eth.accounts.decrypt(keystore, 'Drc@1234');
var amount = web3.utils.toWei(req.body.transaction_value.toString(), "ether");
var fee_eth = req.body.transaction_fee * 1000000000;
var convertTOGwei = fee_eth / 21000;
var decimalLimit = convertTOGwei.toFixed(2);
var fee = web3.utils.toWei(decimalLimit.toString(),'gwei');
var sender = req.body.from_address;
var receiver = req.body.to_address;
/*var rawTransaction = {
"from": sender,
"to": receiver,
"gasPrice": web3.utils.toHex(fee),
"value": web3.utils.toHex(amount),
"gas": 21000,
"chainId": 3
};*/
const txCount = await web3.eth.getTransactionCount(sender)
// Transaction
const txObject = {
nonce: web3.utils.toHex(txCount),
to: receiver,
value: web3.utils.toHex(amount),
gasLimit: web3.utils.toHex(21000),
gasPrice: web3.utils.toHex(fee)
}
// Sign the transaction
const tx = new Tx(txObject, { chain: 'ropsten', hardfork: 'istanbul' })
const pk = Buffer.from(privateKey, 'hex')
tx.sign(pk)
const serializedTx = tx.serialize()
const raw = '0x' + serializedTx.toString('hex')
// Broadcast the transaction
const receipt = await web3.eth.sendSignedTransaction(raw)
return receipt;
} catch (e) {
console.error(`try/catch Error:(${e})`);
}
API_KEY
up there looks rather suspicious.