How to connect my wallet to Moralis server

I have a token X erc20 on Polygon main net to reward users.
Now I want to write a cloud function to send 10 token X to the user wallet, how can I connect my wallet to moralis server to do that?

This can make a transfer: https://docs.moralis.io/moralis-server/sending-assets#transferring-erc20-tokens

// sending 0.5 tokens with 18 decimals
const options = {type: "erc20", 
                 amount: Moralis.Units.Token("0.5", "18"), 
                 receiver: "0x..",
                 contract_address: "0x.."}
let result = await Moralis.transfer(options)

Doing that in a cloud function is a little more complicated, as a cloud function will not have access to your wallet private key.

Yeah I see this function on the docs.
But this function is run on server right? so how can setup it so that we can send erc20 token on server by code (automatically signed??

That function is available only on browser. If you want to do transactions from the server you need to do it manually using standard web3 abilities

I got it. Do you have any link/docs about transfer erc20 token on Polygon main net with auto signed? thank you very much :slight_smile:

You may not want to do that, you can let your users to execute a contract call in order to get the rewards.

Yeah, we should let user call the contract. But how can we decide how much they get the reward? in smart contract, right? but he may call many times?

The smart contract somehow should also keep track of what rewards every account should receive.

1 Like

Yeah, but it’s suitable for game play that win-lose can be processed on the smart contract. For the game user need skill to win the game, if user get reward after they win by calling the smart contract function, they can fake the game score.

You can add constraints in smart contract like an address can not call that function more than once a month or after it received X value of token Y.

yeah, the cool down variable will prevent them play too many times.
However, I don’t get your idea “after it received X value of token Y”.
You know, when users finish the game, they call the function in the contract, the function must take additional parameters like win/loose or game high score… and how the smart contract can validate it’s not faked?
“after it received X value of token y” => which function send X token Y to address? this function is called by users or by the owner?

What is the game that the users play?

any game, they play, get higher score and we reward them.

asking because some games can be played directly on blockchain, like an user calls a function on a smart contract to enter the game, at the end the smart contract decides who won and they can call another smart contract function to get the reward

It’s jumping game, and they must have skill to get higher score. Like I said before, if the game is play on the blockchain, it’s just random things, right? not related to their skill.


like this one, how can make it play on the blockchain?

if the game is off chain, someone can make a program to play the game, also not related to their skill

1 Like

ok, so the gameplay like jumping is not suitable for blockchain game, right?

It depends, it the rewards are high enough someone will find a way to automate the gameplay with a program.

1 Like