-
Notifications
You must be signed in to change notification settings - Fork 250
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Andy Haynes
committed
Aug 15, 2024
1 parent
7d62567
commit be989a4
Showing
3 changed files
with
35 additions
and
18 deletions.
There are no files selected for viewing
42 changes: 24 additions & 18 deletions
42
packages/cookbook/accounts/access-keys/create-full-access-key.js
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,25 +1,31 @@ | ||
const { KeyPair, keyStores, connect } = require("near-api-js"); | ||
const path = require("path"); | ||
const homedir = require("os").homedir(); | ||
const { getTestnetRpcProvider, addFullAccessKey, getSignerFromKeystore } = require('@near-js/client'); | ||
const { KeyPair } = require('@near-js/crypto'); | ||
const path = require('path'); | ||
const homedir = require('os').homedir(); | ||
|
||
const CREDENTIALS_DIR = ".near-credentials"; | ||
const ACCOUNT_ID = "example.testnet"; | ||
const CREDENTIALS_DIR = '.near-credentials'; | ||
const ACCOUNT_ID = 'example.testnet'; | ||
const credentialsPath = path.join(homedir, CREDENTIALS_DIR); | ||
const keyStore = new keyStores.UnencryptedFileSystemKeyStore(credentialsPath); | ||
|
||
const config = { | ||
keyStore, | ||
networkId: "testnet", | ||
nodeUrl: "https://rpc.testnet.near.org", | ||
}; | ||
// const config = { | ||
// keyStore, | ||
// networkId: 'testnet', | ||
// nodeUrl: 'https://rpc.testnet.near.org', | ||
// }; | ||
// | ||
// createFullAccessKey(ACCOUNT_ID); | ||
|
||
createFullAccessKey(ACCOUNT_ID); | ||
async function createFullAccessKeyExample(accountId) { | ||
const keyPair = KeyPair.fromRandom('ed25519'); | ||
await addFullAccessKey({ | ||
account: ACCOUNT_ID, | ||
publicKey: keyPair.getPublicKey(), | ||
deps: { | ||
rpcProvider: getTestnetRpcProvider(), | ||
signer: getSignerFromKeystore(keyStore), | ||
}, | ||
}); | ||
|
||
async function createFullAccessKey(accountId) { | ||
const keyPair = KeyPair.fromRandom("ed25519"); | ||
const publicKey = keyPair.publicKey.toString(); | ||
const near = await connect(config); | ||
const account = await near.account(accountId); | ||
await keyStore.setKey(config.networkId, publicKey, keyPair); | ||
await account.addKey(publicKey); | ||
await keyStore.setKey('testnet', accountId, keyPair); | ||
} |
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.