Hi!
I have a contract which receives wei, I wanna send there some tokens to keep by the contract. how to manage receiving token in contract? for currency there is receive() payble method, what about ERC20? I can call token.transferFrom() and transfer token from sender to the contract, and manage it, but what if some just send a token from their metamask wallet?? cant understand the idea =((
Mar 19, 2022, 1:06 PM
Guys, can someone explain the idea of receiving ERC20 token by a contract?
Mar 19, 2022, 1:12 PM
contract receives the token, and transfer it to another EOA?
Mar 19, 2022, 1:14 PM
Create a test event and emit it anch chrck what is haopening
I dont use remix.
This was for @elijah147
Mar 19, 2022, 1:15 PM
Ah I see
Mar 19, 2022, 1:16 PM
I can't understand idea when I send any token to the my contract, how should I handle this by contact?
Mar 19, 2022, 1:16 PM
But u can deploy it in ganache and test it
Mar 19, 2022, 1:16 PM
You should use other standars for that, example erc223 if I remember correctly
Or erc 777
Mar 19, 2022, 1:17 PM
need to put the final address of the transfer in arguments, record it, then make an automatic or on request transfer
Mar 19, 2022, 1:17 PM
Mar 19, 2022, 1:17 PM
the challenge would be to get multiple transfer from the same address to different ones
Mar 19, 2022, 1:18 PM
I believe the error happens on this function but i'm not 100 sure where it is failing I suspect is line 67
Mar 19, 2022, 1:18 PM
wooh go ant try to implement )
Mar 19, 2022, 1:19 PM
If I do it provides me an error
let me see if I can mimic it
Mar 19, 2022, 1:19 PM
@El_invader why u have those values there??
Mar 19, 2022, 1:21 PM
It was part of the call but it enforce me to remoce () and add ; at the end
Mar 19, 2022, 1:22 PM
But u are not adding nothin
Mar 19, 2022, 1:22 PM
idk i was sleepy as hell tbh
what would be the proper way to add it without causing exclusive error?
Mar 19, 2022, 1:23 PM
@El_invader
That code is soooooo messy
Using a +
That code is soooooo messy
Using a +
Mar 19, 2022, 1:23 PM
true I fuckedup
Mar 19, 2022, 1:23 PM
Im going to be a bit hard. But if you need help to see whats wrong with that code you need to go back to programming basics
Mar 19, 2022, 1:24 PM
Mar 19, 2022, 1:24 PM
And why dont you use requires and put a revert reason???
Mar 19, 2022, 1:25 PM
Can you give me an example?
Like this?
Function name() public returns (bool success) {
require(name);
}
Like this?
Function name() public returns (bool success) {
require(name);
}
Mar 19, 2022, 1:36 PM
Yo dont know how a require works???
https://ethereum.stackexchange.com/questions/24969/solidity-how-can-we-write-a-error-message-in-require
https://ethereum.stackexchange.com/questions/24969/solidity-how-can-we-write-a-error-message-in-require
Mar 19, 2022, 1:48 PM
Btw thanks yes I have an idea of how βrequireβ works
I have been trying to find a contract using at least 0.8.12 but the closest one thats safe was BTT
Mar 19, 2022, 2:07 PM
One more question) Ok, I send some tokens from an address to my contract. Now when I look at token balance of my contract I see it. (token.balanceOf(address(this)))
But can contract track who send the tokens and track balance of received token by sender? aka erc20 wallet?
p.s. I know that I can write a custom func which transfer token from and address to contract and the manage it. but can contract track it somehow else?
But can contract track who send the tokens and track balance of received token by sender? aka erc20 wallet?
p.s. I know that I can write a custom func which transfer token from and address to contract and the manage it. but can contract track it somehow else?
Mar 19, 2022, 2:36 PM
Yes you could write your contract to have a function through which people could transfer tokens, and it tracks the senders. If people do plain transfers to the contract it can't track those senders since no contract code gets run
Mar 19, 2022, 2:42 PM
so, if contract receive plain transfer it's developer deal to handle this "common balance" somehow?
Mar 19, 2022, 2:43 PM
Yeah basically
Mar 19, 2022, 2:44 PM
huh. Thanks a tons man! It costs me a day to comprehend tokens behavior ... ))
Mar 19, 2022, 2:44 PM
No prob. Yeah a typical setup in this case is to have an ownerOnly function that can "rescue" these improperly sent tokens, sending them back to the address that sent them
Of course you need to go look up the transfers to get the sender addresses
Also useful for people that accidentally send other unrelated tokens to the contract
I typically write ERC20 and ERC721 "rescue" functions into my NFT contracts for this purpose
Mar 19, 2022, 2:49 PM
as I assume the contract owner have to provide sender address to the 'rescue' func, because contract dont know it. right?
Mar 19, 2022, 3:00 PM
Right
Mar 19, 2022, 3:00 PM
πππ
Mar 19, 2022, 3:01 PM