Skip to content
This repository has been archived by the owner on Jan 21, 2022. It is now read-only.

Add ERC20 decimal field support #115

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion src/__tests__/erc20/erc20.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -226,6 +226,7 @@ test('erc20: fetch symbol and totalSupply', async () => {
tokenContract {
symbol
totalSupply
decimals
}
from {
account {
Expand Down Expand Up @@ -254,6 +255,7 @@ test('erc20: fetch symbol and totalSupply', async () => {
tokenContract: {
symbol: 'NULS',
totalSupply: 4e25,
decimals: 18,
},
from: {
account: {
Expand Down Expand Up @@ -285,6 +287,7 @@ test('erc20: fetch null symbol', async () => {
tokenContract {
symbol
totalSupply
decimals
}
from {
account {
Expand Down Expand Up @@ -313,6 +316,7 @@ test('erc20: fetch null symbol', async () => {
tokenContract: {
symbol: null,
totalSupply: 1e27,
decimals: 18,
},
from: {
account: {
Expand Down Expand Up @@ -347,6 +351,7 @@ test('erc20: fetch token balance of recipient (account 0x0)', async () => {
}
symbol
totalSupply
decimals
}
from {
account {
Expand Down
8 changes: 8 additions & 0 deletions src/abi/erc20.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,14 @@
"payable": false,
"type": "function"
},
{
"constant": true,
"inputs": [],
"name": "decimals",
"outputs": [{ "name": "", "type": "uint8" }],
"payable": false,
"type": "function"
},
{
"constant": true,
"inputs": [],
Expand Down
7 changes: 7 additions & 0 deletions src/erc20/model/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,13 @@ export class Erc20TokenContract {
.call()
.catch(() => undefined);
}

public async decimals() {
return this._contract.methods
.decimals()
.call()
.catch(() => undefined);
}
}

export class Erc20TokenHolder {
Expand Down
1 change: 1 addition & 0 deletions src/erc20/schema/token.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,6 @@ type TokenContract {
account: Account
symbol: String
totalSupply: Long
decimals: Int
}
`;