I am working on a project where I need to send ether from an user to a smart contract and from the smart contract to the user. The smart contract is code in Solidity and I'm using python and web3.py to communicate with it.
I manage to do it like this: From the user to the smart contract in my python script:
#send transaction to the smart contract
web3.eth.sendTransaction({
'to': address,
'from': web3.eth.defaultAccount,
'value': 10000000000000000000
})
And from the smart contract to the user using this function:
function sendEther(address payable recipient, int _amount) public payable {
recipient.transfer(_amout ether);
}
Note that this function can be call in the smart contract.
But then I wanted to create a function deposit (from user to smart contract) in my smart contract:
function deposit(uint256 amount) payable public {
require(msg.value == amount);
// nothing else to do!
}
So basicaly, if I need to call this function with my python script, I need to proceed like this:
contract.functions.deposit(10).transac({
'to': address,
'from': web3.eth.defaultAccount,
'value': 10
})
And by checking the balance of the smart contract, it works correctly.
But how do I need to proceed if I want to call the deposit function inside my smart contract and proceed to a transaction from user to smart contract? How do I parse the 'msg.value' in my smart contract when I call the function inside? Is that even possible?
Many thanks, Alban