0

Hi am developing a etherium DAPP.

In that for every user registration some ether will get transfer from user to contract...

Everything work perfect but the transacted ether is not reflecting in ganache accounts....

Account balance should be 144.44 enter image description here

Metamask transaction is fine for 5.5 Ether

enter image description here

enter image description here

Transaction details in Ganache

enter image description here

JS CODE

createUser: function (){
        console.log("First Name: "+ $('#firstName').val());
        console.log("Last Name: "+ $('#lastName').val());
        console.log("Age: "+ $('#age').val());
        console.log("Is city: "+ $('#city').val());

      if ($('#firstName').val() && $('#lastName').val()  && $('#age').val()  && $('#city').val() ){        
           web3.eth.getAccounts(function (error,accounts){
          if (error){
              App.showError(error);
          }
         App.currentAccount = curacc;
         // App.currentAccount = "0xAa1e9e6f830c2C07FCA79D9cE2ebC81310541A1b";
          console.log("curr acc: "+ App.currentAccount);

          let tipAmount = window.web3.utils.toWei('5.5', 'Ether');
          console.log("tipAmount" + tipAmount);

          App.contracts.HelloWorld.deployed().then(function(instance){
            return instance.createUser.sendTransaction($('#firstName').val(), $('#lastName').val(), 
            $('#age').val() , $('#city').val(), {from:App.currentAccount , value: tipAmount})
          }).then(function(result){
              App.showMessage('Submitted data saved Successfully....');
              App.ShowSavedUser();
          }).catch(function (error){
              App.showError(error);
          })
        })
      }
      else{
        console.log("Data not filled for all fields....");
          App.showError('Please fill all fields...');
      }
    },

SOLIDITY CODE

pragma solidity ^0.5.0;

contract HelloWorld {

uint public userCount = 0;


constructor() public{
    createUser ("Monicka", "Akilan", 30, "Chennai");
}

  struct User {
    uint id;
    string firstName;
    string lastName;
    uint age;
    string city;    
    uint tipAmount;
    address payable author;
  }
event profileTips(string firstName, string lastName, uint age, 
 string city, uint tipAmount, address payable author);

mapping(uint => User) public Users;

 function createUser(string memory _firstName, string memory _lastName, uint _age, 
 string memory  _city) public payable{
    userCount ++;
    // address(msg.sender).transfer(msg.value);
     Users[userCount] = User(userCount, _firstName, _lastName, _age, _city, 20, msg.sender);
    emit profileTips(_firstName, _lastName, _age,  _city, msg.value,  msg.sender);
 }
}

Can anyone help me solve this sync issue....

Thanks in Advance

  • i don’t see what is out of sync? The contract recieved 5.5 ether you send to it – haxerl Jun 15 at 16:47
  • Does metamask shows the correct balance? The code has address(msg.sender).transfer(msg.value) commented out, perhaps you were addressing a previous version with that code uncommended? – Ismael Jun 15 at 18:13
  • yeah the balance is showing in metamask – Monicka Akilan Jun 16 at 9:44

Your Answer

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

Browse other questions tagged or ask your own question.