Help with sending value to external contract interface

I keep getting an error when sending a value to an external function; the error I get that t should be payable, but I did that!!!
image

1 Like

can you share your full code so I can try to replicate?

Hey @samartrade, hope you are great.

Would be great if you can share your code so we can help you solve the issue :face_with_monocle:.

You can use the “Preformatted Text” Button to encapsulate any kind of code you want to show.


function formatText(){

let words = “I’m a preformatted Text box, Please use me wisely!”

}

prefromatted_text-animated

preformatted text

If you have any more questions, please let us know so we can help you! :slight_smile:

Carlos Z.

Here is the code for the 3 files:

pragma solidity 0.7.5;

import "./destroyable.sol";

import "./ownable.sol";

interface governmentInterface{
    function addTransaction(address _from, address _to, uint _amount) payable external;
}

contract banki is destroyable{
    governmentInterface governmantInstance = governmentInterface(0x1d142a62E2e98474093545D4A3A0f7DB9503B8BD);
   
   
    mapping(address => uint) balance;
    
    constructor(){
        owner=msg.sender;
    }


    
    event depositDone(uint amount, address indexed depositedTo);
   
    function transfer(address _receipnt, uint _amount) public {
        require(balance[msg.sender]>=_amount, "Insufficeint balance"); //validate if the sender have sufficient balance
        require(msg.sender!=_receipnt, "don't transfer money to yourself");
       
        uint previousBalance=balance[msg.sender];
        _transfer(msg.sender, _receipnt, _amount);
        governmantInstance.addTransaction{value: 1 wei}(msg.sender, _receipnt, _amount);
        assert(balance[msg.sender]==previousBalance-_amount);
    }
    
    function deposit() public payable returns(uint){
        balance[msg.sender] += msg.value;
        emit depositDone(msg.value, msg.sender);
        return balance[msg.sender];
    }
    
    function withdraw(uint _amountToWithdraw) public onlyOwner{
        require(balance[msg.sender]>=_amountToWithdraw, "no money");
        uint previousBalance=balance[msg.sender];
        msg.sender.transfer(_amountToWithdraw);
        balance[msg.sender] -=_amountToWithdraw;
        assert(balance[msg.sender]==previousBalance-_amountToWithdraw);
    }
    function getBalance() public view returns(uint){
        return balance[msg.sender];
    }
    
    
    function _transfer(address _from, address _to, uint _amount) private{
        balance[_from] -= _amount;
        balance[_to] += _amount;       
    }
           
}

Code for government file:

pragma solidity 0.7.5;

contract government {
    struct Transaction{
        address from;
        address to;
        uint amount;
        uint txId;
    }
    
    Transaction[] transactionLog;
    
    function addTransaction(address _from, address _to, uint _amount) payable external{
        
        transactionLog.push(Transaction(_from,_to, _amount, transactionLog.length));
    }
    
    function getTransaction(uint _index) public view returns(address, address, uint){
        return (transactionLog[_index].from, transactionLog[_index].to, transactionLog[_index].amount);
    }
    
    function getContractBalance() public view returns (uint){
        return address(this).balance;
    }
}

Code for the ownable file:


contract ownable{
    address payable public owner;

    constructor(){
        owner=msg.sender;
    }
    
    
    modifier onlyOwner(){
        require(msg.sender == owner);
        _;            
    }
    
}

Thanks @thecil and @Bhujanga, I found the issue: I didn’t update the government contract to point to the new address.

1 Like