How can I have my customers to pay the custom tokens to my dapp by using MetaMask?When I try on this, I couldn't see any options I could choose the custom ERC20 token but only the Ether. Please advice.
2 Answers
If your users have the tokens they can "add token" in metamask. In metamask you have 2 tabs, "send" and "Token". Click on "Token" and then on "add token", it will ask you the address of the contract that created the token and the number of decimal points. Then the users will be able to transfer tokens.
UPDATE: To interact with your contract you do not need users to add the token to metamask.
You can use web3
Define the web3 variable, this allows you to interact with your contract
var web3 = new Web3(new Web3.providers.HttpProvider("your ethereum node"));
To access the functions of the contract you need the definitions of the functions (ABI)
ABI = "put here your contract ABI"
Then you can create an instance of your contract:
var Contract = web3.eth.contract(ABI);
var contractInstance = Contract.at('address of your contract')
Now you can acces the functions of your contrat, for instance the function transfer, to transfer tokens from teh user account to another user or to your contract:
contractInstance.transfer.("the_adress","the amount of tokens", {from:address},(function(err,result){
if(!err){
console.log(result)
}
})
This is just a quick overview of how to do it. I hope it helps.
-
Thank you for replying my question - @Jaime. But, what I meant here is when interacting with Dapp.– DavidBCommented May 17, 2018 at 5:54
-
-
-
I just update the answer to show how to include js code in your website so that you can call the functions in your contract, you can link every function to a button in your website. i hope this helps. If this answer your question please accept the answer. Let me know how it goes.– JaimeCommented May 18, 2018 at 8:07
-
1Furthermore, tokens are not things, so you do not really send tokens, you send a command cryptographically signed that change the balances in a mapping variable, so when you said you "send" tokens you are just changing a number in a register. That number represent the number of tokens you have. So in your applications sending tokens means sending a message with your signature, the contract check your credentials and if you have a balance (number) allows you to add the required amount to the register of someone else, this is what sendign tokens really means.– JaimeCommented May 18, 2018 at 15:00
If I understand you correctly, it sounds like you're trying to replace the gas fee (a fee in the blockchain's genesis currency you must pay to write to the blockchain) with your ERC20 token. You can't do this. You can add your ERC20 token in addition to the gas fee but you cannot solely replace the gas fee with any ERC20 token.