0

Goodday Everyone….So am building a dapp where different addresses can send ether to a smart contract…So am trying to get the value of ether sent by each addresses through a function….How do I write that function??

2 Answers 2

0

Yes, you are trying to get the value of ether sent by each addresses through a function.

You can use:

receive() external payable {}

fallback() external payable {}

See: https://docs.soliditylang.org/en/v0.8.12/contracts.html

2
  • 1
    I think this function gives only the balance of the total Ether that address has.....I want to be able to receive ether from different addresses, then limit how much that particular address can withdraw based on the amount they sent to that smart contract.
    – EniKay
    Commented Nov 26, 2022 at 14:48
  • If that is the case, you need the fallback or receive function. Both functions allow you to receive ether from different addresses. I have revised my answer. Commented Nov 26, 2022 at 15:50
0

First of all, you need to store the address of the sender in a data structure while receiving the ETH, you can go with the array.

Along with that, you need a mapping in the form of address->uint to store the amount of ETH sent by each sender.

Then just simply create a view function that when passed with the array index returns the ETH sent by a particular sender.

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.