-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a method to check peer dialablility (#79)
* Add an option for intermediaries to the server script * Add an option to specify additional peers in the server script * Add a method to check peer dialablility * Add script to fetch account balance on chain * Fix balance script log --------- Co-authored-by: Nabarun <nabarun@deepstacksoft.com>
- Loading branch information
1 parent
829b901
commit 564db65
Showing
6 changed files
with
136 additions
and
11 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
import yargs from 'yargs'; | ||
import debug from 'debug'; | ||
import { Wallet, providers } from 'ethers'; | ||
|
||
import { DEFAULT_CHAIN_URL } from '../src/constants'; | ||
|
||
const log = debug('ts-nitro:util'); | ||
|
||
const getArgv = () => yargs.parserConfiguration({ | ||
'parse-numbers': false, | ||
}).options({ | ||
chainurl: { | ||
alias: 'c', | ||
type: 'string', | ||
describe: 'RPC endpoint for the chain', | ||
default: DEFAULT_CHAIN_URL, | ||
}, | ||
address: { | ||
alias: 'a', | ||
type: 'string', | ||
describe: 'Address of account to check balance for', | ||
}, | ||
key: { | ||
alias: 'k', | ||
type: 'string', | ||
describe: 'Private key of account to check', | ||
}, | ||
}).argv; | ||
|
||
async function main() { | ||
const argv = getArgv(); | ||
|
||
const provider = new providers.JsonRpcProvider(argv.chainurl); | ||
let address: string; | ||
|
||
if (argv.address) { | ||
address = argv.address; | ||
} else if (argv.key) { | ||
const signer = new Wallet(argv.key, provider); | ||
address = await signer.getAddress(); | ||
} else { | ||
throw new Error('Provide either address or private key of an account'); | ||
} | ||
|
||
const balance = await provider.getBalance(address); | ||
log(`Balance of account ${address} is ${balance.toString()}`); | ||
} | ||
|
||
main() | ||
.then(() => {}) | ||
.catch((err) => { | ||
log(err); | ||
}); | ||
|
||
process.on('uncaughtException', (err) => { | ||
log('uncaughtException', err); | ||
}); |
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