EatTheBlocks Forum

Sending Ether in Truffle console environment

Hi,

I have two contracts:

pragma solidity ^0.5.8;

contract SC1 {
    event Log(uint gas);

    // Fallback function must be declared as external.
    function() external payable {
        // send / transfer (forwards 2300 gas to this fallback function)
        // call (forwards all of the gas)
        emit Log(gasleft());
    }

    // Helper function to check the balance of this contract
    function getBalance() public view returns (uint) {
        return address(this).balance;
    }
   
}

==

        pragma solidity ^0.5.8;
        contract SC2 {
            function transferToFallback(address payable _to) public payable {
                _to.transfer(msg.value);
            }

            function callFallback(address payable _to) public payable {
                //(bool success,) = bank.call.value(msg.value)(payload); 
                //(bool success,) = bank.call{value: msg.value}(payload);
                //require(success, "Ether transfer failed.");
                
                (bool sent, ) = _to.call.value(msg.value)("");
                require(sent, "Failed to send Ether");
            }
           function() external payable{
            }
        }

Problem:
I am sending Ether from SendtFallback smart contract (SC)to Fallback SC but Fallback balance is zero and SendToFallback balance does not change. I think the problem is with the signature of transferToFallback function of SendToFallback SC. It does not accept any argument for sending Ether. Please guide me how to send Ether from SendToFallback Smart Contract to Fallback.

My Work:
I have used truffle console for sending Ether. I am using the following command:
)> senderSTB.transferTo(receiverFB.address, {from:accounts[0]})

The migration file i.e. 2_deploy_contracts.js is:

const FB = artifacts.require(“Fallback”);
const STFB = artifacts.require(“SendToFallback”);

module.exports = function(deployer) {
deployer.deploy(FB);
deployer.deploy(STFB);
};

Complete steps are provided at: Problem with transferring Ether in Truffle console
Zulfi.