Skip to content

Instantly share code, notes, and snippets.

@andreespirela
Created October 28, 2022 20:08
Show Gist options
  • Save andreespirela/90411be052e1ebad2dcd17517295c1a5 to your computer and use it in GitHub Desktop.
Save andreespirela/90411be052e1ebad2dcd17517295c1a5 to your computer and use it in GitHub Desktop.
import * as nearAPI from "near-api-js";
const { keyStores, KeyPair } = nearAPI;
const myKeyStore = new keyStores.InMemoryKeyStore();
const PRIVATE_KEY = "YOUR_PRIVATE_KEY";
// creates a public / private key pair using the provided private key
const keyPair = KeyPair.fromString(PRIVATE_KEY);
// adds the keyPair you created to keyStore
await myKeyStore.setKey("testnet", "YOUR_ACCOUNT.testnet", keyPair);
const account = await nearConnection.account("YOUR_ACCOUNT.testnet");
const contract = new Contract(
account, // the account object that is connecting
"YOUR_ACCOUNT.testnet",
{
// name of contract you're connecting to
viewMethods: [""], // view methods do not change state but usually return a value
changeMethods: ["nft_approve"], // change methods modify state (Change methods for NEP-0178)
}
);
await contract. nft_approve(
{
token_id: "TOKEN_ID",
account_id: "NORAMP_WALLET"
},
"300000000000000", // attached GAS (optional)
"1000000000000000000000000" // attached deposit in yoctoNEAR (optional)
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment