Created
February 2, 2023 21:23
-
-
Save xdayeh/1020ff37fc4f1fd3290424356fa37327 to your computer and use it in GitHub Desktop.
Retrieve the price of any bsc token from it's address BNB smart chain
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(async () => { | |
const Token = '0x0e09fabb73bd3ade0a17ecc321fd13a19e81ce82'; | |
const abi = [{"inputs":[{"internalType":"uint256","name":"amountIn","type":"uint256"},{"internalType":"address[]","name":"path","type":"address[]"}],"name":"getAmountsOut","outputs":[{"internalType":"uint256[]","name":"amounts","type":"uint256[]"}],"stateMutability":"view","type":"function"},] | |
const web3 = new Web3(Web3.givenProvider); | |
const contract = new web3.eth.Contract(abi, '0x10ed43c718714eb63d5aa57b78b54704e256024e'); | |
const result = await contract.methods.getAmountsOut((10 ** 18) + '', [Token, '0xe9e7cea3dedca5984780bafc599bd69add087d56']).call(); | |
const price = result[1] / (10 ** 18); | |
console.log('$' + price.toFixed(2) ); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment