From 0e9df5cb761a4d16f219e5bc66a460a4b99bd7d3 Mon Sep 17 00:00:00 2001 From: ricmoo Date: Fri, 5 Aug 2016 16:14:09 -0400 Subject: [PATCH] Fixed bug when passing in hex string to formatEther. --- lib/wallet.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/wallet.js b/lib/wallet.js index 580c3173e..131fd80ca 100644 --- a/lib/wallet.js +++ b/lib/wallet.js @@ -236,12 +236,14 @@ var zero = new utils.BN(0); var negative1 = new utils.BN(-1); var tenPower18 = new utils.BN('1000000000000000000'); utils.defineProperty(Wallet, 'formatEther', function(wei, options) { + if (typeof(wei) === 'number') { // @TODO: Warn if truncation will occur? wei = new utils.BN(wei); } else if (utils.isHexString(wei)) { - wei = new utils.BN(wei.substring(2)); + wei = new utils.BN(wei.substring(2), 16); } + if (!options) { options = {}; } if (!(wei instanceof utils.BN)) { throw new Error('invalid wei'); }