forked from singnet/snet-sdk-js
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request singnet#147 from singnet/master
Update Web-sdk
- Loading branch information
Showing
29 changed files
with
15,462 additions
and
13,481 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
PRIVATE_KEY= | ||
SIGNER_PRIVATE_KEY= | ||
NETWORK_ID=3 | ||
PROVIDER_HOST=https://ropsten.infura.io | ||
PROVIDER_HOST=https://goerli.infura.io/v3/xxxxxx | ||
IPFS_ENDPOINT=http://ipfs.singularitynet.io:80 | ||
DEFAULT_GAS_PRICE=4700000 | ||
DEFAULT_GAS_LIMIT=210000 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
import Web3 from 'web3'; | ||
import { ethereumMethods } from '../utils/ethereumUtils'; | ||
|
||
import logger from '../utils/logger'; | ||
import blockChainEvents from '../utils/blockchainEvents'; | ||
|
||
/** | ||
* @implements Identity | ||
*/ | ||
class WalletRPCIdentity { | ||
/** | ||
* @param {Config} config | ||
* @param {Web3} web3 | ||
*/ | ||
constructor(config, web3) { | ||
this._eth = new Web3(config.web3Provider); | ||
this._web3 = web3; | ||
this.setupAccount(); | ||
} | ||
|
||
async getAddress() { | ||
const accounts = await this._web3.eth.getAccounts(); | ||
return accounts[0]; | ||
} | ||
|
||
async signData(sha3Message) { | ||
const address = await this.getAddress(); | ||
return this._web3.eth.personal.sign(sha3Message, address, ''); | ||
} | ||
|
||
async sendTransaction(transactionObject) { | ||
return new Promise((resolve, reject) => { | ||
this._web3.eth.sendTransaction(transactionObject) | ||
.on('transactionHash', (hash) => { | ||
logger.info(`Transaction hash: ${hash}`); | ||
}) | ||
.on('error', (error) => { | ||
logger.error(`Couldn't send transaction. ${error}`); | ||
reject(error); | ||
}) | ||
.then((receipt) => { | ||
if (receipt.status) { | ||
resolve(receipt); | ||
} else { | ||
reject(receipt); | ||
} | ||
}); | ||
}); | ||
} | ||
|
||
async setupAccount() { | ||
const accounts = await this._web3.eth.getAccounts(); | ||
if (accounts.length > 0) { | ||
this._web3.eth.defaultAccount = accounts[0]; | ||
} else { | ||
logger.error('No accounts found'); | ||
} | ||
} | ||
} | ||
|
||
export default WalletRPCIdentity; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
export { default as PrivateKeyIdentity } from './PrivateKeyIdentity'; | ||
export { default as MetaMaskIdentity } from './MetaMaskIdentity'; | ||
export { default as WalletRPCIdentity } from './WalletRPCIdentity'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,9 @@ | ||
import { format, createLogger, transports } from 'winston'; | ||
import createLogger from 'winston/dist/winston/create-logger'; | ||
import { format } from 'logform'; | ||
|
||
const logger = createLogger({ | ||
format: format.simple(), | ||
level: process.env.DEBUG ? 'silly' : 'info', | ||
transports: [new transports.Console({ level : 'debug'})] | ||
}); | ||
|
||
export default logger; |
Oops, something went wrong.