2

I am trying to implement deposit functionality in my contract in the sense whoever calls the function below needs to deposit some ether. For example:

Contract A calls the function below and again, Contract A needs to deposit some ether.

I can do this with the remix interface by passing "VALUE". But I want to pass this variable as an argument.

Here is what

event Deposit(address sender, uint amount, uint balance);

function deposit(uint testAmount) public payable { testAmount = msg.value; // GIVES ERROR emit Deposit(msg.sender, testAmount, address(this).balance); }

function doWork(int job_id, uint amount) public payable{ deposit(amount); }

Emrah
  • 1,654
  • 2
  • 9
  • 24

1 Answers1

1

Your issue is that you're trying to reassign to a parameter, which you don't need to do. This is likely the simplest change you could make to get this to work:

event Deposit(address sender, uint amount, uint balance);

function deposit() public payable { emit Deposit(msg.sender, msg.value, address(this).balance); }

function doWork(int job_id, uint amount) public payable{ deposit(); }

natewelch_
  • 12,021
  • 1
  • 29
  • 43
  • 1
    This still requires passing the AMOUNT that I want to deposit to a smart contract using the VALUE input of the remix solidity. I am trying to not use the interface of remix. – Emrah Dec 01 '20 at 02:30
  • @emrah I'm not sure what you mean by "interface of remix". The above seems to do what you want, taking the value from the msg.value field – natewelch_ Aug 28 '22 at 21:25