Reputation: 139
is it possible to know for which price user is buying/selling token on transfer function call?
I want to store information on the contract for with user bought/sold tokens on the transfer function.
Upvotes: 1
Views: 374
Reputation: 614
Yes it is possible. this is where oracles comes into play chainlink oracle provide off-chain data like token price feeds in contract in a decentralised way. Here is how you can get token price feed in smart contract in EVM-compatible blockchains
To keep record of price on each transfer extend transfer event to emit the price as well that you fetch from oracle.
Your Flow for modified transfer function will be something like this.
emit Transfer(sender, recipient, amount, price);
where price is current price that you got from oracle.Upvotes: 1
Reputation: 858
No, this is not possible, at least in a token contract, because the token contract only "knows" that the user send or approved tokens and that's all that can know, it could be possible in a dex or cex contract
Upvotes: 1