I have using ethers.js library for transfer token on two networks : BEP-20
and Pulse-chain
, when I send USDT on BEP-20 it works fine, but for USDT on pulsechain I get error gas estimate (missing revert data)
here is the message response of tx.wait() :
missing revert data (action=”estimateGas”, data=null, reason=null, transaction=…
and my type script code is :
import { HttpException } from '@nestjs/common';
import { CommandHandler, ICommandHandler } from '@nestjs/cqrs';
import { InternalServerError, Invalid_Network, Invalid_Token } from 'src/common/translates/Error.Translate';
import { ethers } from 'ethers';
import { Request_Was_Successful1 } from 'src/common/translates/successful.Translate';
import { DepositCommand } from './deposit.command';
import { InjectRepository } from '@nestjs/typeorm';
import { TokenEntity } from 'src/domains/transaction/entities/token.entity';
import { Repository } from 'typeorm';
@CommandHandler(DepositCommand)
export class DepositCommandHandler implements ICommandHandler<DepositCommand> {
constructor(
@InjectRepository(TokenEntity)
private readonly tokenRepository: Repository<TokenEntity>
) { }
async execute(command: DepositCommand): Promise<any> {
try {
const { networkName, tokenName, amount, toAddress } = command.body;
const token = await this.tokenRepository.findOne({
where: [{
tokenName: tokenName,
networkName: networkName
}]
});
if (!token) {
throw new HttpException(Invalid_Token, Invalid_Token.status_code);
}
let wallet: any;
const mainWalletPrivateKey = process.env.MAIN_WALLET_PRIVATE_KEY;
if (networkName.toLowerCase() == 'bep-20') {
const bscProvider = await this.getResponsiveNode();
wallet = new ethers.Wallet(mainWalletPrivateKey, bscProvider);
} else if (networkName.toLowerCase() == 'pulse-chain') {
const pulseChainProvider = new ethers.JsonRpcProvider('https://rpc.pulsechain.com');
// const pulseChainProvider = new ethers.JsonRpcProvider('https://rpc-pulsechain.g4mm4.io');
// const pulseChainProvider = new ethers.JsonRpcProvider('https://pulsechain-rpc.publicnode.com');
wallet = new ethers.Wallet(mainWalletPrivateKey, pulseChainProvider);
} else {
throw new HttpException(Invalid_Network, Invalid_Network.status_code);
}
const contract = new ethers.Contract(token.contractAddress, JSON.parse(token.contractABI), wallet);
const decimals = await contract.decimals();
const amountInSmallestUnit = ethers.parseUnits(amount.toString(), decimals);
for (let attempt = 1; attempt <= 5; attempt++) {
const tx = await contract.transfer(toAddress, amountInSmallestUnit);
const receipt = await tx.wait();
console.log('receipt', receipt);
if (receipt.status === 1) {
const Request_Was_Successful = Request_Was_Successful1({
tx_receipt_hash: receipt.hash
});
throw new HttpException(
{
...Request_Was_Successful,
},
Request_Was_Successful.status_code,
);
}
}
} catch (error) {
console.log('error', error);
if (error.status === undefined) {
const formatError = InternalServerError(error.message);
throw new HttpException(formatError, formatError.status_code);
} else throw error;
}
}
async getResponsiveNode() {
const rpcNodes = [
'https://bsc-dataseed1.binance.org/',
'https://bsc-dataseed2.binance.org/',
'https://bsc-dataseed3.binance.org/',
'https://bsc-dataseed4.binance.org/'
];
for (let node of rpcNodes) {
try {
const provider = new ethers.JsonRpcProvider(node);
await provider.getBlockNumber();
console.log(`Responsive node found: ${node}`);
return provider;
} catch (error) {
console.log(`Node ${node} is not responsive.`);
}
}
throw new Error('No responsive nodes found');
}
}
I added the {gasLimit: 20000} to the transfer method and then it subract pls from my wallet and does not transfer the usdt :
const tx = await contract.transfer(toAddress, amountInSmallestUnit, {gasLimit: 20000});
const receipt = await tx.wait();
and return transaction reverted
thanks in advance