-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcleanABI.js
34 lines (26 loc) · 936 Bytes
/
cleanABI.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
const fs = require('fs')
const path = require('path')
// Assuming 'LandRegistry.json' contains your ABI
const abiPath = path.resolve(__dirname, 'public', 'LandNFT.json')
try {
// Read ABI file
const abiJSON = fs.readFileSync(abiPath, 'utf8')
console.log('Read ABI JSON:', abiJSON) // Debugging output
// Parse JSON into an array
let abi = JSON.parse(abiJSON).abi
if (!Array.isArray(abi)) {
throw new Error('ABI is not an array')
}
// Clean the ABI by filtering out error entries
const cleanAbi = abi.filter((fragment) => fragment.type !== 'error')
// Optionally, write the cleaned ABI back to a file
const cleanedAbiPath = path.resolve(
__dirname,
'public',
'cleanedLandNFT.json'
)
fs.writeFileSync(cleanedAbiPath, JSON.stringify(cleanAbi, null, 2))
console.log('ABI cleaned and saved to cleanedLandNFT.json')
} catch (error) {
console.error('Error cleaning ABI:', error.message)
}