string bytecode throws error in ContractFactory
See original GitHub issueHere 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:
- Created 3 years ago
- Comments:5 (3 by maintainers)
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Absolutely! Many thanks.
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)