diff --git a/lib/kredits.js b/lib/kredits.js index 33bbe8b..8182137 100644 --- a/lib/kredits.js +++ b/lib/kredits.js @@ -32,14 +32,13 @@ class Kredits { // Initialize our registry contract this.addresses = addresses; this.contracts = {}; + this.ipfs = new IPFS(); } - static setup(provider, signer, ipfsConfig) { - this.ipfsConfig = ipfsConfig; + static setup(provider, signer, ipfsConfig = null) { let ipfsAPI = new IPFS(ipfsConfig); - this.ipfs = ipfsAPI; - return this.ipfs._ipfsAPI.id().catch((error) => { + return ipfsAPI._ipfsAPI.id().catch((error) => { throw new Error(`IPFS node not available; config: ${JSON.stringify(ipfsConfig)} - ${error.message}`); }).then(() => { @@ -83,13 +82,6 @@ class Kredits { return new ethers.Contract(address, abi, provider); } - get ipfs() { - return this._ipfsAPI; - } - set ipfs(ipfs) { - this._ipfsAPI = ipfs; - } - get Contributor() { // TODO: rename to contributor return this.contractFor('contributors'); diff --git a/lib/utils/ipfs.js b/lib/utils/ipfs.js index 6dc1887..e0aecb6 100644 --- a/lib/utils/ipfs.js +++ b/lib/utils/ipfs.js @@ -4,6 +4,9 @@ const multihashes = require('multihashes'); class IPFS { constructor(config) { + if (!config) { + config = {host: 'localhost', port: '5001', protocol: 'http'}; + } this._ipfsAPI = ipfsAPI(config); this._config = config; }