Last active
May 4, 2019 12:38
-
-
Save chebykin/d0b327c18e6ba8f633841f922216526d to your computer and use it in GitHub Desktop.
Verify contracts using Blockscout API
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const axios = require('axios'); | |
const assert = require('assert'); | |
axios.interceptors.request.use(request => { | |
console.log('Starting Request', request); | |
return request; | |
}); | |
const base = 'https://explorer.testnet.galtproject.io'; | |
const COMPILER_VERSION = 'v0.5.7+commit.6da8b019'; | |
const OPTIMIZATION = false; | |
const source = | |
'pragma solidity 0.5.7; contract MyContractStorage { mapping(bytes32 => address) public contracts; function setContract(bytes32 _key, address _value) external { contracts[_key] = _value; } }'; | |
const EVM_VERSION = 'petersburg'; | |
const verifyGet = async (name, addressHash, optimization, compilerVersion, contractSourceCode) => { | |
assert.ok(name); | |
assert.ok(addressHash); | |
assert.ok(compilerVersion); | |
const params = { | |
module: 'contract', | |
action: 'verify', | |
name, | |
addressHash, | |
compilerVersion, | |
contractSourceCode, | |
evmVersion: EVM_VERSION, | |
optimization: !!optimization | |
}; | |
try { | |
const response = await axios({ | |
url: '/api', | |
method: 'get', | |
baseURL: base, | |
params | |
}); | |
const { data } = response; | |
console.log(data); | |
} catch (error) { | |
console.log(error); | |
} | |
}; | |
const verifyPost = async (name, addressHash, optimization, compilerVersion, contractSourceCode) => { | |
assert.ok(name); | |
assert.ok(addressHash); | |
assert.ok(compilerVersion); | |
const params = { | |
module: 'contract', | |
action: 'verify', | |
name, | |
address_hash: addressHash, | |
compiler_version: compilerVersion, | |
contract_source_code: contractSourceCode, | |
evmVersion: EVM_VERSION, | |
optimization: !!optimization | |
}; | |
try { | |
const response = await axios({ | |
url: '/api/v1/verified_smart_contracts', | |
method: 'post', | |
baseURL: base, | |
data: params | |
}); | |
const { data } = response; | |
console.log(data); | |
} catch (error) { | |
console.log(error); | |
} | |
}; | |
// verifyPost('MyContractStorage', '0xe74aef820d13cce919ba5327e6e0a532c44cf2e8', OPTIMIZATION, COMPILER_VERSION, source); | |
verifyGet('MyContractStorage', '0xa95441b9149d25412afc757feb22108a3de72ddd', OPTIMIZATION, COMPILER_VERSION, source); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment