1

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.

1

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. – DavidB May 17 '18 at 5:54
  • By Dapp you mean interacting with your smart contract? – Jaime May 17 '18 at 8:37
  • Yes. That is correct. @Jaime – DavidB May 18 '18 at 4:33
  • 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. – Jaime May 18 '18 at 8:07
  • 1
    Furthermore, 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. – Jaime May 18 '18 at 15:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.