This repository has been archived by the owner on Oct 4, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 94
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add interactive
near repl
with auto-injected nearlib
, near
and …
…`account`
- Loading branch information
Showing
4 changed files
with
37 additions
and
17 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
module.exports = { | ||
command: 'repl', | ||
desc: 'launch interactive Node.js shell with NEAR connection available to use', | ||
builder: (yargs) => yargs, | ||
handler: async (argv) => { | ||
const repl = require('repl'); | ||
const context = repl.start('> ').context; | ||
context.nearlib = require('nearlib'); | ||
context.near = await require('../utils/connect')(argv); | ||
if (argv.accountId) { | ||
context.account = await context.near.account(argv.accountId); | ||
} | ||
} | ||
}; |
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,15 @@ | ||
const nearlib = require('nearlib'); | ||
const UnencryptedFileSystemKeyStore = nearlib.keyStores.UnencryptedFileSystemKeyStore; | ||
|
||
module.exports = async function connect(options) { | ||
if (options.keyPath === undefined && options.helperUrl === undefined) { | ||
const homeDir = options.homeDir || `${process.env.HOME}/.near`; | ||
options.keyPath = `${homeDir}/validator_key.json`; | ||
} | ||
// TODO: search for key store. | ||
const keyStore = new UnencryptedFileSystemKeyStore('./neardev'); | ||
options.deps = { | ||
keyStore, | ||
}; | ||
return await nearlib.connect(options); | ||
} |