Hey guys, please anyone got idea how to get the smart contract address of a token.

E.g if someone sends token to my smart contract, I want to verify if that token is my own token.

Understanding that I cannot restrict other tokens from being sent. Anyway to verify if the token address is my smart contract address before I execute a function?.

Mar 18, 2020, 1:46 PM
Hi! Actually a token contract is just a records contract of addresses, where for each address a particular amount of units is assigned. When you send somebody tokens, you just simply assign some of units (unsigned integers) to this particular address. And then deduct this amount of units(tokens) from the record (mapping) of your current balance and add this amount to the record with the receipt’s address. So as contract owner, you are unable to check who and what kind of tokens transferred to your address, because your contract or account didn’t called.
So in order to verify the desired token contract address, you may simple call balanceOf(your contract address) function in a trusted token contract and watch the balance of it.
Mar 18, 2020, 2:46 PM
Yes true. But still not what I want
Mar 18, 2020, 3:00 PM
The only way is to brute force all token contracts available some how and check the balance of your contract.
But this is barely possible
Did you meant token address aka token smart contract address?
Mar 18, 2020, 3:11 PM
Maybe I give a better instance.


I have a contract with token XYZ, at the front end of my dapp, I want user to purchase services with my token.


I should be able to receive tokens with my contract first and foremost.
Then I should be able to verify if the token coming in through a function call is my token.


Using function call cause contract might be receiving tokens from anywhere, cannot restrict what comes in, any token can come in.

But really if token is coming in through the function call at my front end, then it should verify if the token being sent is truly my token or another token before it renders the service.



On metamask, if you check token, by the side you can find token contract address.

So I want to be able to verify if that address is same with my contract address, that way I will be sure it's my token am receiving.
Mar 18, 2020, 3:12 PM
So let user to get your tokens somehow before he pays for your services like selling them at one rate and accept them in other rate.
The user cannot get your XYZ tokens unless you transfer some to him
You may send some XYZ tokens to your contract address, which means your contract address is stored in XYZ token contract
After the service is provided, you check the balanceOf(your service contract address)
If it got increased, then fire up your service
Mar 18, 2020, 3:21 PM
Yes, my user will get my tokens either from exchange, direct transfer etc.


What I want is for me to recieve his payment through my token. Just like we send transactions with eth.
If its direct like this, if someone else sends tokens that's not my token to smart contract, it will increase as well. I wouldn't even know which token it was that was sent.


Smart contract doesnt even notify when it receives tokens
Mar 18, 2020, 3:24 PM
Yes it is possible, just create a balance of your service contract in your XYZ tokens and then watch for it.
You simply check the balance
Send 1 XYZ to your contract address, and that’s it.
Mar 18, 2020, 3:25 PM
In fiat system, someone sends funds to your account. You do not identify the person by the balance cause two people can send same amount.
Mar 18, 2020, 3:25 PM
Ok. If you are owner of the XYZ contract you may watch for transactions
Mar 18, 2020, 3:27 PM
This wont be efficient.
Mar 18, 2020, 3:27 PM
Do you mean gas consumption?
Mar 18, 2020, 3:28 PM
However, this is one thing that missed in ERC20, ERC223 kinda takes care of this, but for me, I dont seem to get the full gist of it that's why I came here for someone who might probably have much better understanding of how it's done.
No man. Not gas in this case. The whole thing is a little complicated though
Mar 18, 2020, 3:29 PM

© 2024 Draquery.com All rights reserved.