diff --git a/lib/script/script.js b/lib/script/script.js index f7820cb..428a39f 100644 --- a/lib/script/script.js +++ b/lib/script/script.js @@ -702,11 +702,11 @@ Script.fromAddress = function(address) { }; /** + * @param {Network} [network] * @return {Address} the associated address for this script */ Script.prototype.toAddress = function(network) { - network = Networks.get(network); - $.checkArgument(network, 'Must provide a network'); + network = Networks.get(network) || Networks.defaultNetwork; if (this.isPublicKeyHashOut() || this.isScriptHashOut()) { return new Address(this, network); } diff --git a/test/script/script.js b/test/script/script.js index 48dbfb9..29b7208 100644 --- a/test/script/script.js +++ b/test/script/script.js @@ -592,6 +592,12 @@ describe('Script', function() { }); describe('toAddress', function() { + it('uses default network', function() { + var stringAddress = '1NaTVwXDDUJaXDQajoa9MqHhz4uTxtgK14'; + var address = new Address(stringAddress); + var script = new Script(address); + script.toAddress().toString().should.equal(stringAddress); + }); it('for a P2PKH address', function() { var stringAddress = '1NaTVwXDDUJaXDQajoa9MqHhz4uTxtgK14'; var address = new Address(stringAddress);