compileHasher.js 998 B

123456789101112131415161718192021222324252627282930313233343536
  1. // Generates Hasher artifact at compile-time using Truffle's external compiler
  2. // mechanism
  3. const path = require('path')
  4. const fs = require('fs')
  5. const genContract = require('circomlib/src/poseidon_gencontract.js')
  6. // where Truffle will expect to find the results of the external compiler
  7. // command
  8. const outputPath = path.join(__dirname, 'build', 'contracts')
  9. const outputPath2 = path.join(outputPath, 'Hasher2.json')
  10. const outputPath3 = path.join(outputPath, 'Hasher3.json')
  11. if (!fs.existsSync(outputPath)) {
  12. fs.mkdirSync(outputPath, { recursive: true })
  13. }
  14. function main() {
  15. const contract2 = {
  16. contractName: 'Hasher2',
  17. abi: genContract.generateABI(2),
  18. bytecode: genContract.createCode(2),
  19. }
  20. fs.writeFileSync(outputPath2, JSON.stringify(contract2, null, 2))
  21. const contract3 = {
  22. contractName: 'Hasher3',
  23. abi: genContract.generateABI(3),
  24. bytecode: genContract.createCode(3),
  25. }
  26. fs.writeFileSync(outputPath3, JSON.stringify(contract3, null, 2))
  27. }
  28. main()