-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathverify.js
More file actions
93 lines (77 loc) · 3.56 KB
/
Copy pathverify.js
File metadata and controls
93 lines (77 loc) · 3.56 KB
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
92
93
const request = require('request-promise-native')
const fs = require('fs')
const contractAddress = process.argv[2]
const contractPath = process.argv[3]
const contractName = process.env.CONTRACT_NAME || 'EthToSmthSwaps'
if (!contractAddress || !contractPath || contractAddress === '-h') {
console.log(`
Usage: node verify.js 0xc07rac7adde55 path/to/contract.sol
`)
process.exit(-1)
}
console.log('Verify contract')
console.log(' ADDRESS =', contractAddress)
console.log(' PATH =', contractPath)
const raw_source_code = fs.readFileSync(contractPath, 'utf8')
console.log(' CODE PREVIEW:')
const lines = raw_source_code.split("\n")
console.log(' ', lines.shift())
console.log(' ', lines.shift())
console.log(' ', lines.shift())
console.log(' ', lines.shift())
console.log(' ', lines.shift())
console.log(' ', '...')
const API_KEY = process.env.ETHERSCAN_API_KEY
if (!API_KEY) {
console.error(`
Error: Required 'ETHERSCAN_API_KEY'.
You need to set you key as an environment variable, e.g.
ETHERSCAN_API_KEY=... node verify.js
You can learn how to get a key at https://etherscancom.freshdesk.com/support/solutions/articles/35000022163-i-need-an-api-key
`)
process.exit(-1)
}
const URL = process.env.NETWORK === 'mainnet'
? `https://api.etherscan.io/api`
: `https://rinkeby.etherscan.io/api`
// Reference: https://etherscan.io/apis#contracts
//
// type: "POST", //Only POST supported
// url: "//api.etherscan.io/api", //Set to the correct API url for Other Networks
// data: {
// apikey: $('#apikey').val(), //A valid API-Key is required
// module: 'contract', //Do not change
// action: 'verifysourcecode', //Do not change
// contractaddress: $('#contractaddress').val(), //Contract Address starts with 0x...
// sourceCode: $('#sourceCode').val(), //Contract Source Code (Flattened if necessary)
// contractname: $('#contractname').val(), //ContractName
// compilerversion: $('#compilerversion').val(), // see http://etherscan.io/solcversions for list of support versions
// optimizationUsed: $('#optimizationUsed').val(), //0 = Optimization used, 1 = No Optimization
// runs: 200, //set to 200 as default unless otherwise
// constructorArguements: $('#constructorArguements').val(), //if applicable
// libraryname1: $('#libraryname1').val(), //if applicable, a matching pair with libraryaddress1 required
// libraryaddress1: $('#libraryaddress1').val(), //if applicable, a matching pair with libraryname1 required
// libraryname2: $('#libraryname2').val(), //if applicable, matching pair required
// libraryaddress2: $('#libraryaddress2').val(), //if applicable, matching pair required
// libraryname3: $('#libraryname3').val(), //if applicable, matching pair required
// libraryaddress3: $('#libraryaddress3').val(), //if applicable, matching pair required
// libraryname4: $('#libra
request
.post({
method: 'POST',
url: `${URL}`,
form: {
apikey: API_KEY,
module: 'contract',
action: 'verifysourcecode',
contractaddress: contractAddress,
sourceCode: raw_source_code,
contractname: contractName,
compilerversion: 'v0.5.0+commit.1d4f565a',
optimizationUsed: '1',
runs: 200,
// constructorArguements: '',
},
})
.then(console.log)
.catch(err => console.error(err.message))