3

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})`);
}
6
  • We need more context. What's your code for example ? Do you send your transaction directly to a node or to an API that has a node for you (infura ? ) ? Jan 22 '20 at 12:28
  • @FlorianCastelain, I do a code in node js. I have edited my question and paste my code here Jan 22 '20 at 12:34
  • Infura requires a project ID (provided to you when you open an account there). So your API_KEY up there looks rather suspicious. Jan 22 '20 at 12:42
  • INdeed. Read this: infura.io/docs/gettingStarted/makeRequests Your "APIKEY" shoud be the project id, like so: "mainnet.infura.io/v3/YOUR-PROJECT-ID" Jan 22 '20 at 12:48
  • project id will get from Infura? Is it free? Jan 22 '20 at 12:49
7

You need to:

  1. Sign up with Infura.io
  2. Login into Infura.io
  3. Click CREATE NEW PROJECT button and enter project name

Then in project details screen you will see your endpoint URL. Something like this: mainnet.infura.io/v3/xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx. This URL you should use in your code. You may also configure additional security settings for your project, either to require project secret (good for backend applications) or to whitelist origins (good for frontends). Origin is basically where you frontend app is deployed. If you are just developing locally, origin like localhost:3000 could be a good choice.

3
3

No, until today it was possible to connect Infura as ETH service provider by this endpoint mainnet.infura.io/PROJECT_SECRET

But today smth went wrong and it trows an exception with message "project ID is required"

Setting mainnet.infura.io/v3/PROJECT_ID as an endpoint throws "401 Unauthorized"

0

login to your https://infura.io/ panel then you can get your project secret and Id

https://infura.io/

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.