diff --git a/src/__tests__/erc20/erc20.test.ts b/src/__tests__/erc20/erc20.test.ts index f9429fe..c991376 100644 --- a/src/__tests__/erc20/erc20.test.ts +++ b/src/__tests__/erc20/erc20.test.ts @@ -213,7 +213,7 @@ test('erc20: transferFrom transaction', async () => { expect(tx.decoded).toEqual(decoded); }); -test('erc20: fetch symbol and totalSupply', async () => { +test('erc20: fetch symbol, totalSupply and decimals', async () => { const query = ` { block(number: 5600000) { @@ -226,6 +226,7 @@ test('erc20: fetch symbol and totalSupply', async () => { tokenContract { symbol totalSupply + decimals } from { account { @@ -254,6 +255,7 @@ test('erc20: fetch symbol and totalSupply', async () => { tokenContract: { symbol: 'NULS', totalSupply: 4e25, + decimals: 18, }, from: { account: { @@ -285,6 +287,7 @@ test('erc20: fetch null symbol', async () => { tokenContract { symbol totalSupply + decimals } from { account { @@ -313,6 +316,7 @@ test('erc20: fetch null symbol', async () => { tokenContract: { symbol: null, totalSupply: 1e27, + decimals: 18, }, from: { account: { @@ -347,6 +351,7 @@ test('erc20: fetch token balance of recipient (account 0x0)', async () => { } symbol totalSupply + decimals } from { account { diff --git a/src/abi/erc20.json b/src/abi/erc20.json index d867ed6..ffaa829 100644 --- a/src/abi/erc20.json +++ b/src/abi/erc20.json @@ -15,6 +15,14 @@ "payable": false, "type": "function" }, + { + "constant": true, + "inputs": [], + "name": "decimals", + "outputs": [{ "name": "", "type": "uint8" }], + "payable": false, + "type": "function" + }, { "constant": true, "inputs": [], diff --git a/src/erc20/model/index.ts b/src/erc20/model/index.ts index 25d5764..387d441 100644 --- a/src/erc20/model/index.ts +++ b/src/erc20/model/index.ts @@ -65,6 +65,13 @@ export class Erc20TokenContract { .call() .catch(() => undefined); } + + public async decimals() { + return this._contract.methods + .decimals() + .call() + .catch(() => undefined); + } } export class Erc20TokenHolder { diff --git a/src/erc20/schema/token.ts b/src/erc20/schema/token.ts index ee8f6e2..91101a7 100644 --- a/src/erc20/schema/token.ts +++ b/src/erc20/schema/token.ts @@ -8,5 +8,6 @@ type TokenContract { account: Account symbol: String totalSupply: Long + decimals: Int } `;