//必要なFee = 必要Gas × Gasプライス
var estimatedFeeInWei = function(){
var gas = Session.get('sendEther.estimatedGas');
var gasPrice = new BigNumber(Session.get('sendEther.currentGasPrice'));
return gasPrice.mul(gas);
var estimationCallback = function(e, res){
console.log('Estimated gas: ', res, e);
Session.set('sendEther.estimatedGas', res);
var getGasPriceCallback = function(e, res){
console.log('Current Gas Price in Wei: ', res.toString(10), e);
Session.set('sendEther.currentGasPrice', res.toString(10));
Template.sendEtherComponent.events({
//「Send Ether」コンポーネントのSubmitボタン押下時のイベント制御
'submit form': function(e) {
e.preventDefault(); //ボタン押下時のブラウザでのデフォルト動作の禁止
//画面で入力された送金情報を「fundInfo」オブジェクトに格納
fAddr: $(e.target).find('[name=f-addr]').val(),
tAddr: $(e.target).find('[name=t-addr]').val(),
amount: web3.toWei($(e.target).find('[name=amount]').val(),'ether')
if(EthAccounts.findOne({address: fundInfo.fAddr}, {reactive: false})) {
Session.set('sendEther.fundInfo', fundInfo);
//必要Gas量の見積もりをEthereumノードに問い合わせ→ Session変数に格納
web3.eth.estimateGas({from: fundInfo.fAddr, to: fundInfo.tAddr, value: fundInfo.amount}, estimationCallback.bind(template));
//現在のGas priceをEthereumノードに問い合わせ問い合わせ→ Session変数に格納
web3.eth.getGasPrice(getGasPriceCallback.bind(template));
$('#sendConfirmModal').modal('show');
Template.sendConfirmModalTemplate.helpers({
sendAmountInEther: function(){
var amountEth = web3.fromWei(Session.get("sendEther.fundInfo").amount,'ether');
return parseFloat(amountEth).toFixed(3);
return Session.get("sendEther.fundInfo").fAddr;
return Session.get("sendEther.fundInfo").tAddr;
return web3.fromWei(estimatedFeeInWei(),'ether').toString(10);