Hey, is there any example of a working erc20 transfer on matic mainnet? When I attempt to call a transfer of the (POS) Dai token it hangs for 750 seconds before erroring. This is using Infura and Web3. There’s not really any working documentation that explains how to transfer assets on the network, only between.
var polyweb3 = new Web3(new Web3.providers.HttpProvider(`https://polygon-mainnet.infura.io/v3/${infura}`))
var contract = new polyweb3.eth.Contract(config.daiAbiArray, "0x8f3cf7ad23cd3cadbd9735aff958023239c6a063") // abi from https://polygonscan.com/address/0x490e379c9cff64944be82b849f8fd5972c7999a7#code
var data = contract.methods.transfer(to, amount)
var gasLimit = 75000 // fallback
await data.estimateGas({from: from})
.then(gasAmount => {
gasLimit = gasAmount
}).catch(e => {
console.error(e)
})
// fill data of contract
var rawTransaction = {
from: from,
to: "0x8f3cf7ad23cd3cadbd9735aff958023239c6a063",
gasLimit: polyweb3.utils.toHex(gasLimit),
gasPrice: gasPrice,
value: '0x0',
data: data.encodeABI(),
chainId: 137,
nonce: polyweb3.utils.toHex(count)
}
var transaction = new Tx(rawTransaction)
// Sign transaction
transaction.sign(privateKey)
var serialized = transaction.serialize()
// Send transaction
polyweb3.eth.sendSignedTransaction('0x'+serialized.toString('hex'))
.then(rcpt => {
console.log(rcpt)
return cb(true, rcpt.transactionHash)
})
.catch(err => {
return cb(false, err)