Skip to content

Instantly share code, notes, and snippets.

@mattlockyer
Created April 17, 2021 21:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mattlockyer/39e70070fa1b51d4a9b31fadae99052f to your computer and use it in GitHub Desktop.
Save mattlockyer/39e70070fa1b51d4a9b31fadae99052f to your computer and use it in GitHub Desktop.
NEAR Protocol - Sign TX as another account using an access key added to that account
import * as nearAPI from 'near-api-js';
const {
Account,
KeyPair,
} = nearAPI;
// near is your current near connection instance (somewhere in your app init)
export const getAccessKeyAccount = (near, accountId, secretKey) => {
const keyPair = KeyPair.fromString(secretKey);
near.connection.signer.keyStore.setKey(near.config.networkId, accountId, keyPair);
const account = new Account(near.connection, accountId);
return account;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment