Skip to content

Instantly share code, notes, and snippets.

@xpdlf1004
Last active May 17, 2018 01:12
Show Gist options
  • Save xpdlf1004/762b31632f06cca592932b1af1ef5fdd to your computer and use it in GitHub Desktop.
Save xpdlf1004/762b31632f06cca592932b1af1ef5fdd to your computer and use it in GitHub Desktop.
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