VMException while transferring Ether from one Smart contract to other
zak100
Posted on September 29, 2022
`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()
}
Following is the 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.
Posted on September 29, 2022
Join Our Newsletter. No Spam, Only the good stuff.
Sign up to receive the latest update from our blog.
Related
November 30, 2024
November 30, 2024