0

I have downloaded contracts with their abi and json. I have to deploy them. when i extract bytecode from downloaded files and then assign it to my data variable to deploy contract whic gives following error; Same error related question asked earlier here, but no answer is given.

UnhandledPromiseRejectionWarning: Error: The data field must be HEX encoded data.

here is my code;

async function deployCon(key) {

  var v = constructorParameters[key].input.length;
// console.log("deploy for contract : ", v)

const contract = new web3.eth.Contract(abi[key]);
if(v == 0) {
  params = {
    data: "0x" + bytecode[key],
};
}
else {
  params = {
    data: "0x" + bytecode[key],
    arguments: constructorParameters[key].input
};
}

const transaction = contract.deploy(params); 
const options = {
    data: transaction.encodeABI(),
    gas: await transaction.estimateGas({from: account1})
};

const signed = await web3.eth.accounts.signTransaction(options, privateKey1);
receipt = await web3.eth.sendSignedTransaction(signed.rawTransaction);
console.log(`Contract deployed at address: ${receipt.contractAddress}`);
return receipt;

}

and here is my bytecode[key] value

606060405260018054600160a060020a031916........

NOTE: I have just tried above code for the contract see here

  • As I explained to you on that other question of yours - this method of copying someone else's bytecode including the construction arguments is prone to a miserable failure! Any argument which is an address of an account or a contract, will potentially make the deployed contract unusable for you, if you even manage to deploy it without reverting (due to various checks or calls that the constructor might be making to any of those addresses). Once again - you should use the source code, and input your own construction arguments. – goodvibration Nov 29 '19 at 11:26
  • yes, you are right.. But when i take source code and compile above contracts (more than 800 ) then it will give error , because , i think, different contract had been created with different versions of solidity. That's why i just take their ABIs and bytecodes . BTW, is there any repository which contain contracts of latest version only. One by one by downloading specific contract from etherscan.io is not feasible ... – Amir Ali Nov 29 '19 at 12:10
  • why would you need to use random contracts which were written in an old solidity version? – Niklas Feurstein Nov 30 '19 at 12:36
  • I need any contracts, but should be run through program blindly without knowing their logic... – Amir Ali Dec 1 '19 at 4:18
2

Your Bytecode isn't a hex number.

Prepend a 0x.

For example 0x606060405260018054600160a060020a031916...

EDIT: Nevermind you already did that. Here is another try. Convert the string to hex.

parseInt("0x6060604...", 16)

Take note of the radix 16. Leave this value unchanged.

  • I have done as per your direction, but same error... – Amir Ali Nov 30 '19 at 3:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.