-
Notifications
You must be signed in to change notification settings - Fork 0
/
verify.js
91 lines (81 loc) · 2.22 KB
/
verify.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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
require('dotenv').config()
const ethers = require('ethers')
const axios = require('axios')
const path = require('path')
const fs = require('fs')
const solc = require('solc')
const qs = require('qs')
const config = require('./config').default
const main = async () => {
const contractAddress = process.argv[2]
if (!contractAddress) return
const { sourceName, contractName, constructorArguments } = config
const contractPath = path.resolve(__dirname, 'contracts', sourceName)
const source = fs.readFileSync(contractPath, 'utf8')
const input = {
language: 'Solidity',
sources: {
[sourceName]: {
content: source,
},
},
settings: {
optimizer: {
runs: 200,
enabled: true,
},
outputSelection: {
'*': {
'*': ['*'],
},
},
},
}
const solcVersion = JSON.parse(
JSON.parse(solc.compile(JSON.stringify(input))).contracts[sourceName][
contractName
].metadata,
).compiler.version
const factory = ethers.ContractFactory.fromSolidity(
JSON.parse(solc.compile(JSON.stringify(input))).contracts[sourceName][
contractName
],
)
console.log(
'Verifying the source code on Etherscan:',
contractAddress,
`${sourceName}:${contractName}`,
solcVersion,
)
axios({
method: 'POST',
url:
config.deployment.network === 'mainnet'
? 'https://api.etherscan.io/api'
: 'https://api-rinkeby.etherscan.io/api',
headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
data: qs.stringify({
apiKey: process.env.ETHERSCAN_API_KEY,
module: 'contract',
action: 'verifysourcecode',
contractaddress: contractAddress,
sourceCode: JSON.stringify(input),
codeformat: 'solidity-standard-json-input',
contractname: `${sourceName}:${contractName}`,
compilerversion: `v${solcVersion}`,
optimizationUsed: 1,
runs: 200,
constructorArguements: factory.interface
.encodeDeploy(constructorArguments)
.slice(2),
}),
}).then((r) => {
console.log('Verification result: ', r.data.result)
})
}
main()
.then(() => process.exit(0))
.catch((error) => {
console.error(error)
process.exit(1)
})