Ethereumの手数料を日本円に変換するサイト作りました

リンクはここです。

checkgasprice.netlify.com f:id:hido_dev:20190224112345p:plain

経緯

Ethereumの手数料であるGasをUSドルに変換するサイトは死ぬほどあったのですが、日本円verがなかったので作りました。

技術的なこと

infura.ioよりmainnetの平均GasPriceを取得してます。

const Web3 = require('web3');
const web3 = new Web3(new Web3.providers.HttpProvider('https://mainnet.infura.io'));

// infura.ioより平均のGasPriceを取得
const getGasPrice = () => {
  return web3.eth.getGasPrice();
}

またETH => JPYを取得するAPIに関しては coinmarketcap.com より拝借しております。

const getETHtoJPY = () => {
  const myRequest = new Request('https://api.coinmarketcap.com/v2/ticker/1027/?convert=JPY');
  return fetch(myRequest, {
  mode: 'cors'
  })
  .then(response => {
    if (response.status === 200) {
      return response.json();
    } else {
      throw new Error('Something went wrong on api server!');
    }
  })
  .then(response => {
    return response;
  }).catch(error => {
    return error;
  });
}

コード的にはこんな感じです。