Add helper to initialize a new instance with provider #128
@ -66,6 +66,23 @@ class Kredits {
|
||||
return new Kredits(provider, signer, { ipfsConfig: ipfsConfig }).init();
|
||||
}
|
||||
|
||||
static for (connectionOptions, kreditsOptions) {
|
||||
let { network, rpcUrl, wallet } = connectionOptions;
|
||||
if (!rpcUrl && network === 'local') { rpcUrl = 'http://localhost:8545'; }
|
||||
let ethProvider, signer;
|
||||
if (rpcUrl) {
|
||||
ethProvider = new ethers.providers.JsonRpcProvider(rpcUrl);
|
||||
} else {
|
||||
ethProvider = new ethers.getDefaultProvider(network);
|
||||
}
|
||||
if (wallet) {
|
||||
signer = wallet.connect(ethProvider);
|
||||
} else if (ethProvider.getSigner) {
|
||||
signer = ethProvider.getSigner();
|
||||
}
|
||||
return new Kredits(ethProvider, signer, kreditsOptions);
|
||||
}
|
||||
|
||||
get Kernel () {
|
||||
let k = this.contractFor('Kernel');
|
||||
// in case we want to use a special apm (e.g. development vs. production)
|
||||
|
Loading…
x
Reference in New Issue
Block a user