Skip to content

Instantly share code, notes, and snippets.

@ilyar
Last active June 7, 2021 08:20
Show Gist options
  • Select an option

  • Save ilyar/a2a7b82153c172ddb565ac109ae24e11 to your computer and use it in GitHub Desktop.

Select an option

Save ilyar/a2a7b82153c172ddb565ac109ae24e11 to your computer and use it in GitHub Desktop.
import * as near from '@4ire-labs/near-sdk' // const near = require('@4ire-labs/near-sdk')
process.env.NEAR_ENV = 'testnet'
async function main() {
const account = await near.readUnencryptedFileSystemKeyStore(near.accountIdBySlug('ilyar'))
console.log(account)
console.log('Account:', {
implicitId: account.accountId,
publicKey: account.keyPair.publicKey.toString(),
hasSecretKey: account.keyPair.secretKey.length === 88,
})
const connect = await near.newAccountConnect(account)
const mnemonic = near.generateMnemonic() // near.generateMnemonic(Buffer.from('0123456789ABCDEF'))
const newAccount = near.mnemonicToAccount(mnemonic)
console.log('Implicit Account:', { // https://docs.near.org/docs/roles/integrator/implicit-accounts
mnemonic: mnemonic,
implicitId: newAccount.accountId,
publicKey: newAccount.keyPair.publicKey.toString(),
})
const outcomeRaw = await connect.addKey(newAccount.keyPair.publicKey)
const outcome = near.transactionOutcome(outcomeRaw)
console.log('Sender Account:', {
transactionId: outcome.transactionId,
})
}
main().catch(console.error)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment