Use kredits-contracts from npm, update provider setup
This commit is contained in:
parent
7056772066
commit
21aaf2f3bf
20
index.js
20
index.js
@ -6,7 +6,7 @@ const Kredits = require('kredits-contracts');
|
|||||||
|
|
||||||
const walletPath = process.env.KREDITS_WALLET_PATH || './wallet.json';
|
const walletPath = process.env.KREDITS_WALLET_PATH || './wallet.json';
|
||||||
const walletJson = fs.readFileSync(walletPath);
|
const walletJson = fs.readFileSync(walletPath);
|
||||||
const providerUrl = process.env.KREDITS_PROVIDER_URL || 'http://localhost:7545';
|
const providerUrl = process.env.KREDITS_PROVIDER_URL;
|
||||||
const networkId = parseInt(process.env.KREDITS_NETWORK_ID || 100);
|
const networkId = parseInt(process.env.KREDITS_NETWORK_ID || 100);
|
||||||
|
|
||||||
const ipfsConfig = {
|
const ipfsConfig = {
|
||||||
@ -37,9 +37,13 @@ module.exports = async function(robot) {
|
|||||||
// Ethereum provider/node setup
|
// Ethereum provider/node setup
|
||||||
//
|
//
|
||||||
|
|
||||||
const ethProvider = new ethers.providers.JsonRpcProvider(providerUrl);
|
let ethProvider;
|
||||||
ethProvider.signer = wallet;
|
if (providerUrl) {
|
||||||
wallet.provider = ethProvider;
|
ethProvider = new ethers.providers.JsonRpcProvider(providerUrl);
|
||||||
|
} else {
|
||||||
|
ethProvider = new ethers.getDefaultProvider('rinkeby');
|
||||||
|
}
|
||||||
|
const signer = wallet.connect(ethProvider);
|
||||||
|
|
||||||
//
|
//
|
||||||
// Kredits contracts setup
|
// Kredits contracts setup
|
||||||
@ -47,7 +51,11 @@ module.exports = async function(robot) {
|
|||||||
|
|
||||||
let kredits;
|
let kredits;
|
||||||
try {
|
try {
|
||||||
kredits = await new Kredits(ethProvider, wallet, ipfsConfig).init();
|
kredits = await new Kredits(signer.provider, signer, {
|
||||||
|
// TODO support local devchain custom address
|
||||||
|
apm: 'open.aragonpm.eth',
|
||||||
|
ipfsConfig
|
||||||
|
}).init();
|
||||||
} catch(error) {
|
} catch(error) {
|
||||||
robot.logger.warning('[hubot-kredits] Could not set up kredits:', error);
|
robot.logger.warning('[hubot-kredits] Could not set up kredits:', error);
|
||||||
process.exit(1);
|
process.exit(1);
|
||||||
@ -75,7 +83,7 @@ module.exports = async function(robot) {
|
|||||||
|
|
||||||
robot.respond(/got ETH\??/i, res => {
|
robot.respond(/got ETH\??/i, res => {
|
||||||
ethProvider.getBalance(wallet.address).then((balance) => {
|
ethProvider.getBalance(wallet.address).then((balance) => {
|
||||||
res.send(`my wallet contains ${ethers.utils.formatEther(balance)} ETH`);
|
res.send(`My wallet contains ${ethers.utils.formatEther(balance)} ETH`);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
1046
package-lock.json
generated
1046
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@ -10,13 +10,14 @@
|
|||||||
"create-wallet": "scripts/create-wallet.js"
|
"create-wallet": "scripts/create-wallet.js"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
|
"eth-provider": "^0.2.2",
|
||||||
"ethers": "^4.0.27",
|
"ethers": "^4.0.27",
|
||||||
"group-array": "^0.3.3",
|
"group-array": "^0.3.3",
|
||||||
"kosmos-schemas": "^1.1.2",
|
"kosmos-schemas": "^1.1.2",
|
||||||
|
"kredits-contracts": "4.x",
|
||||||
"node-cron": "^2.0.3",
|
"node-cron": "^2.0.3",
|
||||||
"node-fetch": "^2.3.0",
|
"node-fetch": "^2.3.0",
|
||||||
"prompt": "^1.0.0",
|
"prompt": "^1.0.0"
|
||||||
"kredits-contracts": "3.x"
|
|
||||||
},
|
},
|
||||||
"repository": {
|
"repository": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
|
Loading…
x
Reference in New Issue
Block a user