Skip to content
This repository was archived by the owner on Dec 26, 2024. It is now read-only.

Commit 0f444f0

Browse files
committed
feature: add getsourcecode method
1 parent 0047627 commit 0f444f0

File tree

2 files changed

+35
-4
lines changed

2 files changed

+35
-4
lines changed

lib/contract.js

+24-4
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,7 @@ module.exports = function(getRequest, apiKey) {
66
* @param {string} address - Contract address
77
* @example
88
* api.contract
9-
* .getabi('0xfb6916095ca1df60bb79ce92ce3ea74c37c5d359')
10-
* .at('0xfb6916095ca1df60bb79ce92ce3ea74c37c5d359')
11-
* .memberId('0xfb6916095ca1df60bb79ce92ce3ea74c37c5d359')
9+
* .getabi('0xBB9bc244D798123fDe783fCc1C72d3Bb8C189413')
1210
* .then(console.log)
1311
* @returns {Promise.<object>}
1412
*/
@@ -21,6 +19,28 @@ module.exports = function(getRequest, apiKey) {
2119
});
2220

2321
return getRequest(query);
24-
}
22+
},
23+
/**
24+
* Returns the Sourcecode of a given verified contract
25+
* @param {string} address - Contract address
26+
* @example
27+
* api.contract
28+
* .getsourcecode('0xBB9bc244D798123fDe783fCc1C72d3Bb8C189413')
29+
* .then(console.log)
30+
* @returns {Promise.<object>}
31+
*/
32+
getsourcecode(address) {
33+
const module = 'contract';
34+
const action = 'getsourcecode';
35+
36+
var query = querystring.stringify({
37+
module, action, address, apiKey
38+
});
39+
40+
return getRequest(query);
41+
},
42+
43+
44+
2545
};
2646
};

test/methods-test.js

+11
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,17 @@ describe('api', function() {
169169
});
170170
});
171171

172+
it('contract.getsourcecode', function(done){
173+
var api = init(process.env.API_KEY);
174+
var abi = api.contract.getsourcecode('0xBB9bc244D798123fDe783fCc1C72d3Bb8C189413');
175+
abi.then(function(){
176+
assert.ok(true);
177+
done();
178+
}).catch(err=> {
179+
assert.equal(err, 'Contract source code not verified');
180+
done();
181+
});
182+
}).timeout(100000);
172183

173184

174185
describe('proxy', function() {

0 commit comments

Comments
 (0)