Skip to content

Instantly share code, notes, and snippets.

@Daltonic
Created December 22, 2023 18:21
Show Gist options
  • Save Daltonic/021ee2f4d05f4f7c1e80452e6fdd263f to your computer and use it in GitHub Desktop.
Save Daltonic/021ee2f4d05f4f7c1e80452e6fdd263f to your computer and use it in GitHub Desktop.
Event X
const { ethers } = require('hardhat')
const fs = require('fs')
async function deployContract() {
let contract
const servicePct = 5
try {
contract = await ethers.deployContract('DappEventX', [servicePct])
await contract.waitForDeployment()
console.log('Contracts deployed successfully.')
return contract
} catch (error) {
console.error('Error deploying contracts:', error)
throw error
}
}
async function saveContractAddress(contract) {
try {
const address = JSON.stringify(
{
dappEventXContract: contract.target,
},
null,
4
)
fs.writeFile('./contracts/contractAddress.json', address, 'utf8', (error) => {
if (error) {
console.error('Error saving contract address:', err)
} else {
console.log('Deployed contract address:', address)
}
})
} catch (error) {
console.error('Error saving contract address:', error)
throw error
}
}
async function main() {
let contract
try {
contract = await deployContract()
await saveContractAddress(contract)
console.log('Contract deployment completed successfully.')
} catch (error) {
console.error('Unhandled error:', error)
}
}
main().catch((error) => {
console.error('Unhandled error:', error)
process.exitCode = 1
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment