-
Couldn't load subscription status.
- Fork 3.3k
-
At this point of the course I was following the typing out of this code.
async function updateAbi() { const raffle = await ethers.getContract("Raffle") fs.writeFileSync( FRONTEND_ABI_FILE, raffle.interface.format(ethers.utils.FormatTypes.json)
As the last line is getting typed out, the video quickly cuts to the Ethers docs. At the same time, VScode suggests I replace json with JSON by hitting Enter. I do so (in VScode we trust).
I run yarn hardhat node to produce our .json files. I get the following error:
TypeError: The "data" argument must be of type string or an instance of Buffer, TypedArray, or DataView. Received an instance of Array
at Object.writeFileSync (node:fs:2163:5)
I try adding .toString() on the end. It goes through but the abi.json looks all weird and unformatted. Nope, next.
After tinkering around and googling for like 15 minutes, while looking at the Ethers docs I try putting it back to lowercase .json. It goes through and my abi.json looks beauuutiful!!
Just a heads-up for anyone potentially searching the Discussions for this error (I didn't find any); might save them some time and frustration, it made my eyes roll how a VScode suggestion made the code break like this lol.
Take note when VScode suggests you something. You could overlook it and it can break your code later.
Cheers
Beta Was this translation helpful? Give feedback.
All reactions
Replies: 3 comments 1 reply
-
Bruv I used .json in lowercase itself, but I'm not getting an abi.json output. Do you have any ideas why? My contract addresses JSON file is all perfect, but I'm getting errors here. Do you have any idea?
Beta Was this translation helpful? Give feedback.
All reactions
-
No idea mate, show some of your code, like your updateAbi() function, your FRONT_END_ABI_FILE variable, etc. we can start there
Beta Was this translation helpful? Give feedback.
All reactions
-
instead of this
fs.writeFileSync(FRONT_END_ABI_FILE, raffle.interface.format(ethers.utils.FormatTypes.JSON));
try this
fs.writeFileSync(FRONT_END_ABI_FILE, JSON.stringify(raffle.interface));
Beta Was this translation helpful? Give feedback.
All reactions
-
In ethers 6, you can use the formatJson() function to get the same thing that Patrick.
The doc : https://docs.ethers.org/v6/api/abi/#Interface-formatJson
The line to write the contract ABI :
fs.writeFileSync(FRONT_END_ABI_FILE, raffle.interface.formatJson());
Beta Was this translation helpful? Give feedback.