Skip to content

Instantly share code, notes, and snippets.

@mattlockyer
Created June 5, 2021 00:03
Show Gist options
  • Select an option

  • Save mattlockyer/c0bbcc738bcd5891b0a95bd4b6514d39 to your computer and use it in GitHub Desktop.

Select an option

Save mattlockyer/c0bbcc738bcd5891b0a95bd4b6514d39 to your computer and use it in GitHub Desktop.

Revisions

  1. mattlockyer created this gist Jun 5, 2021.
    28 changes: 28 additions & 0 deletions basics.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,28 @@
    // 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: ...
    });