Amit
Amit

Reputation: 21

Sending ether from one account to other account

I am using the below code in solidity to transfer ether from one account to another.

I am calling this from the owner's account.

But my ether gets deducted from owners and goes to contract address instead of the receiver/payee account.

 function PayCredit(address payable payee, uint money, uint invoiceNum) public payable{
        require(msg.sender==owner, "only owner can invoke it");
        payee.transfer(address(this).balance);
        claims[payee][invoiceNum].isPayed = true;
    }


Upvotes: 1

Views: 7535

Answers (1)

Block Crasher
Block Crasher

Reputation: 304

You are sending your ether's to contract address , change address(this) to address .

I would suggest you good practice of sending ether's to other account. Solidity transaction support value as argument and this is good place for sending ether(WEI) to other account . below code snippet will send 12 WEI to other account.

pragma solidity >=0.4.22 <0.6.0;

contract AB {
uint256 num1;
address owner;
constructor() public{
    owner = msg.sender;
}

function sendBal(address payable receiver) payable external onlyOwner {
    uint256 amount = msg.value;
    receiver.transfer(amount);  
}

Illustrate how to call sendBal Function

Upvotes: 3

Related Questions