0

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

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();
}
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. – blockByblock Dec 1 '20 at 2:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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