3
contract NotifyContract { //address at 0x971A46e7C16D2bBEd2167460961D86Dc3715EE32
    address public userAddr;
    byte public types;
    function notify(byte tokenByte,address userAddr_){
        types=tokenByte;
        userAddr=userAddr_;
    } 
}

//

contract Set {
    bool public ret;
    address public tokenAddr;
    address public userAddr;
    function Set(address tokenAddr_,address userAddr_){
        tokenAddr=tokenAddr_;
        userAddr=userAddr_;
    } 
    function call1(byte bb){
        ret=tokenAddr.call("notify",bb,userAddr);   //1 not valid
    }
    function call2(byte bb){
        tokenAddr.call(bytes4(sha3("notify(byte,address)")),bb,userAddr);//2 not valid
    }
    function call3(byte bb){
        NotifyContract c=NotifyContract(tokenAddr);// valid
        c.notify(bb,userAddr);
    }
}

At first, I create the NotifyContract contract, then I create the Set contract and pass the NotifyContract address and other userAddr_, but the function call is not valid. NotifyContract do not have the changed value? only 3 is valid. Is there something wrong?

  • 1
    byte tokenAddr_ is misleading. Because one will assume tokenAddr_ is an address. – Xavier Leprêtre B9lab Sep 4 '16 at 9:52
  • 1
    so sorry,I have correct it. It is strange that call function is not valid. Is something wrong?? – Jim Green Sep 4 '16 at 10:03
3
  1. call1 will never work.
  2. If your contract name is Set, then the constructor function is function Set(). You forgot to capitalise it. function set() is wrong. If you make this mistake then address public tokenAddr; will always be 0x.
  3. byte is an alias for bytes1, so "notify(byte,address)" is not the canonical signature. "notify(bytes1,address)" is.
  • 1
    thank u very much. 1. Why call1 will never work? it actually does not work. 2.as u said , I change byte to bytes1, it works. why? – Jim Green Sep 4 '16 at 11:28
  • 1
    call1 will never work because this is not how you call a function. The first 4 bytes have to be calculated as per call2 and "notify" is neither 4 bytes nor correct. And the signature calculation in call2 has to use the canonical signature. If you don't, the sha3 is different and the function is not recognised. – Xavier Leprêtre B9lab Sep 4 '16 at 12:21
  • 1
    If this answered your question, you might as well mark it as such. Cheers – Xavier Leprêtre B9lab Sep 6 '16 at 9:19

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.