Sending in solidity

Hi guys Im new and try to learn solidity to be able to deploy my first dApp.
I've seen different functions for sending, what are differencies bettween?

  1. (bool sent,) = msg.sender.call{value: value}("");
  2. payable(msg.sender).transfer(value);
  3. emit Transfer(msg.sender, 0, address(this).balance);

What is the differenc and which one is used for?

And another question, when I write a deposit function, can I specify the amount as a function parameter like here the _value:
function Deposit(uint _value) public payable {

}
Because only the msg.value is deposited successfully. How does it work, when I want to let the user to enter the amount at a webpage he wants to deposit?

Best Regards

the first option is the correct one to transfer, the second is no longer used, and the third is an event. Regarding the function, the payment will be made through the network's native crypto, you have to do it through the global variable msg.value

to allow user to put amount is done with web3.js

So to keep the argument uint amoun is ok and can be used later on to specify the amount right?

the payment will be made through the network's native crypto, you have to do it through the global variable msg.value
Got it. What would be the way to use a stable coin like DAI within an application for deposit and withdraw?

no, everything is passed through msg.value, that mount would be a security problem

what you can do in the contract with state variables, is to check if the amount sent by msg.value is correct

Ok, so only msg.value matters right?
What about the other question, is it possible to build an dApp which is interacting with the user, using a stable coin?
Is it possible? For example like a lottery, user can deposit DAI and withdraw DAI afterwards?

Best regards

Yes, that can be done, I hope I have helped you

1 Like

Yes thank you you have answered a lot of questions.
I would appreciate if someone could share an example for a smart contract which is interacting using a stable coin like BUSDT or DAI. Using google I only see result how to create a stable coin, which is not my focus.

Best Regards

what to look for can be found by understanding how the erc20 token works