0

I have a function as follows i.e. transfer.

function transfer(address _to, uint256 ENvalue, uint256 PWvalue) public returns (bool) {
require(_to != address(0));

balances[_to].bEN = balances[_to].bEN + ENvalue;

balances[_to].bPW = balances[_to].bPW + PWvalue;

return true;

}

When I invoke this function as follows:

    contractInstance.methods.transfer('0x31c5f6A1fDb0C142742478eb31B710E9D47eAEe9', 5, 10).send({ from: '0xE07b6e5a2026CC916A4E2Beb03767ae0ED6af773' }, function(error, result) {
    console.log(error);
    console.log(result)
});

I receive following message:

> contractInstance.methods.transfer('0x31c5f6A1fDb0C142742478eb31B710E9D47eAEe9', 5, 10).send({ from: '0xE07b6e5a2026CC916A4E2Beb03767ae0ED6af773' }, function(error, result) {
...     console.log(error);
...     console.log(result)
... });
Promise {
  <pending>,
  domain: 
   Domain {
     domain: null,
     _events: 
      { removeListener: [Function: updateExceptionCapture],
        newListener: [Function: updateExceptionCapture],
        error: [Function: debugDomainError] },
     _eventsCount: 3,
     _maxListeners: undefined,
     members: [] },
  _events: undefined,
  emit: [Function: emit],
  on: [Function: on],
  once: [Function: once],
  off: [Function: removeListener],
  listeners: [Function: listeners],
  addListener: [Function: on],
  removeListener: [Function: removeListener],
  removeAllListeners: [Function: removeAllListeners] }

and when I get the balance of 0x31c5f6A1fDb0C142742478eb31B710E9D47eAEe9 it is still zero. Is there something wrong ?

> contractInstance.methods.balanceOfPW('0x31c5f6A1fDb0C142742478eb31B710E9D47eAEe9').call({ from: '0xE07b6e5a2026CC916A4E2Beb03767ae0ED6af773' }, function(error, result) {
...     console.log(error);
...     console.log(result)
... });
Promise {
  <pending>,
  domain: 
   Domain {
     domain: null,
     _events: 
      { removeListener: [Function: updateExceptionCapture],
        newListener: [Function: updateExceptionCapture],
        error: [Function: debugDomainError] },
     _eventsCount: 3,
     _maxListeners: undefined,
     members: [] } }
> null
0

And for getting balances :

struct Balances {
    uint256 bEN;
    uint256 bPW;
  }
  mapping(address => Balances) balances;
function balanceOfEN(address _owner) constant returns (uint256 balance) {
    return balances[_owner].bEN;
  }
  function balanceOfPW(address _owner) constant returns (uint256 balance) {
    return balances[_owner].bPW;
  }
  • can you show the code for balanceOfPW? – shaish Apr 30 '18 at 20:28
  • @shaish I added in question. – Questioner Apr 30 '18 at 20:59
  • tested in remix, it works. are you sure you gave the original transaction time to get mined? – shaish Apr 30 '18 at 21:09
  • @shaish I don't know how long is enough to be sure a transaction is mined ? – Questioner Apr 30 '18 at 21:40
  • you have callbacks that get called in this case (or you can split the function in two, look in etherscan, and then run the second function,or if you're running locally on ganache just wait for the promise to resolve). – shaish Apr 30 '18 at 22:24

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.