0

I have two Smart contracts SC1 and SC2, I am sending ether from SC1 to SC2.

pragma solidity 0.5.16;
contract SC1 {
    address owner;
    constructor() public {
        owner = msg.sender;
    }
    function transferTo(uint amount, address payable dest ) public {
        require(tx.origin == owner);
        dest.transfer(amount);
    }
    function () external payable{
    }
}

==

pragma solidity ^0.5.16;
interface SC1 {  
   function transferTo(uint amount, address payable to   ) external;
}
contract SC2{

    uint public  count;
    address owner;
    constructor() public {
        owner = msg.sender;
    }
    function() external payable  { 
      count++; 
      if (count < 2 ) 
         TxUserWallet(msg.sender).transferTo(msg.sender.balance, address(this));
      
   }
}

truffle script

var assert = require('assert');
const path = require("path");
const fs = require("fs");


module.exports = async function(callback) {
  try {
     let arg1 = ""
     let arg2  = ""
     let  amount = '6'
     const accounts = await web3.eth.getAccounts();
     const acc2 = accounts[2];
     transferFuncName= "transferTo"
     const vic= artifacts.require("SC1");
     const att= artifacts.require("SC2");
     const vicobj = await vic.new();
     const attobj = await att.new();
     result1 = await web3.eth.sendTransaction({to:vicobj.address, from:acc2, value: web3.utils.toWei(‘11’)})
    
     arg2 =  attobj.address
     arg1 = web3.utils.toWei(amount,"ether")
     result2 = await vicobj[transferFuncName](arg1, arg2, {from:accounts[0]})
    }
 catch(error) {
    console.log(error)
  }

  callback()
}

I am getting following error message:

Using network 'development'.

{ Error: Returned error: VM Exception while processing transaction: revert
    at module.exports (/home/zulfi/Truffle_programs/js_search_opcode_js/executingFunc.js:23:46)
    at process._tickCallback (internal/process/next_tick.js:68:7)
  hijackedStack:
   'Error: Returned error: VM Exception while processing transaction: revert\n    at Object.ErrorResponse (/home/zulfi/.nvm/versions/node/v10.23.3/lib/node_modules/truffle/build/webpack:/node_modules/web3-core-helpers/src/errors.js:29:1)\n    at /home/zulfi/.nvm/versions/node/v10.23.3/lib/node_modules/truffle/build/webpack:/node_modules/web3/node_modules/web3-core-requestmanager/src/index.js:170:1\n    at /home/zulfi/.nvm/versions/node/v10.23.3/lib/node_modules/truffle/build/webpack:/packages/provider/wrapper.js:107:1\n  

Somebody, please guide me.

Zulfi.

1 Answer 1

0

I found the solution for this problem: SC2 should be like this:

pragma solidity ^0.5.16;
interface SC1 {  
   function transferTo(uint amount, address payable to   ) external;
}
contract SC2{

    uint public  count;
    address owner;
    constructor() public {
        owner = msg.sender;
    }
    function() external payable  { 
     
      
   }
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.