Hi, I need help with a function I’m building in my dapp: I have coins that I need to claim inside the game and send to my metamask (just like bombcrypto and other games do, for example) . I’m having difficulty doing this function, can you help me with any code examples that have done something similar? Is it possible to do with web3 or open zeppelin or another framework? Thank you for your hel
you want to make a function that the users of a game can call it in order to claim a currency on chain based on a currency that it is present only off chain in game?
if yes, it may be a question similar to this one: How to create metod withdraw or clain tokek
Hello, in my case it’s not like a fake currency off chain, what I need is that:
Transfer a real token from one metamask account (where tokens are stored) to another metamask account, but automatically when player clicks on the button claim
Its from the game metamask account to user metamask account
Do you know a way to transfer tokens automatically when user clicks on the claim button?
I was analyzing moralis documentation and trying to understand if the method moralis.transfer(options) is possible to do that?
I still think that it is equivalent of having two currencies (one real and one to keep track of what the user can claim)
you send from your server from your account that currency when user clicks the button, you can not do it directly with a Moralis SDK function, you will need the private key on server, you will skip MetaMask and you will send the signed transaction directly to a speedy node, you will pay the gas fees
step 1: you create a smart contract with a claim function
step 2: you send to that smart contract enough currency to be sent to users that claim later (so that you skip approve step)
step 3: in that claim function from the smart contract, you validate the parameters for that claim function in the smart contract function so that the parameters have a signature signed by an admin private key, then you tell the user what parameters has to send to the smart contract claim function, the user makes the call with Moralis.executeFunction, the user pays the gas fee, but you’ll have to generate the parameters on your server and you will have to use that admin private key to generate the parameters
Thanks a lot for describing the two versions !
Actually version 2 is exactly what I am looking for.
Would highly appreciate more details / examples.
Could you please provide that - thanks in advance for your time
you will find some info here: https://medium.com/mycrypto/the-magic-of-digital-signatures-on-ethereum-98fe184dc9c7
Thanks, but was more looking for something practicable
Link this: Have a way to send token ERC20 on backend?
Anything else you would recommend ?!