I want to write a contract which enables the user to deposit the native chain token in a contract and to then later withdraw the token.
The only example I found so far, only enables the user to withdraw the balance from the smart contract but I couldn't figure out how to send token to the contract.
This is how I want it in theory to look:
#[ink(message, payable)]
pub fn deposit(&mut self, value: Balance) {
// Test if caller has sufficient funds
// deposit the balance to the contract
}
#[ink(message, payable)]
pub fn withdraw(&mut self, value: Balance) {
ink_env::debug_println!("requested value: {}", value);
ink_env::debug_println!("contract balance: {}", self.env().balance());
assert!(value <= self.env().balance(), "insufficient funds!");
if self.env().transfer(self.env().caller(), value).is_err() {
panic!(
"requested transfer failed. this can be the case if the contract does not\
have sufficient free funds or if the transfer would have brought the\
contract's balance below minimum balance."
)
}
}