Skip to main content
2 of 3
deleted 36 characters in body

Cannot send USDT on Polygon : Error happened while trying to execute a function inside a smart contract

//token_address is the adress of the contract : 0xc2132D05D31c914a87C6611C10748AEb04B58e8F
//minABI is the abi of the USDT contract on ETH, since the one on Polygon has no methods decimals or transfer
let contract = new web3.eth.Contract(minABI, token_address);

//Calculate the amount to transfer. In this example I want to transfer 5.44 usdt
let decimals_bn = await contract.methods.decimals().call();
const base = new BigNumber(10);
const amount_to_transfer = base.pow(decimals_bn).times(balance);//this gives 5440000 which seems correct

//Transaction count for nonce
let transaction_count = await web3.eth.getTransactionCount(account_from.address);

//Get gas price 
let gas_price = await web3.eth.getGasPrice();

//Estimate gas 
let estimated_gas = await web3.eth.estimateGas({from: account_from.address});

const createTransaction = await web3.eth.accounts.signTransaction(
{
    from: account_from.address,
    nonce: web3.toHex(transaction_count),
    gasPrice: web3.utils.toHex(gas_price),
    gas: web3.utils.toHex(estimated_gas),
    //gasLimit: web3.utils.toHex(estimated_gas),//I tried with gas , gasLimit or both         
    to: token_address,
    value: "0x0",
    data: contract.methods.transfer(adress_to, web3.toHex(amount_to_transfer)).encodeABI(),
    },
account_from.privateKey
);

//this is when the error trigger
await web3.eth.sendSignedTransaction(createTransaction.rawTransaction);

//Error : 'Error happened while trying to execute a function inside a smart contract'

48 hours on this matter and still no solution. I don't know if the problem is related to gas value or to something else.

Please advise, any help is appreciated.