Web3 Send on Cloud Function

Hi, i’m trying execute a payable send method on a contract through a Cloud Function but got some errors, so, got some questions:

- What’s the correct form to send multiple parameters?
I’m trying contract.methods.contractfunction(param1, param2, …).send() according to the ABI structure order but got unknow param1 error. I also tried using a javascript object ({param1, param2}) and an array ([param1, param2]) but got Invalid number of parameters error.

- First parameter it’s an Address account. Must be formatted in any way?
I tried using the property request.user.attributes.ethAddress but didn’t work. By the way, i logged the request attribute and it’s correct (my wallet address).

Finally, i tried to execute the function using Moralis.executeFunction with the same parameters on the front and worked perfect.

So, it’s possible execute payable functions on cloud functions? Moralis SDK will transmit the signature request to front application and await for the approval of the metamask client?

Thanks alot.

You can not do that from a cloud function, you’ll have to do it from front end.

1 Like

I was afraid you confirm my suspicions. :pensive: Thks.

Actually you can send transaction from cloud functions, but you need to sign the transaction. You can use 2 ways:

  1. Provide your private key to cloud functions(unsafe method)
  2. I haven’t tested it before. But I guess it should work: You can sign transaction on front-end and send it on cloud functions. Take a look at:

https://web3js.readthedocs.io/en/v1.2.11/web3-eth-accounts.html#eth-accounts-signtransaction
https://web3js.readthedocs.io/en/v1.2.11/web3-eth.html#sendsignedtransaction

But you should think about whether it makes sense to transfer this logic to the backend :face_with_monocle:

Thanks @Yomoo, the first option it’s not an option :slight_smile:, i’m trying to oversecure a transaction using an enviroment variable (config variables on Moralis) and store PKs from clients doesn’t sound pretty at all (Unless you want to do a money theft system :stuck_out_tongue:). I will study the second option, but surely, will design a better way to manage what i want to do.

1 Like

Wish you success and feel free to ask any questions :man_mechanic:

1 Like