Last active
May 17, 2018 01:12
-
-
Save xpdlf1004/762b31632f06cca592932b1af1ef5fdd to your computer and use it in GitHub Desktop.
This file contains 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
export class GasPriceAPIClient { | |
public async requestGasPrice(): Promise<string> { | |
// https://ethgasstation.info/json/ethgasAPI.json | |
try { | |
const response = await rp("https://ethgasstation.info/json/ethgasAPI.json"); | |
const { fastest } = JSON.parse(response); | |
let fastestInMwei = fastest * 100; | |
// 10Gwei ~ 30Gwei 사이의 값으로 설정 | |
fastestInMwei = _.clamp(fastestInMwei, 10 * 1000, 30 * 1000); | |
return toWei(String(_.floor(fastestInMwei)), "Mwei"); | |
} catch (err) { | |
return toWei("20", "Gwei"); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment