Skip to content

Commit 85cfa68

Browse files
committed
feat(contract): Method getAbi - refac + test + docs
1 parent 3350b56 commit 85cfa68

File tree

5 files changed

+126
-87
lines changed

5 files changed

+126
-87
lines changed

dist/web3data.min.js

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2595,7 +2595,7 @@
25952595
*
25962596
* @param hash - The address.
25972597
* @returns The detailed information for the specified contract.
2598-
* @example
2598+
* @example const details = await web3data.contract.getDetails('0x06012c8cf97bead5deae237070f9587f8e7a266d')
25992599
*/
26002600
getDetails(hash) {
26012601
throwIf$2(is$3.notHash(hash), NO_ADDRESS$2);
@@ -2625,14 +2625,17 @@
26252625
})
26262626
}
26272627

2628-
getAbi(hash, filterOptions) {
2629-
if (is$3.notHash(hash)) return Promise.reject(new Error(NO_ADDRESS$2))
2630-
return get$3(this.web3data, {
2631-
pathParam: hash,
2632-
endpoint: ENDPOINT$2,
2633-
subendpoint: 'abi',
2634-
filterOptions
2635-
})
2628+
/**
2629+
* Retrieves the contract's abi.
2630+
*
2631+
* @param hash - The contract address.
2632+
* @returns The abi of the contract.
2633+
* @example
2634+
* const abi = await web3data.contract.getAbi('0x06012c8cf97bead5deae237070f9587f8e7a266d')
2635+
*/
2636+
getAbi(hash) {
2637+
throwIf$2(is$3.notHash(hash), NO_ADDRESS$2);
2638+
return this.getDetails(hash).then(({abi}) => abi)
26362639
}
26372640

26382641
getSourceCode(hash, filterOptions) {

docs/api.md

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -641,7 +641,7 @@ Retrieves all the detailed information for the specified contract (ABI, bytecode
641641
##### Examples
642642

643643
```javascript
644-
644+
const details = await web3data.contract.getDetails('0x06012c8cf97bead5deae237070f9587f8e7a266d')
645645
```
646646

647647

@@ -654,6 +654,39 @@ Retrieves all the detailed information for the specified contract (ABI, bytecode
654654

655655

656656

657+
#### getAbi(hash)
658+
659+
660+
Retrieves the contract's abi.
661+
662+
663+
664+
665+
##### Parameters
666+
667+
| Name | Type | Description | |
668+
| ---- | ---- | ----------- | -------- |
669+
| hash | | The contract address. |   |
670+
671+
672+
673+
674+
##### Examples
675+
676+
```javascript
677+
const abi = await web3data.contract.getAbi('0x06012c8cf97bead5deae237070f9587f8e7a266d')
678+
```
679+
680+
681+
##### Returns
682+
683+
684+
- The abi of the contract.
685+
686+
687+
688+
689+
657690
### src/market.js
658691

659692

src/contract.js

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ class Contract {
2323
*
2424
* @param hash - The address.
2525
* @returns The detailed information for the specified contract.
26-
* @example
26+
* @example const details = await web3data.contract.getDetails('0x06012c8cf97bead5deae237070f9587f8e7a266d')
2727
*/
2828
getDetails(hash) {
2929
throwIf(is.notHash(hash), NO_ADDRESS)
@@ -53,14 +53,17 @@ class Contract {
5353
})
5454
}
5555

56-
getAbi(hash, filterOptions) {
57-
if (is.notHash(hash)) return Promise.reject(new Error(NO_ADDRESS))
58-
return get(this.web3data, {
59-
pathParam: hash,
60-
endpoint: ENDPOINT,
61-
subendpoint: 'abi',
62-
filterOptions
63-
})
56+
/**
57+
* Retrieves the contract's abi.
58+
*
59+
* @param hash - The contract address.
60+
* @returns The abi of the contract.
61+
* @example
62+
* const abi = await web3data.contract.getAbi('0x06012c8cf97bead5deae237070f9587f8e7a266d')
63+
*/
64+
getAbi(hash) {
65+
throwIf(is.notHash(hash), NO_ADDRESS)
66+
return this.getDetails(hash).then(({abi}) => abi)
6467
}
6568

6669
getSourceCode(hash, filterOptions) {

test/contract.test.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,9 @@ test('throws exception when calling getAudit without hash', async t => {
5454
});
5555

5656
/*********** Test getAbi() ***********/
57-
test('Successfully gets contract abi', async t => {
58-
let response = await t.context.web3data.contract.getAbi(TOKEN_ADDRESS);
59-
t.is(response.status, 200)
57+
test('Successfully calls getAbi()', async t => {
58+
const abi = await t.context.web3data.contract.getAbi(TOKEN_ADDRESS);
59+
t.true(Array.isArray(abi))
6060
});
6161
test('throws exception when calling getAbi without hash', async t => {
6262
await t.throwsAsync(async () => {

0 commit comments

Comments
 (0)