The Chain.spend(addr, ntokens) will take from the function caller(Call.caller) wallet to send to addr. The question now is how does the contract send tokens from the Contract.Address to the function caller
To explain better let me use an example of a trading system where Buy means trading Fiat to AE and Sell means trading AE to Fiat.
At this time, the Chain.spend method transfers token from the Callers address after confirmation to the stipulated address then keeps the record so the admin can send the equivalent Fiat to the user.
Then for Buy, the caller sends Fiat to get the equivalent in AE right? So how does one achieve this goal after the caller has sent the equivalent Fiat?
It doesn’t matter what the use case is Chain.spend only takes two arguments, the account that receives the tokens, and the number of tokens to move.
To move tokens from account A to account B using contract C, account A first have to give those tokens to the contract C and then contract C can Chain.spend(B, …) - when doing a contract call you can attach tokens to the call, and likewise when you are doing a remote contract call inside a contract.
when calling the sell_ae function, make sure the Call.value is an AE value and not aettos or the rest
When calling the 'buy_ae` function, make sure the fiat amount is greater than 100 and less than or equals to the balance on the Contract.address when divided by 1000000000000000000 and multiplied with 100.