aquí está el código como se explica en web3 doc (nodo: 13887)
web3.eth.estimateGas({data: '0x' + bytecode}).then(value=>{
console.log('gasEstimate = ' + value);
let MyContract = new web3.eth.Contract(abi,{
from: publicKey,//user wallet
gasPrice: '10000000000000',
gas: value
});
console.log('deploying contract...');
MyContract.deploy().send(function(error, transactionHash){
}).on('error', function(error){ })
.on('transactionHash', function(transactionHash){ })
.on('receipt', function(receipt){
console.log(receipt.contractAddress) // contains the new contract address })
.on('confirmation', function(confirmationNumber, receipt){ })
.then(function(newContractInstance){
console.log(newContractInstance.options.address) // instance with the new contract address
});
});
aquí hay un mensaje de error
UnhandledPromiseRejectionWarning: Error: Request failed with status code 522
at createError (/home/project/node_modules/axios/lib/core/createError.js:16:15)
at settle (/home/project/node_modules/axios/lib/core/settle.js:18:12)
at IncomingMessage.handleStreamEnd (/home/project/node_modules/axios/lib/adapters/http.js:201:11)
at emitNone (events.js:111:20)
at IncomingMessage.emit (events.js:208:7)
at endReadableNT (_stream_readable.js:1064:12)
at _combinedTickCallback (internal/process/next_tick.js:138:11)
at process._tickCallback (internal/process/next_tick.js:180:9)
(node:13887) 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: 2)
(node:13887) [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.
EDITAR
Gracias a todo esto es un código de trabajo.
web3.eth.estimateGas({data: '0x' + bytecode}).then(value=>{
let MyContract = new web3.eth.Contract(abi,{
from: publicKey,
gasPrice: 1000000,
gas: value
});
MyContract.deploy({
data: '0x' + bytecode
}).send({
from: publicKey,
gasPrice: 1000000,
gas: value
},function(error, transactionHash){})
.on('error', function(error){ })
.on('transactionHash', function(transactionHash){ })
.on('receipt', function(receipt){})
.on('confirmation', function(confirmationNumber, receipt){ })
.then(function(newContractInstance){ });
});
Olvidó enviar la información que se requiere para implementar el contrato. Según el documento, debe proporcionar el código de bytes y los argumentos del constructor de su contrato a la función deploy
.
myContract.deploy({
data: '0x12345...',
arguments: [123, 'My String']
})
.send({
from: '0x1234567890123456789012345678901234567891',
gas: 1500000,
gasPrice: '30000000000000'
}, function(error, transactionHash){ ... })
.on('error', function(error){ ... })
.on('transactionHash', function(transactionHash){ ... })
.on('receipt', function(receipt){
console.log(receipt.contractAddress) // contains the new contract address
})
.on('confirmation', function(confirmationNumber, receipt){ ... })
.then(function(newContractInstance){
console.log(newContractInstance.options.address) // instance with the new contract address
});
El código de estado 522 es tiempo de espera de conexión HTTP. Compruebe si configuró el proveedor y creó la instancia web3 correctamente. Compruebe también su estado de Internet.
let MyContract = new web3.eth.Contract(abi, ...
. Lo que debe hacer es exactamente lo que dijo mirgi, simplemente intente pasar los datos como contract.deploy({data: your_bytecode}), si tiene argumentos de constructor, entonces pase los argumentos.
buena vibración
MyContract.deploy()
con(await MyContract.deploy())
... Y, por supuesto, declarar la función completaasync
.mirg
then
kherwa