Search code examples
solidityeverscale

How to call run-local function from debot?


How to call run-local (without sending a message) function of another contract from debot? For example, for getting a public variable.


Solution

  • This was useful for me.

    In debot:

    1. Create interface for function of another contract with function (if public variable too).
    interface IOther {   
        function funcName()    
        external returns(uint);
    }
    
    1. Build the message and send it.
    function runLocal() public{
            optional(uint256) pubkey = 0;                 
            address remoteContract = address.makeAddrStd(0, 0xceaa3bc6b00cf2b1e750dae2dd94d246a126a989009a3fb3bb73bea1a48b3b);                    
            TvmCell message = tvm.buildExtMsg({
                abiVer: 2,
                callbackId: tvm.functionId(onSuccessFuncName),
                onErrorId: tvm.functionId(onErrorFuncName),
                time: uint64(now),
                dest: remoteContract,
                call: {
                    IOther.funcName
                }
                });
                tvm.sendrawmsg(message, 1);      
        }
    
        function onSuccessFuncName(uint response) public{                                        
            /* working with response from remote contract */
        } 
        
        function onErrorFuncName() public{        
           /* catch error */
        }