question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

string bytecode throws error in ContractFactory

See original GitHub issue

Here is the line of code to initialize a contract with ContractFactory:

 const factory = new ContractFactory(abi, bytecode, wallet); 

When abi is an array […] and bytecode is in JS object {…}, the execution of the above is fine. However when bytecode comes in string and passed in to ContractFactory as JSON.parse(bytecode), then there is an error:

     Possible Unhandled Promise Rejection (id: 0):
    SyntaxError: JSON Parse error: Unexpected identifier "object" parse@[native code]

If both abi and bytecode are in string, how to pass them to ContractFactory in correct format? The doc says the abi is interface and bytecode is string.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
emclabcommented, Jan 22, 2021

Absolutely! Many thanks.

0reactions
ricmoocommented, Jan 22, 2021

Actually looking at the code, it does support natively the bytecode object from Solidty.

You should not convert it to a string using toString(). That discards it’s structure. If you need to serialize it as a string, you need to use JSON.stringify(bytecode).

Let me know if that works.

(Note: if you are storing this in your database, it would save your db a lot of space-time to store just the value of "object" instead)

Read more comments on GitHub >

github_iconTop Results From Across the Web

ContractFactory - Ethers.js
The Contract Factory sends a special type of transaction, an initcode transaction (i.e. the to field ... contractFactory.bytecode ⇒ string< DataHexString >.
Read more >
ByteCode produced by hardhat compilation incompatible with ...
js ContractFactory constructor to throw an invalid bytecode error. Examing what's actually in the json, most of it looks like a hex string,...
Read more >
Getting error when trying to forceImport ABIs for upgrades
I have the old abis (the ones that are currently deployed) on a folder in my repository called "oldAbis". My code looks something...
Read more >
ContractFactory - Hethers - Hedera
contractFactory.bytecode ⇒ string< DataHexString >. The bytecode (i.e. initcode) that ... throws on failure (the reciept is on the error). await contract.
Read more >
I use ethers.js deployment contract, but returned error ...
getSigner() console.log("Account:", await signer.getAddress()); const factory = new ethers.ContractFactory( bodyJSON2.abi, bodyJSON2.bytecode, ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found