-1

enter image description hereI wrote a sample api to send ethers from one account to another account using rinkeby testnet.It's throwing the following error(I attached screenshot). Please tell me how to resolve that error and why this error is coming?enter image description here

Here is my code

app.post("/sendTransaction", async (req, res) => {
    var user_email = req.body.email;
    var to_address = req.body.to_address;
    var value = req.body.amount;
    let from_address = req.body.from_address;
    var web3 = new web3(new web3.providers.HttpProvider('http://127.0.0.1:8545'));
    const accounts = await web3.eth.getAccounts()
    await web3.eth.personal.unlockAccount(from_address, "test", 15000);
    let BuserAccBalance = await web3.eth.getBalance(from_address);
    let tran_hash = await web3.eth.sendTransaction({
        from: accounts[1],
        to: accounts[5],
        value: web3.utils.toWei('1')
    });
    console.log("Transaction Hash:" + JSON.stringify(tran_hash));
    let AuserAccBalance = await web34.eth.getBalance(from_address);
 res.send("Balance before Tran:" + BuserAccBalance + " Balance after Tran:" + AuserAccBalance + "\nTransaction Hash is:" + tran_hash.transactionHash);

});

Error I am getting is :Error: "Provided address "undefined" is invalid, the capitalization checksum test failed, or its an indrect IBAN address which can't be converted".

  • 2
    Please share your actual code and error message, not a screenshot of them. (Screenshots aren't searchable, so this question won't be useful to anyone in the future who has the same problem.) – smarx Aug 30 '18 at 15:32
  • Hey, I added my api code and error can you please check it once? – M Gopi Aug 31 '18 at 3:54
  • 1
    log accounts[1] and accounts[5], Make sure these two are not ` null` and not undefined – Subhod I Aug 31 '18 at 4:38
  • What Subhod said is right. maybe your geth path is missing the jsons of the addresses that you are trying to use. – Rajesh Aug 31 '18 at 5:04
  • Sorry I did n't get exactly. Can u guys explain a little bit more. Thanks for u r responses – M Gopi Aug 31 '18 at 9:05
1

You are Unlocking " from_address " and trying to send from accounts[1].

Try with below code

app.post("/sendTransaction", async (req, res) => {
    var user_email = req.body.email;
    var to_address = req.body.to_address;
    var value = req.body.amount;
    let from_address = req.body.from_address;
    var web3 = new web3(new web3.providers.HttpProvider('http://127.0.0.1:8545'));
    const accounts = await web3.eth.getAccounts()
    await web3.eth.personal.unlockAccount(from_address, "test", 15000);
    let BuserAccBalance = await web3.eth.getBalance(from_address);
    let tran_hash = await web3.eth.sendTransaction({
        from: from_address,
        to: accounts[5],
        value: web3.utils.toWei('1')
    });
    console.log("Transaction Hash:" + JSON.stringify(tran_hash));
    let AuserAccBalance = await web34.eth.getBalance(from_address);
 res.send("Balance before Tran:" + BuserAccBalance + " Balance after Tran:" + AuserAccBalance + "\nTransaction Hash is:" + tran_hash.transactionHash);

});

If still problem exists, indicate the exact line where are you getting this error. Also print all the addresses in log and update your question.

  • Hey, I tried the above solution but I am not getting. I am printing the accounts log.The problem is from here " await web3.eth.personal.unlockAccount(from_address, "test", 15000);". I tried to print the "BuserAccBalance" but it is not printing. – M Gopi Sep 3 '18 at 5:35
  • I added latest screenshot also – M Gopi Sep 3 '18 at 5:42
  • Print from_address and try, I suspect this is not in correct format – M. Gopal Sep 3 '18 at 8:03

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.