0

I am trying to hash an address then send tokens to a mapping of the hash in the token contract, then be able to withdraw those tokens using a hash of the address. It compiles but cannot make it work. What am I doing wrong?

Also I don't think I need the 'payable', and not sure what to put after 'dreceive' as this function shouldn't need any input.

contract BasicToken is ERC20Basic {
  using SafeMath for uint256;
  bytes32 hashed;

  mapping(address => uint256) balances;
  mapping(bytes32 => uint256) dks;

  function transfer(address _to, uint256 _value) returns (bool) {
    balances[msg.sender] = balances[msg.sender].sub(_value);
    balances[_to] = balances[_to].add(_value);
    Transfer(msg.sender, _to, _value);
    return true;
  }

  function balanceOf(address _owner) constant returns (uint256 balance) {
    return balances[_owner];
  }

  function dsend(address _sendto, uint256 _amount) payable returns (bool) {
    hashed = keccak256(_sendto);
    balances[msg.sender] = balances[msg.sender].sub(_amount);
    dks[hashed] = dks[hashed].add(_amount);
    Dtransfer(msg.sender, _amount);
    return true;
  }  

  function dreceive(amount) payable returns (bool) {
    hashed = keccak256(msg.sender); 
    dks[hashed] = dks[hashed].sub(amount);
    balances[msg.sender] = balances[msg.sender].add(amount);
    Drec(this, amount);
    return true; 
  }

}
0

There's at least 2 problems I can see from looking at the code:

  • You are not setting any initial balance for the tokens. There should be a constructor where you assign some initial supply (or you mint tokens). None of the functions will work as it is now as there is no balance to move from account to account.

  • Even though both dsend and dreceive are marked as payable, none of them are doing anything with msg.value.

I'm not entirely sure why you'd want to rewrite the logic of the ERC20 tokens and make them not compliant with the protocol.

  • This is just a child contract within a token contract that includes the initial supply and ERC20Basic contract. – Curious2424 Nov 26 '17 at 0:54
  • I see how I should use _value instead of _amount when subtracting from the balances mapping, although they are both bytes32. I am trying to create separate functions for interacting with the erc20 contract. Hash the address tokens are to be sent to, use that hash as a mapping to store within the contract, then use that hash to withdraw. – Curious2424 Nov 26 '17 at 1:00

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.