1
0
mirror of https://github.com/oceanprotocol/ocean.js.git synced 2024-11-26 20:39:05 +01:00

add decimals() function

This commit is contained in:
Miquel A. Cabot 2022-05-27 10:55:12 +02:00
parent a7c0cff63c
commit b3102c78c1
2 changed files with 12 additions and 0 deletions

View File

@ -117,6 +117,7 @@ export async function getPoolCreationParams(
]
}
}
export async function unitsToAmount(
web3: Web3,
token: string,

View File

@ -183,3 +183,14 @@ export async function balance(
return await unitsToAmount(web3, tokenAddress, trxReceipt, tokenDecimals)
}
/**
* Get decimals for any erc20
* @param {Web3} web3
* @param {String} tokenAdress
* @return {Promise<number>} Number of decimals of the token
*/
export async function decimals(web3: Web3, tokenAddress: string): Promise<number> {
const tokenContract = new web3.eth.Contract(minAbi, tokenAddress)
return await tokenContract.methods.decimals().call()
}