Skip to content

Instantly share code, notes, and snippets.

@mattlockyer
Created June 5, 2021 00:03
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/c0bbcc738bcd5891b0a95bd4b6514d39 to your computer and use it in GitHub Desktop.
Save mattlockyer/c0bbcc738bcd5891b0a95bd4b6514d39 to your computer and use it in GitHub Desktop.
NEAR Basics, Connect, Wallet, Account, Call Methods
// new near instance (for NodeJS use InMemoryKeyStore)
// do this once somewhere when app "mounts" or loads
const near = new Near({
networkId,
nodeUrl,
walletUrl,
deps: {
keyStore: new keyStores.BrowserLocalStorageKeyStore()
},
});
const account = new Account(near.connection, [ACCOUNT_ID]);
// or use walletAccount
const wallet = new WalletAccount(near);
// now with either "wallet" or "account" you can call methods of your contract!
await account.viewFunction(contractId, methodName, { ... args ... });
await account.functionCall({
contractId: ...,
methodName: ...,
args: { ... },
gas: ...,
attachedDeposit: ...
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment