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);
}

1 Answer 1

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();
}
2
  • 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 1, 2020 at 2: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, 2022 at 21:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.