How to use Moralis for ERC20 Token Transfer on POLYGON network?

we have a utility written in NODEJS that sends erc20 token on Ethereum mainet when user wants to withdraw , now we have moved to POLYOGON network and want to send transactions from our Polygon address to users owned Polygon address.

This article is the exact information we are looking for but with polygon network: https://moralis.io/erc20-transfer-how-to-transfer-erc20-tokens/

how possibly we can achieve this with moralis on polygon network ?

what is the exact question? what part you don’t know how to do?

question is that is it possible with moralis to implement erc20 send token with polygon network , if yes then where it is covered in the doc , all i see is based on Ethereum mainnet , you can refer me to the exact/relevant piece of code or documentation where it covers polygon network erc20 token transfer/send transactions tutorial/guide or maybe without moralis with javascript/nodejs .

i.e on this link : https://docs.moralis.io/moralis-server/sending-assets#transferring-erc20-tokens
there is piece of code to send erc20 token over Ethereum , how this can be used to send token over ploygon network addresses , meaning that what change is required is setting for polygon , assuming the example provided is for Ethereum

ok, got it, if you want to transfer on polygon network all you have to do is to have metamask connected on polygon network, same code will work on ethereum, polygon, bsc

yes but i want to implement it with nodejs , we have users polygon address and withdraw amount and nodeJs cron will fetch these details and process it over polygon , with metamask it a manual approach and it will not be possible to send to thousands of addresses that’s why looking for piece of code in javascript or moralis for bulk processing

ok, I think that you can not do it in nodejs with that sdk transfer function, you’ll have to use directly web3 or ethers with a private key and with a node RPC address

yes that is what i’m looking for , relevant doc , code or tutorial.

There is some example code for this question on this thread:

1 Like

Thank you @RedCabbage , i almost have almost same code for ethereum mainet and it works perfectly fine , would it work for polygon because im bit confused on the RPC endpoint which is not mentioned in the above code for polygon or Ethereum RPC

everything should work the same, you can get a RPC url from here in case that you don’t have one already: https://admin.moralis.io/speedyNodes

Yes, the code is identical for Polygon. The only difference is when you declare web3 (if you’re using Moralis), you set the chainId to the Polygon chain - or let MetaMask (etc) do it for you.

const web3 = Moralis.web3ByChain("0x89"); // 137 Polygon

or

await Moralis.enableWeb3(); // Since Moralis 1.0.0
const chain = window.ethereum; // From your plugin
const web3 = new Web3(chain);
1 Like

i was able to solve this by using the same code , I only added these 2 lines

let Web3 = require(‘web3’);
let web3 = new Web3(‘https://polygon-rpc.com’);

and its working perfectly fine now :slight_smile:

Thank You @cryptokid and @RedCabbage

2 Likes