Transfiera el token ERC20 en la red principal con web3js (éxito en ropsten, falló en la red principal)

Quiero transferir algunos tokens ERC20 en ethereum. Hice un poco de trabajo de preparación y probé en ropsten, tuvo éxito. Luego cambié la API utilizada, la dirección de la billetera, httpProvicer, la dirección del contrato y ejecuté el código, pero falló. No encontré por qué. ¿Usted me podría ayudar?

A continuación se muestra la parte principal de mi código.

web3 = new Web3(new Web3.providers.HttpProvider("https://mainnet.infura.io/xxxx"));
let WALLETBASE = "xxx";      
let contractAddr = "xxx";    
let gasPrice = web3.utils.toHex(41 * 10^9); //41gwei

let abi = JSON.parse(fs.readFileSync("./file.abi").toString("utf8"));
let contractInstance = new web3.eth.Contract(abi, contractAddr);
function setAllocation(_nonce, _to, _amount){
console.log('prepare for new transaction: %s %s', _to, _amount);
var transfer_amount = _amount + '000000000000000000';
let data = web3.utils.sha3("transfer(address,uint256)").substr(0,10)    
            + "000000000000000000000000"                                
            + _to.substr(2,40)                                          
            + "00000000000000000000000000000000"                        
            + toHex32(transfer_amount);                                         
var noncehex = "0x" + _nonce.toString(16);
// console.log('data: ' + data);

web3.eth.estimateGas({
    "from" : WALLETBASE,
    "nonce": noncehex,
    "to"   : contractAddr,
    "data" : data
}).then((value) => {
    console.log("gas limit: " + value);
    var signedTx = {
        "from"      : WALLETBASE,       
        "nonce"     : noncehex, 
        "gasPrice"  : gasPrice,         
        "gasLimit"  : value,
        "to"        : contractAddr,     
        "value"     : "0x00",
        "data"      : data,
        "chainId"   : 1
    }

    var privateKey = new Buffer.from("xxxx", 'hex');
    var tx = new Tx(signedTx);
    tx.sign(privateKey);
    var serializedTx = tx.serialize();

    try{
        web3.eth.sendSignedTransaction('0x' + serializedTx.toString('hex'),
            function(err, hash) {
            if (!err) {
                console.log("-------------------");
                console.log("to: " + _to);
                console.log("TxHash: " + hash);
            } else {
                console.log("=====error occur=====");
                console.log(err);
            }
        });
    }catch(err){
        console.log('ERROR: ' + err);
    }
});
}

cuando ejecuto el código, toma mucho tiempo sin ninguna respuesta. durante unos 5 minutos, recibí el error:

(node:1336) UnhandledPromiseRejectionWarning: Error: Transaction was not mined within750 seconds, please make sure your transaction was properly sent. Be aware that it might still be mined!
at /Users/.../node_modules/web3-core-method/src/index.js:392:42
at process._tickCallback (internal/process/next_tick.js:178:7)
(node:1336) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1)
(node:1336) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

PD: la dirección de la billetera no me pertenece. El propietario me dio la clave privada y transfiero tokens en su nombre. ¿Hay algún problema de autorización de identidad?

¿Qué error estás recibiendo?
¡Agregué la información del error!
¿Tienes el hash de la transacción? El gas parece suficiente. ¿Cómo se obtiene la transacción nonce? El formato de la entrada de la transacción no parece lo suficientemente flexible, si pierde un '0' allí, podría terminar enviando a la dirección incorrecta o una cantidad incorrecta. ¿Por qué no usa una biblioteca como web3 para formatear la transacción? ERC20 son bastante comunes y puede obtener el ABI fácilmente.
hola Ismael, si tengo el hash de transaccion. pero cuando lo busqué, dijo que no se pudo ubicar el txhash. Hasta ahora, han pasado 18 horas y todavía no se podía ver esa transacción en mi dirección.

Respuestas (1)

Tus transacciones están siendo enviadas. Ese es un mensaje de advertencia.

Además, su código no finaliza porque espera a que se extraiga su transacción y luego le devuelve la llamada exitosa.

En su lugar, puede obtener el recibo y verificar el estado de tx en una llamada separada.

web3.eth.sendSignedTransaction('0x' + serializedTx.toString('hex'))
.on('receipt', console.log);
Han pasado 18 horas y todavía no obtuve ninguna respuesta. y no pude localizar la transacción por txhash. Supongo que tal vez haya alguna otra razón.