diff --git a/javascript/examples/account-details.js b/javascript/examples/account-details.js index 1448d94..81af1a7 100644 --- a/javascript/examples/account-details.js +++ b/javascript/examples/account-details.js @@ -1,21 +1,17 @@ -import { connect } from "near-api-js"; +import { Account } from "@near-js/accounts"; +import { JsonRpcProvider } from "@near-js/providers"; -const connection = await connect({ - networkId: "testnet", - nodeUrl: "https://test.rpc.fastnear.com", +// Gather details through the RPC Provider +const provider = new JsonRpcProvider({ + url: "https://test.rpc.fastnear.com", }); -// Create an account object -const account = await connection.account("example-account.testnet"); +const rpcState = await provider.viewAccount("example-account.testnet"); +console.log({ rpcState }); -// Gets the total, staked and available balance in yoctoNEAR -const accountBalance = await account.getAccountBalance(); -console.log(accountBalance); +// Option 2: Use an Account object +const account = new Account("example-account.testnet", provider); +const accountBalance = await account.getBalance(); +const accountState = await account.getState(); -// Account's state, including its code hash and storage usage -const accountState = await account.state(); -console.log(accountState); - -// Gets a list of authorized apps for an account -const accountDetails = await account.getAccountDetails(); -console.log(accountDetails); +console.log({ accountState, accountBalance }); \ No newline at end of file diff --git a/javascript/examples/batch-actions.js b/javascript/examples/batch-actions.js index e4e735d..5d28809 100644 --- a/javascript/examples/batch-actions.js +++ b/javascript/examples/batch-actions.js @@ -1,36 +1,32 @@ -import { connect, keyStores, KeyPair, transactions, utils } from "near-api-js"; +import { Account } from "@near-js/accounts"; +import { JsonRpcProvider } from "@near-js/providers"; +import { KeyPairSigner } from "@near-js/signers"; +import { actionCreators } from "@near-js/transactions"; +import { NEAR } from "@near-js/tokens"; import dotenv from "dotenv"; dotenv.config({ path: "../.env" }); -const privateKey = process.env.PRIVATE_KEY; -const accountId = process.env.ACCOUNT_ID; -const myKeyStore = new keyStores.InMemoryKeyStore(); -const keyPair = KeyPair.fromString(privateKey); -await myKeyStore.setKey("testnet", accountId, keyPair); - -const connectionConfig = { - networkId: "testnet", - keyStore: myKeyStore, - nodeUrl: "https://test.rpc.fastnear.com", -}; -const nearConnection = await connect(connectionConfig); +// Create a signer from a private key string +const privateKey = process.env.PRIVATE_KEY; +const signer = KeyPairSigner.fromSecretKey(privateKey); // ed25519:5Fg2... -const account = await nearConnection.account(accountId); +// Create a connection to testnet RPC +const provider = new JsonRpcProvider({ + url: "https://test.rpc.fastnear.com", +}); -// Send a batch of actions to a single receiver -// Prepare the actions -const callAction = transactions.functionCall( - "increment", // Method name - [], // Arguments - "30000000000000", // Gas - 0, // Deposit -); -const transferAction = transactions.transfer(utils.format.parseNearAmount("1")); +// Create an account object +const accountId = process.env.ACCOUNT_ID; +const account = new Account(accountId, provider, signer); // example-account.testnet // Send the batch of actions const batchActionsResult = await account.signAndSendTransaction({ receiverId: "counter.near-examples.testnet", - actions: [callAction, transferAction], + actions: [ + actionCreators.functionCall("increment", {}, "30000000000000", 0), + actionCreators.transfer(NEAR.toUnits("0.1")) + ], }); + console.log(batchActionsResult); diff --git a/javascript/examples/contract-interaction.js b/javascript/examples/contract-interaction.js index e3db355..dc52284 100644 --- a/javascript/examples/contract-interaction.js +++ b/javascript/examples/contract-interaction.js @@ -1,80 +1,40 @@ -import { connect, keyStores, KeyPair, providers } from "near-api-js"; +import { Account } from "@near-js/accounts"; +import { JsonRpcProvider } from "@near-js/providers"; +import { KeyPairSigner } from "@near-js/signers"; + import dotenv from "dotenv"; -import fs from "fs"; dotenv.config({ path: "../.env" }); -const privateKey = process.env.PRIVATE_KEY; -const accountId = process.env.ACCOUNT_ID; -const myKeyStore = new keyStores.InMemoryKeyStore(); -const keyPair = KeyPair.fromString(privateKey); -await myKeyStore.setKey("testnet", accountId, keyPair); - -const connectionConfig = { - networkId: "testnet", - keyStore: myKeyStore, - nodeUrl: "https://test.rpc.fastnear.com", -}; -const nearConnection = await connect(connectionConfig); +// Create a connection to testnet RPC +const provider = new JsonRpcProvider({ + url: "https://test.rpc.fastnear.com", +}); -const account = await nearConnection.account(accountId); +const contractId = "guestbook.near-examples.testnet"; -// Make a view call to a contract -async function viewContract({ +// Make a read-only function call +const totalMessages = await provider.callFunction( contractId, - methodName, - args = {}, - finality = "optimistic", -}) { - // Set up a new provider - const url = `https://test.rpc.fastnear.com`; - const provider = new providers.JsonRpcProvider({ url }); - - // Convert the arguments to base64 - const argsBase64 = args - ? Buffer.from(JSON.stringify(args)).toString("base64") - : ""; - - // Make the view call - const viewCallResult = await provider.query({ - request_type: "call_function", - account_id: contractId, - method_name: methodName, - args_base64: argsBase64, - finality: finality, - }); + "total_messages", + {} +); - // Parse the result - return JSON.parse(Buffer.from(viewCallResult.result).toString()); -} +console.log({ totalMessages }); -// Use the view call function -const viewCallData = await viewContract({ - contractId: "guestbook.near-examples.testnet", - methodName: "total_messages", -}); -console.log(viewCallData); +// Create a signer from a private key string +const privateKey = process.env.PRIVATE_KEY; +const signer = KeyPairSigner.fromSecretKey(privateKey); // ed25519:5Fg2... -// If args are required, they can be passed in like this: -// args: { -// from_index: "0", -// limit: "10" -// } +// Create an account object +const accountId = process.env.ACCOUNT_ID; +const account = new Account(accountId, provider, signer); // example-account.testnet -// Make a function call to a contract -const contractCallResult = await account.functionCall({ - contractId: "guestbook.near-examples.testnet", // Contract account ID - methodName: "add_message", // Method to call - args: { - text: "Hello, world!", - }, // Arguments for the method - gas: 100000000000000, // Optional: gas limit - attachedDeposit: 0, // Optional: deposit in yoctoNEAR +// Make a function call that modifies state +const result = await account.callFunction({ + contractId: contractId, + methodName: "add_message", + args: { text: "Hello, world!" }, }); -console.log(contractCallResult); -// Deploy a contract to the account -const deployResult = await account.deployContract( - fs.readFileSync("../contracts/contract.wasm"), // Path of contract WASM relative to the working directory -); -console.log(deployResult); +console.log({ result }); \ No newline at end of file diff --git a/javascript/examples/create-account-from-seed.js b/javascript/examples/create-account-from-seed.js index a2d2f0d..2ed1215 100644 --- a/javascript/examples/create-account-from-seed.js +++ b/javascript/examples/create-account-from-seed.js @@ -1,40 +1,27 @@ -import { connect, keyStores, KeyPair, utils } from "near-api-js"; +import { Account } from "@near-js/accounts"; +import { JsonRpcProvider } from "@near-js/providers"; +import { KeyPairSigner } from "@near-js/signers"; +import { NEAR } from "@near-js/tokens"; import { generateSeedPhrase } from "near-seed-phrase"; import dotenv from "dotenv"; dotenv.config({ path: "../.env" }); -const privateKey = process.env.PRIVATE_KEY; -const accountId = process.env.ACCOUNT_ID; -const myKeyStore = new keyStores.InMemoryKeyStore(); -const keyPair = KeyPair.fromString(privateKey); -await myKeyStore.setKey("testnet", accountId, keyPair); - -const connectionConfig = { - networkId: "testnet", - keyStore: myKeyStore, - nodeUrl: "https://test.rpc.fastnear.com", -}; -const nearConnection = await connect(connectionConfig); +// Create a connection to testnet RPC +const provider = new JsonRpcProvider({ + url: "https://test.rpc.fastnear.com", +}); -const account = await nearConnection.account(accountId); +// Instantiate the account that will create the new account +const signer = KeyPairSigner.fromSecretKey(process.env.PRIVATE_KEY); +const account = new Account(process.env.ACCOUNT_ID, provider, signer); -// Create a .testnet account -// Generate a new account ID based on the current timestamp -const newAccountId = Date.now() + ".testnet"; -// Generate a new seed phrase +// Generate a new key const { seedPhrase, publicKey, secretKey } = generateSeedPhrase(); -console.log("Seed phrase", seedPhrase); -console.log("Private key", secretKey); -console.log("Public key", publicKey); +console.log(`Created key ${secretKey} with seed phrase ${seedPhrase}`); -const createAccountResult = await account.functionCall({ - contractId: "testnet", - methodName: "create_account", - args: { - new_account_id: newAccountId, // example-account.testnet - new_public_key: publicKey, // ed25519:2ASWc... - }, - attachedDeposit: utils.format.parseNearAmount("0.1"), // Initial balance for new account in yoctoNEAR -}); -console.log(createAccountResult); +await account.createTopLevelAccount( + `acc-${Date.now()}.testnet`, + publicKey, + NEAR.toUnits("0.1") +); diff --git a/javascript/examples/create-account.js b/javascript/examples/create-account.js deleted file mode 100644 index c24b4fb..0000000 --- a/javascript/examples/create-account.js +++ /dev/null @@ -1,57 +0,0 @@ -import { connect, keyStores, KeyPair, utils } from "near-api-js"; -import dotenv from "dotenv"; - -dotenv.config({ path: "../.env" }); -const privateKey = process.env.PRIVATE_KEY; -const accountId = process.env.ACCOUNT_ID; - -const myKeyStore = new keyStores.InMemoryKeyStore(); -const keyPair = KeyPair.fromString(privateKey); -await myKeyStore.setKey("testnet", accountId, keyPair); - -const connectionConfig = { - networkId: "testnet", - keyStore: myKeyStore, - nodeUrl: "https://test.rpc.fastnear.com", -}; -const nearConnection = await connect(connectionConfig); - -const account = await nearConnection.account(accountId); - -// Create a .testnet account -// Generate a new account ID based on the current timestamp -const newAccountId = Date.now() + ".testnet"; -// Generate a new key pair -const newKeyPair = KeyPair.fromRandom("ed25519"); -const newPublicKey = newKeyPair.getPublicKey().toString(); -const newPrivateKey = newKeyPair.toString(); -console.log("Private key", newPrivateKey); -console.log("Public key", newPublicKey); - -const createAccountResult = await account.functionCall({ - contractId: "testnet", - methodName: "create_account", - args: { - new_account_id: newAccountId, // example-account.testnet - new_public_key: newPublicKey, // ed25519:2ASWc... - }, - attachedDeposit: utils.format.parseNearAmount("0.1"), // Initial balance for new account in yoctoNEAR -}); -console.log(createAccountResult); - -// Create a sub account -// Generate a new sub account ID based on the current timestamp -const newSubAccountId = Date.now() + "." + accountId; -// Generate a new key pair -const newSubKeyPair = KeyPair.fromRandom("ed25519"); -const newSubPublicKey = newSubKeyPair.getPublicKey().toString(); -const newSubPrivateKey = newSubKeyPair.toString(); -console.log("Private key", newSubPrivateKey); -console.log("Public key", newSubPublicKey); - -const createSubAccountResult = await account.createAccount( - newSubAccountId, // sub.example-account.testnet - newSubPublicKey, // ed25519:2ASWc... - utils.format.parseNearAmount("0.1"), // Initial balance for new account in yoctoNEAR -); -console.log(createSubAccountResult); diff --git a/javascript/examples/create-subaccount.js b/javascript/examples/create-subaccount.js new file mode 100644 index 0000000..b123234 --- /dev/null +++ b/javascript/examples/create-subaccount.js @@ -0,0 +1,36 @@ +import { Account } from "@near-js/accounts"; +import { JsonRpcProvider } from "@near-js/providers"; +import { KeyPairSigner } from "@near-js/signers"; +import { KeyPair } from "@near-js/crypto"; +import { NEAR } from "@near-js/tokens"; + +import dotenv from "dotenv"; + +dotenv.config({ path: "../.env" }); + +// Create a connection to testnet RPC +const provider = new JsonRpcProvider({ + url: "https://test.rpc.fastnear.com", +}); + +// Create a signer from a private key string +const privateKey = process.env.PRIVATE_KEY; +const signer = KeyPairSigner.fromSecretKey(privateKey); // ed25519:5Fg2... + +// Create an account object +const accountId = process.env.ACCOUNT_ID; +const account = new Account(accountId, provider, signer); // example-account.testnet + +// Generate a new key pair +const keyPair = KeyPair.fromRandom("ed25519"); +const publicKey = keyPair.getPublicKey().toString(); + +const prefix = Date.now().toString(); + +await account.createSubAccount( + prefix, // prefix for the sub account (e.g. sub.near.testnet) + publicKey, // ed25519:2ASWc... + NEAR.toUnits("0") // Initial balance for new account in yoctoNEAR +); + +console.log(`Created ${prefix}.${accountId} with private key ${keyPair.toString()}`) diff --git a/javascript/examples/create-tla.js b/javascript/examples/create-tla.js new file mode 100644 index 0000000..9cdae98 --- /dev/null +++ b/javascript/examples/create-tla.js @@ -0,0 +1,51 @@ +import { Account } from "@near-js/accounts"; +import { JsonRpcProvider } from "@near-js/providers"; +import { KeyPair } from "@near-js/crypto"; +import { KeyPairSigner } from "@near-js/signers"; +import { NEAR } from "@near-js/tokens"; + +import dotenv from "dotenv"; + +dotenv.config({ path: "../.env" }); + +// Create a signer from a private key string +const privateKey = process.env.PRIVATE_KEY; +const signer = KeyPairSigner.fromSecretKey(privateKey); // ed25519:5Fg2... + +// Create a connection to testnet RPC +const provider = new JsonRpcProvider({ + url: "https://test.rpc.fastnear.com", +}); + +// Create an account object +const accountId = process.env.ACCOUNT_ID; +const account = new Account(accountId, provider, signer); // example-account.testnet + +// New .testnet account +const newAccountId = Date.now() + ".testnet"; + +// Generate a new key +const keyPair = KeyPair.fromRandom("ed25519"); +const publicKey = keyPair.getPublicKey().toString(); + +await account.createTopLevelAccount( + newAccountId, + publicKey, + NEAR.toUnits("0") +); + +console.log(`Created ${newAccountId} with private key ${keyPair.toString()}`) + +// Option 2: Call `testnet` directly +const newAccountId2 = Date.now() + ".testnet"; + +await account.callFunction({ + contractId: "testnet", + methodName: "create_account", + args: { + "new_account_id": newAccountId2, + "new_public_key": publicKey + } +}) + +console.log(`Created account ${newAccountId2} with privateKey: ${keyPair.toString()}`) diff --git a/javascript/examples/delete-account.js b/javascript/examples/delete-account.js index 6d35437..88dbca8 100644 --- a/javascript/examples/delete-account.js +++ b/javascript/examples/delete-account.js @@ -1,47 +1,38 @@ -import { connect, keyStores, KeyPair, utils } from "near-api-js"; +import { Account } from "@near-js/accounts"; +import { JsonRpcProvider } from "@near-js/providers"; +import { KeyPairSigner } from "@near-js/signers"; +import { KeyPair } from "@near-js/crypto"; +import { NEAR } from "@near-js/tokens"; + import dotenv from "dotenv"; dotenv.config({ path: "../.env" }); -const privateKey = process.env.PRIVATE_KEY; -const beneficiaryAccountId = process.env.ACCOUNT_ID; -const myKeyStore = new keyStores.InMemoryKeyStore(); +// Create a signer from a private key string +const privateKey = process.env.PRIVATE_KEY; const keyPair = KeyPair.fromString(privateKey); -await myKeyStore.setKey("testnet", beneficiaryAccountId, keyPair); - -const connectionConfig = { - networkId: "testnet", - keyStore: myKeyStore, - nodeUrl: "https://test.rpc.fastnear.com", -}; -const nearConnection = await connect(connectionConfig); - -const accountCreator = await nearConnection.account(beneficiaryAccountId); - -// First create a new account to be deleted -// Generate a new account ID based on the current timestamp -const accountToDeleteId = Date.now() + ".testnet"; -const newKeyPair = KeyPair.fromRandom("ed25519"); -const newPublicKey = newKeyPair.getPublicKey().toString(); - -await accountCreator.functionCall({ - contractId: "testnet", - methodName: "create_account", - args: { - new_account_id: accountToDeleteId, - new_public_key: newPublicKey, - }, - gas: "300000000000000", - attachedDeposit: utils.format.parseNearAmount("0.1"), +const signer = KeyPairSigner.fromSecretKey(privateKey); // ed25519:5Fg2... + +// Create a connection to testnet RPC +const provider = new JsonRpcProvider({ + url: "https://test.rpc.fastnear.com", }); -// Create an account object for the new account -// and add the new key pair to the keystore -const accountToDelete = await nearConnection.account(accountToDeleteId); -await myKeyStore.setKey("testnet", accountToDeleteId, newKeyPair); +// Create a new account to be deleted +const accountId = process.env.ACCOUNT_ID; +const master = new Account(accountId, provider, signer) + +const deleteMe = `${Date.now()}.testnet`; + +await master.createTopLevelAccount( + deleteMe, + keyPair.getPublicKey().toString(), + NEAR.toUnits("0.1") +); + +// Create an account object for the new account with corresponding signer +const accountToDelete = new Account(deleteMe, provider, signer); -// Delete the account with account ID of the account object -// specifying the beneficiary account ID -const deleteAccountResult = - await accountToDelete.deleteAccount(beneficiaryAccountId); // example-beneficiary.testnet -console.log(deleteAccountResult); +// Delete the account +await accountToDelete.deleteAccount(accountId); // example-beneficiary.testnet +console.log(`Account ${deleteMe} was deleted`); diff --git a/javascript/examples/deploy-contract.js b/javascript/examples/deploy-contract.js new file mode 100644 index 0000000..543db1d --- /dev/null +++ b/javascript/examples/deploy-contract.js @@ -0,0 +1,28 @@ +import { Account } from "@near-js/accounts"; +import { JsonRpcProvider } from "@near-js/providers"; +import { KeyPairSigner } from "@near-js/signers"; + +import dotenv from "dotenv"; +import fs from "fs"; + +dotenv.config({ path: "../.env" }); + +// Create a connection to testnet RPC +const provider = new JsonRpcProvider({ + url: "https://test.rpc.fastnear.com", +}); + +// Create a signer from a private key string +const privateKey = process.env.PRIVATE_KEY; +const signer = KeyPairSigner.fromSecretKey(privateKey); // ed25519:5Fg2... + +// Create an account object +const accountId = process.env.ACCOUNT_ID; +const account = new Account(accountId, provider, signer); // example-account.testnet + +// Deploy a contract to the account +const result = await account.deployContract( + fs.readFileSync("../contracts/contract.wasm") // Path of contract WASM relative to the working directory +); + +console.log(result); diff --git a/javascript/examples/keys.js b/javascript/examples/keys.js index e727e01..3156fdd 100644 --- a/javascript/examples/keys.js +++ b/javascript/examples/keys.js @@ -1,53 +1,64 @@ -import { connect, keyStores, KeyPair, utils } from "near-api-js"; +import { Account } from "@near-js/accounts"; +import { JsonRpcProvider } from "@near-js/providers"; +import { KeyPairSigner } from "@near-js/signers"; +import { KeyPair } from "@near-js/crypto"; +import { NEAR } from "@near-js/tokens"; + import dotenv from "dotenv"; dotenv.config({ path: "../.env" }); -const privateKey = process.env.PRIVATE_KEY; + const accountId = process.env.ACCOUNT_ID; -const myKeyStore = new keyStores.InMemoryKeyStore(); -const keyPair = KeyPair.fromString(privateKey); -await myKeyStore.setKey("testnet", accountId, keyPair); +// Create a connection to testnet RPC +const provider = new JsonRpcProvider({ + url: "https://test.rpc.fastnear.com", +}); -const connectionConfig = { - networkId: "testnet", - keyStore: myKeyStore, - nodeUrl: "https://test.rpc.fastnear.com", -}; -const nearConnection = await connect(connectionConfig); +// Query keys with the provider +const keysProvider = await provider.viewAccessKeyList(accountId); +console.log(keysProvider); -const account = await nearConnection.account(accountId); +// Create an Account object without a signer +const account = new Account(accountId, provider); -// Get all access keys for the account -const accessKeys = await account.getAccessKeys(); +// Query keys +const accessKeys = await account.getAccessKeyList(); console.log(accessKeys); -// Add full access key -// Generate a new key pair -const newFullKeyPair = KeyPair.fromRandom("ed25519"); -const newFullPublicKey = newFullKeyPair.getPublicKey().toString(); -console.log(newFullPublicKey); -const addFullKeyResult = await account.addKey( - newFullPublicKey, // The new public key ed25519:2ASWc... +// Create a signer and add it to the Account +const privateKey = process.env.PRIVATE_KEY; +const signer = KeyPairSigner.fromSecretKey(privateKey); // ed25519:5Fg2... + +account.setSigner(signer); + +// New keys +const fullKeyPair = KeyPair.fromRandom("ed25519"); +const fnKeyPair = KeyPair.fromRandom("ed25519"); + +// Add a Full Access Key +await account.addFullAccessKey( + fullKeyPair.getPublicKey().toString() // ed25519:2ASWc... ); -console.log(addFullKeyResult); - -// Add function call access key -// Generate a new key pair -const newFunctionKeyPair = KeyPair.fromRandom("ed25519"); -const newFunctionPublicKey = newFunctionKeyPair.getPublicKey().toString(); -console.log(newFunctionPublicKey); - -const addFunctionKeyResult = await account.addKey( - newFunctionPublicKey, // The new public key ed25519:2ASWc... - "example-contract.testnet", // Contract this key is allowed to call (optional) - ["example_method"], // Methods this key is allowed to call (optional) - utils.format.parseNearAmount("0.25"), // Gas allowance key can use to call methods (optional) + +// Add Function Call Access Key +await account.addFunctionCallAccessKey({ + publicKey: fnKeyPair.getPublicKey(), // The new public key ed25519:2ASWc... + contractId: "example-contract.testnet", // Contract this key is allowed to call (optional) + methodNames: ["example_method"], // Methods this key is allowed to call (optional) + allowance: NEAR.toUnits("0.25") // Gas allowance key can use to call methods (optional) + } ); -console.log(addFunctionKeyResult); -// Delete full access key -const publicKeyToDelete = newFullPublicKey; -const deleteFullKeyResult = await account.deleteKey(publicKeyToDelete); // The public key being deleted ed25519:2ASWc... -console.log(deleteFullKeyResult); +console.log(`Added FAK ${fullKeyPair.toString()}`); +console.log(`Added FCK ${fnKeyPair.toString()}`); + +const accessKeysNew = await account.getAccessKeyList(); +console.log(accessKeysNew); + +// Use the new FullAccess Key to delete the Function Call Key +const newSigner = KeyPairSigner.fromSecretKey(fullKeyPair.toString()); +account.setSigner(newSigner) +await account.deleteKey(fnKeyPair.getPublicKey().toString()); +await account.deleteKey(fullKeyPair.getPublicKey().toString()); diff --git a/javascript/examples/keystore-options/credentials-directory.js b/javascript/examples/keystore-options/credentials-directory.js index 029864f..dd48e5e 100644 --- a/javascript/examples/keystore-options/credentials-directory.js +++ b/javascript/examples/keystore-options/credentials-directory.js @@ -1,31 +1,42 @@ -import { connect, keyStores, utils } from "near-api-js"; +import { Account } from "@near-js/accounts"; +import { JsonRpcProvider } from "@near-js/providers"; +import { KeyPairSigner } from "@near-js/signers"; +import { UnencryptedFileSystemKeyStore } from "@near-js/keystores-node"; +import { NearToken } from "@near-js/tokens"; + +const NEAR = new NearToken(); + import dotenv from "dotenv"; import { homedir } from "os"; import path from "path"; // Load environment variables dotenv.config({ path: "../.env" }); -const accountId = process.env.ACCOUNT_ID; -// Create a keystore and add the key pair via credentials directory +// Create a keystore that stores keys in the `~/.near-credentials` const credentialsDirectory = ".near-credentials"; const credentialsPath = path.join(homedir(), credentialsDirectory); -const myKeyStore = new keyStores.UnencryptedFileSystemKeyStore(credentialsPath); +const myKeyStore = new UnencryptedFileSystemKeyStore(credentialsPath); -// Create a connection to the NEAR testnet -const connectionConfig = { - networkId: "testnet", - keyStore: myKeyStore, - nodeUrl: "https://test.rpc.fastnear.com", -}; -const nearConnection = await connect(connectionConfig); +const accountId = process.env.ACCOUNT_ID; -// Create an account object -const account = await nearConnection.account(accountId); // example-account.testnet +// Create a connection to testnet RPC +const provider = new JsonRpcProvider({ + url: "https://test.rpc.fastnear.com", +}); + +// Get the key from the keystore +const keyPair = await myKeyStore.getKey("testnet", accountId); +const signer = new KeyPairSigner(keyPair); + +// Instantiate the account +const account = new Account(accountId, provider, signer); // Test the signer by transferring NEAR -const sendTokensResult = await account.sendMoney( - "receiver-account.testnet", - utils.format.parseNearAmount("1"), +const sendTokensResult = await account.transferToken( + NEAR, + NEAR.toUnits("0.1"), + "receiver-account.testnet" ); + console.log(sendTokensResult); diff --git a/javascript/examples/keystore-options/credentials-file.js b/javascript/examples/keystore-options/credentials-file.js index 42f965c..2ac9abf 100644 --- a/javascript/examples/keystore-options/credentials-file.js +++ b/javascript/examples/keystore-options/credentials-file.js @@ -1,34 +1,37 @@ -import { connect, keyStores, KeyPair, utils } from "near-api-js"; +import { Account } from "@near-js/accounts"; +import { JsonRpcProvider } from "@near-js/providers"; +import { KeyPairSigner } from "@near-js/signers"; +import { NearToken } from "@near-js/tokens"; + +const NEAR = new NearToken(); + import dotenv from "dotenv"; import fs from "fs"; // Load environment variables dotenv.config({ path: "../.env" }); -const accountId = process.env.ACCOUNT_ID; // Fetch the private key from a credentials file const credentialsPath = "../credentials-file.json"; // Path relative to the working directory const credentials = JSON.parse(fs.readFileSync(credentialsPath)); -// Create a key pair from the private key -const keyPair = KeyPair.fromString(credentials.private_key); -// Create a keystore and add the key pair -const myKeyStore = new keyStores.InMemoryKeyStore(); -myKeyStore.setKey("testnet", accountId, keyPair); - -// Create a connection to the NEAR testnet -const connectionConfig = { - networkId: "testnet", - keyStore: myKeyStore, - nodeUrl: "https://test.rpc.fastnear.com", -}; -const nearConnection = await connect(connectionConfig); - -// Create an account object -const account = await nearConnection.account(accountId); // example-account.testnet + +// Create a signer from the private key +const signer = KeyPairSigner.fromSecretKey(credentials.private_key); + +// Create a connection to testnet RPC +const provider = new JsonRpcProvider({ + url: "https://test.rpc.fastnear.com", +}); + +// Instantiate the account +const accountId = process.env.ACCOUNT_ID; +const account = new Account(accountId, provider, signer); // Test the signer by transferring NEAR -const sendTokensResult = await account.sendMoney( - "receiver-account.testnet", - utils.format.parseNearAmount("1"), +const sendTokensResult = await account.transferToken( + NEAR, + NEAR.toUnits("0.1"), + "receiver-account.testnet" ); + console.log(sendTokensResult); diff --git a/javascript/examples/keystore-options/private-key-string.js b/javascript/examples/keystore-options/private-key-string.js index ecfa921..dca05b3 100644 --- a/javascript/examples/keystore-options/private-key-string.js +++ b/javascript/examples/keystore-options/private-key-string.js @@ -1,30 +1,33 @@ -import { connect, keyStores, KeyPair, utils } from "near-api-js"; +import { Account } from "@near-js/accounts"; +import { JsonRpcProvider } from "@near-js/providers"; +import { KeyPairSigner } from "@near-js/signers"; +import { NearToken } from "@near-js/tokens"; + +const NEAR = new NearToken(); + import dotenv from "dotenv"; // Load environment variables dotenv.config({ path: "../.env" }); -const privateKey = process.env.PRIVATE_KEY; -const accountId = process.env.ACCOUNT_ID; -// Create a keystore and add the key pair via a private key string -const myKeyStore = new keyStores.InMemoryKeyStore(); -const keyPair = KeyPair.fromString(privateKey); // ed25519:5Fg2... -await myKeyStore.setKey("testnet", accountId, keyPair); +// Create a signer from a private key string +const privateKey = process.env.PRIVATE_KEY; +const signer = KeyPairSigner.fromSecretKey(privateKey); -// Create a connection to NEAR testnet -const connectionConfig = { - networkId: "testnet", - keyStore: myKeyStore, - nodeUrl: "https://test.rpc.fastnear.com", -}; -const nearConnection = await connect(connectionConfig); +// Create a connection to testnet RPC +const provider = new JsonRpcProvider({ + url: "https://test.rpc.fastnear.com", +}); -// Create an account object -const account = await nearConnection.account(accountId); // example-account.testnet +// Instantiate an account +const accountId = process.env.ACCOUNT_ID; +const account = new Account(accountId, provider, signer); // Test the signer by transferring NEAR -const sendTokensResult = await account.sendMoney( - "receiver-account.testnet", - utils.format.parseNearAmount("1"), +const sendTokensResult = await account.transferToken( + NEAR, + NEAR.toUnits("0.1"), + "receiver-account.testnet" ); + console.log(sendTokensResult); diff --git a/javascript/examples/keystore-options/seed-phrase.js b/javascript/examples/keystore-options/seed-phrase.js index cdd78ec..0145318 100644 --- a/javascript/examples/keystore-options/seed-phrase.js +++ b/javascript/examples/keystore-options/seed-phrase.js @@ -1,32 +1,37 @@ -import { connect, keyStores, KeyPair, utils } from "near-api-js"; +import { Account } from "@near-js/accounts"; +import { JsonRpcProvider } from "@near-js/providers"; +import { KeyPairSigner } from "@near-js/signers"; +import { parseNearAmount } from "@near-js/utils"; import { parseSeedPhrase } from "near-seed-phrase"; import dotenv from "dotenv"; +import { NearToken } from "@near-js/tokens"; + +const NEAR = new NearToken(); // Load environment variables dotenv.config({ path: "../.env" }); -const seedPhrase = process.env.SEED_PHRASE; -const accountId = process.env.ACCOUNT_ID; // Create a keystore and add the key pair via a seed phrase -const { secretKey } = parseSeedPhrase(seedPhrase); // "royal success river ..." -const myKeyStore = new keyStores.InMemoryKeyStore(); -const keyPair = KeyPair.fromString(secretKey); // ed25519::5Fg2... -await myKeyStore.setKey("testnet", accountId, keyPair); - -// Create a connection to NEAR testnet -const connectionConfig = { - networkId: "testnet", - keyStore: myKeyStore, - nodeUrl: "https://test.rpc.fastnear.com", -}; -const nearConnection = await connect(connectionConfig); +const seedPhrase = process.env.SEED_PHRASE; // "royal success river ..." +const { secretKey } = parseSeedPhrase(seedPhrase); + +// Create a signer from a private key string +const signer = KeyPairSigner.fromSecretKey(secretKey); + +// Create a connection to testnet RPC +const provider = new JsonRpcProvider({ + url: "https://test.rpc.fastnear.com", +}); // Create an account object -const account = await nearConnection.account(accountId); // example-account.testnet +const accountId = process.env.ACCOUNT_ID; +const account = new Account(accountId, provider, signer); // Test the signer by transferring NEAR -const sendTokensResult = await account.sendMoney( - "receiver-account.testnet", - utils.format.parseNearAmount("1"), +const sendTokensResult = await account.transferToken( + NEAR, + NEAR.toUnits("0.1"), + "receiver-account.testnet" ); + console.log(sendTokensResult); diff --git a/javascript/examples/manual-sign.js b/javascript/examples/manual-sign.js index 5d7874e..ffa41f0 100644 --- a/javascript/examples/manual-sign.js +++ b/javascript/examples/manual-sign.js @@ -1,61 +1,77 @@ -import { KeyPair, transactions, providers, utils } from "near-api-js"; -import sha256 from "js-sha256"; +import { JsonRpcProvider } from "@near-js/providers"; +import { Account } from "@near-js/accounts"; +import { KeyPairSigner } from "@near-js/signers"; +import { actionCreators, createTransaction } from "@near-js/transactions"; +import { baseDecode } from "@near-js/utils"; +import { NEAR } from "@near-js/tokens"; + import dotenv from "dotenv"; dotenv.config({ path: "../.env" }); -const privateKey = process.env.PRIVATE_KEY; -const accountId = process.env.ACCOUNT_ID; -const keyPair = KeyPair.fromString(privateKey); +const accountId = process.env.ACCOUNT_ID; -const provider = new providers.JsonRpcProvider({ +// Create a provider for testnet RPC +const provider = new JsonRpcProvider({ url: "https://test.rpc.fastnear.com", }); -// Get the nonce of the key -const accessKey = await provider.query( - `access_key/${accountId}/${keyPair.getPublicKey().toString()}`, - "", -); +// Assume there is a signer that will sign the transaction +const privateKey = process.env.PRIVATE_KEY; +const signer = KeyPairSigner.fromSecretKey(privateKey); // ed25519:5Fg2... + +// We only need to know the public key of the signer +const signerPublicKey = await signer.getPublicKey(); + +// We create a transaction manually + +// 1. Get the nonce of the key +const accessKey = await provider.viewAccessKey(accountId, signerPublicKey); const nonce = ++accessKey.nonce; -// Get a recent block hash -const recentBlockHash = utils.serialize.base_decode(accessKey.block_hash); +// 2. Get a recent block hash +const recentBlockHash = baseDecode(accessKey.block_hash); -// Construct actions -const actions = [transactions.transfer(utils.format.parseNearAmount("1"))]; +// 3. Construct the transaction +const actions = [actionCreators.transfer(NEAR.toUnits("0.1"))]; -// Construct transaction -const transaction = transactions.createTransaction( +const transaction = createTransaction( accountId, - keyPair.getPublicKey(), + signerPublicKey, "receiver-account.testnet", nonce, actions, - recentBlockHash, -); - -// Serialize transaction -const serializedTx = utils.serialize.serialize( - transactions.SCHEMA.Transaction, - transaction, + recentBlockHash ); -// Get serialized transaction hash -const serializedTxHash = new Uint8Array(sha256.sha256.array(serializedTx)); - -// Get signature -const signature = keyPair.sign(serializedTxHash); - -// Construct signed transaction -const signedTransaction = new transactions.SignedTransaction({ - transaction, - signature: new transactions.Signature({ - keyType: transaction.publicKey.keyType, - data: signature.signature, - }), -}); +// Sign and send +const [txHash, signedTransaction] = await signer.signTransaction(transaction); +console.log(Buffer.from(txHash).toString("hex")); // Send transaction const sendTransactionResult = await provider.sendTransaction(signedTransaction); console.log(sendTransactionResult); + + +/** + * We can also simply instantiate an account object (that does not require a signer) + * and use let it construct the transaction for us. + */ + +// 1. Instantiate account +const account = new Account(accountId, provider); + +// 2. Create transaction +const transaction2 = await account.createTransaction( + "receiver-account.testnet", + actions, + signerPublicKey +) + +// 3. Sign transaction +const [txHash2, signedTransaction2] = await signer.signTransaction(transaction2); +console.log(Buffer.from(txHash2).toString("hex")); + +// 4. Send transaction +const sendTransactionResult2 = await provider.sendTransaction(signedTransaction2); +console.log(sendTransactionResult2); diff --git a/javascript/examples/rpc-failover.js b/javascript/examples/rpc-failover.js index af2189e..21eb60b 100644 --- a/javascript/examples/rpc-failover.js +++ b/javascript/examples/rpc-failover.js @@ -1,43 +1,41 @@ -import { connect, keyStores, KeyPair, utils, providers } from "near-api-js"; +import { Account } from "@near-js/accounts"; +import { JsonRpcProvider, FailoverRpcProvider } from "@near-js/providers"; +import { KeyPairSigner } from "@near-js/signers"; +import { NEAR } from "@near-js/tokens"; + import dotenv from "dotenv"; dotenv.config({ path: "../.env" }); -const privateKey = process.env.PRIVATE_KEY; -const accountId = process.env.ACCOUNT_ID; -const myKeyStore = new keyStores.InMemoryKeyStore(); -const keyPair = KeyPair.fromString(privateKey); -await myKeyStore.setKey("testnet", accountId, keyPair); +// Create a signer from a private key string +const privateKey = process.env.PRIVATE_KEY; +const signer = KeyPairSigner.fromSecretKey(privateKey); // ed25519:5Fg2... // Set up a new FailoverRpcProvider with two JSON RPC providers const jsonProviders = [ - new providers.JsonRpcProvider( + new JsonRpcProvider({ url: "https://incorrect-rpc-url.com" }), // Incorrect RPC URL + new JsonRpcProvider( { url: "https://test.rpc.fastnear.com" }, // RPC URL { retries: 3, // Number of retries before giving up on a request backoff: 2, // Backoff factor for the retry delay wait: 500, // Wait time between retries in milliseconds - }, // Retry options + } // Retry options ), - new providers.JsonRpcProvider({ - url: "https://test.rpc.fastnear.com", - }), // Second RPC URL ]; -const provider = new providers.FailoverRpcProvider(jsonProviders); // Create a FailoverRpcProvider -const connectionConfig = { - networkId: "testnet", - keyStore: myKeyStore, - nodeUrl: "https://incorrect-rpc-url.com", // Incorrect RPC URL - provider: provider, -}; -const nearConnection = await connect(connectionConfig); +const provider = new FailoverRpcProvider(jsonProviders); // Create a FailoverRpcProvider -const account = await nearConnection.account(accountId); +// Create an account object +const accountId = process.env.ACCOUNT_ID; +const account = new Account(accountId, provider, signer); // example-account.testnet // Test the signer with transferring 1 NEAR -const sendTokensResult = await account.sendMoney( - "receiver-account.testnet", - utils.format.parseNearAmount("1"), +const sendTokensResult = await account.transfer( + { + token: NEAR, + amount: NEAR.toUnits("0.1"), // Amount of NEAR being sent + receiverId: "receiver-account.testnet", // Receiver account ID + } ); console.log(sendTokensResult); diff --git a/javascript/examples/seat-price.js b/javascript/examples/seat-price.js new file mode 100644 index 0000000..d6794ff --- /dev/null +++ b/javascript/examples/seat-price.js @@ -0,0 +1,20 @@ +import { JsonRpcProvider } from "@near-js/providers"; +import { formatNearAmount } from "@near-js/utils"; + +import dotenv from "dotenv"; + +// Load environment variables +dotenv.config({ path: "../.env" }); // Path relative to the working directory + +// Create a connection to testnet RPC +const provider = new JsonRpcProvider({ + url: "https://test.rpc.fastnear.com", +}); + +const currentEpochSeatPrice = await provider.getCurrentEpochSeatPrice(); + +console.log(`Current epoch seat price: ${formatNearAmount(currentEpochSeatPrice.toString(), 3)}N`); + +const nextEpochSeatPrice = await provider.getNextEpochSeatPrice(); + +console.log(`Next epoch seat price: ${formatNearAmount(nextEpochSeatPrice.toString(), 3)}N`); diff --git a/javascript/examples/send-tokens.js b/javascript/examples/send-tokens.js index bf7bc64..4ad6e0a 100644 --- a/javascript/examples/send-tokens.js +++ b/javascript/examples/send-tokens.js @@ -1,31 +1,69 @@ -import * as nearAPI from "near-api-js"; +import { Account } from "@near-js/accounts"; +import { JsonRpcProvider } from "@near-js/providers"; +import { KeyPairSigner } from "@near-js/signers"; +import { FungibleToken, NEAR } from "@near-js/tokens"; +import { USDT } from "@near-js/tokens/testnet"; + import dotenv from "dotenv"; -const { connect, keyStores, KeyPair, utils } = nearAPI; +const REF = new FungibleToken("ref.fakes.testnet", { + decimals: 18, + symbol: "REF", +}); // Load environment variables dotenv.config({ path: "../.env" }); // Path relative to the working directory const privateKey = process.env.PRIVATE_KEY; const accountId = process.env.ACCOUNT_ID; -// Create a keystore and add the key pair via the private key string -const myKeyStore = new keyStores.InMemoryKeyStore(); -const keyPair = KeyPair.fromString(privateKey); -await myKeyStore.setKey("testnet", accountId, keyPair); - -// Create a connection to the NEAR testnet -const connectionConfig = { - networkId: "testnet", - keyStore: myKeyStore, - nodeUrl: "https://test.rpc.fastnear.com", -}; -const nearConnection = await connect(connectionConfig); - -const account = await nearConnection.account(accountId); - -// Send NEAR tokens to another account -const sendTokensResult = await account.sendMoney( - "receiver-account.testnet", // Receiver account - utils.format.parseNearAmount("1"), // Amount being sent in yoctoNEAR +// Create a signer from a private key string +const signer = KeyPairSigner.fromSecretKey(privateKey); // ed25519:5Fg2... + +// Create a connection to testnet RPC +const provider = new JsonRpcProvider({ + url: "https://test.rpc.fastnear.com", +}); + +// Create an account object +const account = new Account(accountId, provider, signer); // example-account.testnet + +// ------- Send NEAR tokens to another account ------- +const sendNearTokensResult = await account.transfer( + { + token: NEAR, + amount: NEAR.toUnits("0.1"), + receiverId: "receiver-account.testnet" + } +); +console.log(sendNearTokensResult); + +// ------- Send USDT tokens to another account ------- +// if a user isn't registered, the transfer will fail +// it a user is already registered, we'll just get funds back +await USDT.registerAccount({ + accountIdToRegister: "receiver-account.testnet", + fundingAccount: account, +}) + +// Use https://testnet.rhea.finance/#near|usdtt.fakes.testnet to get USDT token +const sendUsdtTokensResult = await account.transfer( + { + token: USDT, + amount: USDT.toUnits("1"), // Amount of USDT being sent + receiverId: "receiver-account.testnet" + } ); -console.log(sendTokensResult); +console.log(sendUsdtTokensResult); + +// ------- Send REF tokens to another account ------- +// Use https://testnet.rhea.finance/#near|ref.fakes.testnet to get REF tokens +const sendREFsResult = await account.transfer( + { + token: REF, + amount: REF.toUnits("1"), // Amount of REF tokens being sent + receiverId: "receiver-account.testnet" + } +); + +// we haven't registered a receiver before sending, so it may fail +console.log(sendREFsResult); diff --git a/javascript/examples/simultaneous-transactions.js b/javascript/examples/simultaneous-transactions.js index 160ff57..deb3679 100644 --- a/javascript/examples/simultaneous-transactions.js +++ b/javascript/examples/simultaneous-transactions.js @@ -1,50 +1,100 @@ -import { connect, keyStores, KeyPair, transactions } from "near-api-js"; +import { Account } from "@near-js/accounts"; +import { JsonRpcProvider } from "@near-js/providers"; +import { KeyPairSigner } from "@near-js/signers"; +import { actionCreators } from "@near-js/transactions"; +import { KeyPair } from "@near-js/crypto"; + import dotenv from "dotenv"; dotenv.config({ path: "../.env" }); const privateKey = process.env.PRIVATE_KEY; const accountId = process.env.ACCOUNT_ID; -const myKeyStore = new keyStores.InMemoryKeyStore(); -const keyPair = KeyPair.fromString(privateKey); -await myKeyStore.setKey("testnet", accountId, keyPair); +// Create a signer from a private key string +const signer = KeyPairSigner.fromSecretKey(privateKey); + +// Create a connection to testnet RPC +const provider = new JsonRpcProvider({ + url: "https://test.rpc.fastnear.com", +}); + +// Create an account object +const account = new Account(accountId, provider, signer); // example-account.testnet + +// Transactions can only be truly simultaneous if signed with different key pairs, +// since each key tracks its own nonce, sending multiple transactions from the same key, +// even with distinct nonces, risks race conditions and execution conflicts. -const connectionConfig = { - networkId: "testnet", - keyStore: myKeyStore, - nodeUrl: "https://test.rpc.fastnear.com", -}; -const nearConnection = await connect(connectionConfig); +// 1. (Optional) Create two different key pairs and add them to your account +// This step is optional, so you can skip it if you already have the keys ready. +const keyPairOne = KeyPair.fromRandom("ed25519"); +console.log("KeyPair One:", keyPairOne.getPublicKey().toString()); -const account = await nearConnection.account(accountId); +const keyPairTwo = KeyPair.fromRandom("ed25519"); +console.log("KeyPair Two:", keyPairTwo.getPublicKey().toString()); -// Send independent transactions simultaneously to different receivers -// Prepare the transactions -const args = Buffer.from(JSON.stringify({ text: "Hello, world!" })); -const tx1 = account.signAndSendTransaction({ - receiverId: "guestbook.near-examples.testnet", +// add two keys in a single transaction +await account.signAndSendTransaction({ + receiverId: account.accountId, actions: [ - transactions.functionCall( - "add_message", // Method name - args, // Arguments - 100000000000000, // Gas - 0, // Deposit + actionCreators.addKey( + keyPairOne.getPublicKey(), + actionCreators.fullAccessKey() + ), + actionCreators.addKey( + keyPairTwo.getPublicKey(), + actionCreators.fullAccessKey() ), ], + waitUntil: "FINAL", }); -const tx2 = account.signAndSendTransaction({ - receiverId: "counter.near-examples.testnet", - actions: [ - transactions.functionCall( - "increment", // Method name - [], // Arguments - 100000000000000, // Gas - 0, // Deposit +const accountOne = new Account( + accountId, + provider, + new KeyPairSigner(keyPairOne) +); +const accountTwo = new Account( + accountId, + provider, + new KeyPairSigner(keyPairTwo) +); + +// 2. Construct the transactions +const signedTxOne = await accountOne.createSignedTransaction( + "guestbook.near-examples.testnet", + [ + actionCreators.functionCall( + "add_message", + { text: "Hello, world!" }, + "30000000000000", + 0 ), - ], -}); + ] +); +const signedTxTwo = await accountTwo.createSignedTransaction( + "counter.near-examples.testnet", + [actionCreators.functionCall("increment", {}, "30000000000000", 0)] +); + +console.log("Created two different signed transactions"); -// Send the transactions simultaneously -const transactionsResults = await Promise.all([tx1, tx2]); +// 3. Send the transactions +const sendTxOne = provider.sendTransaction(signedTxOne); +const sendTxTwo = provider.sendTransaction(signedTxTwo); + +// Wait for them to finish +const transactionsResults = await Promise.all([sendTxOne, sendTxTwo]); console.log(transactionsResults); + +// 4. (Optional) Since we created these keys just for this example, we’ll remove them afterward +// But in a real application, you don’t need to delete them unless there's a specific reason to. + +// delete two keys in a single transaction +await account.signAndSendTransaction({ + receiverId: account.accountId, + actions: [ + actionCreators.deleteKey(keyPairOne.getPublicKey()), + actionCreators.deleteKey(keyPairTwo.getPublicKey()), + ], +}); diff --git a/javascript/examples/tokens-balance.js b/javascript/examples/tokens-balance.js new file mode 100644 index 0000000..2ffe6ef --- /dev/null +++ b/javascript/examples/tokens-balance.js @@ -0,0 +1,38 @@ +import { Account } from "@near-js/accounts"; +import { JsonRpcProvider } from "@near-js/providers"; +import { FungibleToken, NEAR } from "@near-js/tokens"; +import { USDT } from "@near-js/tokens/testnet"; + +import dotenv from "dotenv"; + +const REF = new FungibleToken("ref.fakes.testnet", { + decimals: 18, + symbol: "REF", +}); + +// Load environment variables +dotenv.config({ path: "../.env" }); // Path relative to the working directory +const accountId = process.env.ACCOUNT_ID; + +// Create a connection to testnet RPC +const provider = new JsonRpcProvider({ + url: "https://test.rpc.fastnear.com", +}); + +// Create an account object +const account = new Account(accountId, provider); + +// ------- Fetch NEAR tokens balance in the smallest units as BigInt ------- +const nearTokensBalanceInt = await account.getBalance(NEAR); +console.log("NEAR as units: ", nearTokensBalanceInt); +console.log("NEAR: ", NEAR.toDecimal(nearTokensBalanceInt)); + +// ------- Fetch USDT tokens balance in the smallest units as BigInt ------- +const usdtTokensBalanceInt = await account.getBalance(USDT); +console.log("USDT as units: ", usdtTokensBalanceInt); +console.log("USDT: ", USDT.toDecimal(usdtTokensBalanceInt)); + +// ------- Fetch REF tokens balance in the smallest units as BigInt ------- +const refTokensBalanceInt = await account.getBalance(REF); +console.log("REF as units: ", refTokensBalanceInt); +console.log("REF: ", REF.toDecimal(refTokensBalanceInt)); diff --git a/javascript/examples/utils.js b/javascript/examples/utils.js index 81c5704..015d6a6 100644 --- a/javascript/examples/utils.js +++ b/javascript/examples/utils.js @@ -1,9 +1,18 @@ -import { utils } from "near-api-js"; +import { USDT } from "@near-js/tokens/testnet"; +import { NEAR } from "@near-js/tokens"; // Convert NEAR amount into yoctoNEAR -const amountInYoctoNear = utils.format.parseNearAmount("1"); +const amountInYoctoNear = NEAR.toUnits("0.1"); console.log(amountInYoctoNear); // Convert yoctoNEAR amount into NEAR -const amountInNear = utils.format.formatNearAmount("1000000000000000000000000"); +const amountInNear = NEAR.toDecimal("1000000000000000000000000"); console.log(amountInNear); + +// convert USDT amount into base units +const amountInUsdtUnits = USDT.toUnits("0.1").toString(); +console.log(amountInUsdtUnits); + +// convert base units into USDT +const amountInUsdt = USDT.toDecimal("12300000"); +console.log(amountInUsdt); diff --git a/javascript/examples/verify-signature/authentication.js b/javascript/examples/verify-signature/authentication.js index b45ce5a..dc15f1a 100644 --- a/javascript/examples/verify-signature/authentication.js +++ b/javascript/examples/verify-signature/authentication.js @@ -1,5 +1,5 @@ import * as borsh from 'borsh'; -import * as naj from 'near-api-js'; +import { PublicKey } from '@near-js/crypto'; import js_sha256 from 'js-sha256'; class Payload { @@ -33,7 +33,7 @@ function verifySignature({ publicKey, signature, message, recipient, nonce }) { let real_signature = Buffer.from(signature, 'base64') // Use the public Key to verify that the private-counterpart signed the message - const myPK = naj.utils.PublicKey.from(publicKey) + const myPK = PublicKey.from(publicKey) return myPK.verify(to_sign, real_signature) } diff --git a/javascript/package.json b/javascript/package.json index 535b14e..66c6043 100644 --- a/javascript/package.json +++ b/javascript/package.json @@ -1,28 +1,39 @@ { "type": "module", "dependencies": { + "@near-js/accounts": "^2.0.1", + "@near-js/crypto": "^2.0.1", + "@near-js/keystores-node": "^2.0.1", + "@near-js/providers": "^2.0.1", + "@near-js/signers": "^2.0.1", + "@near-js/tokens": "^2.0.1", + "@near-js/transactions": "^2.0.1", + "@near-js/utils": "^2.0.1", "borsh": "2.0.0", "dotenv": "^16.4.7", "js-sha256": "^0.11.0", - "near-api-js": "^4.0.4", "near-seed-phrase": "^0.2.1" }, "scripts": { - "credentials-directory": "node examples/keystore-options/credentials-directory.js", - "credentials-file": "node examples/keystore-options/credentials-file.js", - "private-key-string": "node examples/keystore-options/private-key-string.js", - "seed-phrase": "node examples/keystore-options/seed-phrase.js", "account-details": "node examples/account-details.js", "batch-actions": "node examples/batch-actions.js", "contract-interaction": "node examples/contract-interaction.js", "create-account-from-seed": "node examples/create-account-from-seed.js", - "create-account": "node examples/create-account.js", + "create-subaccount": "node examples/create-subaccount.js", + "create-tla": "node examples/create-tla.js", + "credentials-directory": "node examples/keystore-options/credentials-directory.js", + "credentials-file": "node examples/keystore-options/credentials-file.js", "delete-account": "node examples/delete-account.js", + "deploy-contract": "node examples/deploy-contract.js", "keys": "node examples/keys.js", "manual-sign": "node examples/manual-sign.js", + "private-key-string": "node examples/keystore-options/private-key-string.js", "rpc-failover": "node examples/rpc-failover.js", + "seat-price": "node examples/seat-price.js", + "seed-phrase": "node examples/keystore-options/seed-phrase.js", "send-tokens": "node examples/send-tokens.js", "simultaneous-transactions": "node examples/simultaneous-transactions.js", + "tokens-balance": "node examples/tokens-balance.js", "utils": "node examples/utils.js", "verify-signature": "node examples/verify-signature/verify-signature.js" } diff --git a/javascript/pnpm-lock.yaml b/javascript/pnpm-lock.yaml index 5d53a49..1375432 100644 --- a/javascript/pnpm-lock.yaml +++ b/javascript/pnpm-lock.yaml @@ -8,67 +8,116 @@ importers: .: dependencies: + '@near-js/accounts': + specifier: ^2.0.1 + version: 2.0.1(94f60b238a57a2159112ee1ca73e0c5d) + '@near-js/crypto': + specifier: ^2.0.1 + version: 2.0.1(@near-js/types@2.0.1)(@near-js/utils@2.0.1(@near-js/types@2.0.1)) + '@near-js/keystores-node': + specifier: ^2.0.1 + version: 2.0.1(@near-js/crypto@2.0.1(@near-js/types@2.0.1)(@near-js/utils@2.0.1(@near-js/types@2.0.1)))(@near-js/keystores@2.0.1(@near-js/crypto@2.0.1(@near-js/types@2.0.1)(@near-js/utils@2.0.1(@near-js/types@2.0.1)))(@near-js/types@2.0.1)) + '@near-js/providers': + specifier: ^2.0.1 + version: 2.0.1(@near-js/crypto@2.0.1(@near-js/types@2.0.1)(@near-js/utils@2.0.1(@near-js/types@2.0.1)))(@near-js/transactions@2.0.1(@near-js/crypto@2.0.1(@near-js/types@2.0.1)(@near-js/utils@2.0.1(@near-js/types@2.0.1)))(@near-js/types@2.0.1)(@near-js/utils@2.0.1(@near-js/types@2.0.1)))(@near-js/types@2.0.1)(@near-js/utils@2.0.1(@near-js/types@2.0.1)) + '@near-js/signers': + specifier: ^2.0.1 + version: 2.0.1(@near-js/crypto@2.0.1(@near-js/types@2.0.1)(@near-js/utils@2.0.1(@near-js/types@2.0.1)))(@near-js/keystores@2.0.1(@near-js/crypto@2.0.1(@near-js/types@2.0.1)(@near-js/utils@2.0.1(@near-js/types@2.0.1)))(@near-js/types@2.0.1))(@near-js/transactions@2.0.1(@near-js/crypto@2.0.1(@near-js/types@2.0.1)(@near-js/utils@2.0.1(@near-js/types@2.0.1)))(@near-js/types@2.0.1)(@near-js/utils@2.0.1(@near-js/types@2.0.1))) + '@near-js/tokens': + specifier: ^2.0.1 + version: 2.0.1 + '@near-js/transactions': + specifier: ^2.0.1 + version: 2.0.1(@near-js/crypto@2.0.1(@near-js/types@2.0.1)(@near-js/utils@2.0.1(@near-js/types@2.0.1)))(@near-js/types@2.0.1)(@near-js/utils@2.0.1(@near-js/types@2.0.1)) + '@near-js/utils': + specifier: ^2.0.1 + version: 2.0.1(@near-js/types@2.0.1) borsh: - specifier: 1.0.0 - version: 1.0.0 + specifier: 2.0.0 + version: 2.0.0 dotenv: specifier: ^16.4.7 version: 16.4.7 js-sha256: specifier: ^0.11.0 version: 0.11.0 - near-api-js: - specifier: ^4.0.4 - version: 4.0.4 near-seed-phrase: specifier: ^0.2.1 version: 0.2.1 packages: - '@near-js/accounts@1.2.2': - resolution: {integrity: sha512-8XInUVl8WwQyitRkG1HffZKhDmAXUwOaxurgkTYocDUUUp+ZB8NPxidg2uvj6f2wqnC8KAkjpm73wPoyRm6+yQ==} - - '@near-js/crypto@1.3.0': - resolution: {integrity: sha512-BIKO6v+rbYCzzrjsSV4KgClVgRiPluIXQ89B4ozIG8RjjBe/7IPFYF9tIxsXUyLzPFhISzeNQkL09ksHHmnymg==} - - '@near-js/keystores-browser@0.1.0': - resolution: {integrity: sha512-v/4uFHKnbEXY4UcOAVCUSb3GKsVdrwv4uXBSPluvE16H9oxjB1+gfcz5qejwKp2cifYNCO0KfAWLnZas66Ohcg==} + '@near-js/accounts@2.0.1': + resolution: {integrity: sha512-RLkE4Fta5ip0IXcr0fQEBir5pZN+yInAqetDvW1XEjxMeW14WvCGYNouuhOQq13jvUmSsWG95PEke6zUsUswLg==} + peerDependencies: + '@near-js/crypto': ^2.0.1 + '@near-js/providers': ^2.0.1 + '@near-js/signers': ^2.0.1 + '@near-js/transactions': ^2.0.1 + '@near-js/types': ^2.0.1 + '@near-js/utils': ^2.0.1 + + '@near-js/crypto@2.0.1': + resolution: {integrity: sha512-UyH0by2a2XR4i1SctuwWprWpsLIL8uGX/XUbTxMAqOxbPWwvt/DGuG/eZFLoEQPyfuU5nLwkVuovrJXH/xSttA==} + peerDependencies: + '@near-js/types': ^2.0.1 + '@near-js/utils': ^2.0.1 - '@near-js/keystores-node@0.0.13': - resolution: {integrity: sha512-cnk2mwIRr7bCPgqz7KHU1Bqxm0u9J+FIubZ0AllFpMVMv8TJVVbs7FcsVIk282oeM7xxikjVJjs35DG6//Fehw==} + '@near-js/keystores-node@2.0.1': + resolution: {integrity: sha512-CbAne0McTuQLcnAFqbmPrE1C4n36AO5QY0b+sLbl1y5CXMIVaRcGUEywq3brlNaHSh7U3oajMRthbl5mVg/xtA==} + peerDependencies: + '@near-js/crypto': ^2.0.1 + '@near-js/keystores': ^2.0.1 - '@near-js/keystores@0.1.0': - resolution: {integrity: sha512-89EwYFDvPg7GnJAKmBDASKUSTXny0ZqgqDnSdhp7oJ78bXNlCs9xx0WnkK34TxFBnrL4c9szLjTkfGRcFT07NQ==} + '@near-js/keystores@2.0.1': + resolution: {integrity: sha512-KqUAGwCU+0N04jmFTGfnrMo3G3wZWvNUNH2Soaxm+mUfKjjo1Q5eGicSCVfsUU0v8x04uPta4RfMHFh7aN3/Cg==} + peerDependencies: + '@near-js/crypto': ^2.0.1 + '@near-js/types': ^2.0.1 - '@near-js/providers@0.2.3': - resolution: {integrity: sha512-JBSze9fdoRXkOsFeLiooPWGm3vemY2dgHT0u0HoJCjpQtt41v7tr+6sWpxGWCaDwrzIwhm7og4qkGv4K9IxFVw==} + '@near-js/providers@2.0.1': + resolution: {integrity: sha512-SUWhm9F9mXU2l4tPtRL+WSBYT+CR/yC60YARlI107Pes7kHKHomWC9lU30M2u0W6cWALrGZKEL5nLpTIpDMGWQ==} + peerDependencies: + '@near-js/crypto': ^2.0.1 + '@near-js/transactions': ^2.0.1 + '@near-js/types': ^2.0.1 + '@near-js/utils': ^2.0.1 - '@near-js/signers@0.1.5': - resolution: {integrity: sha512-UldCktmR6HF6N2gPbgiUS8QPYCcDwjyzpdi3ukKezfY2NGA++F068ZwP50S+aQrtcwEBpECTo/Ps6pZq7cSVeQ==} + '@near-js/signers@2.0.1': + resolution: {integrity: sha512-ip9R4zmqo4HFlV+k7iXLCth0UkbHw8bV+WSKc5XaIqkgO2BGiUaV+Y6L/3qqCC8Gga/VPDXQtdV38JjcNuHS2w==} + peerDependencies: + '@near-js/crypto': ^2.0.1 + '@near-js/keystores': ^2.0.1 + '@near-js/transactions': ^2.0.1 - '@near-js/transactions@1.2.3': - resolution: {integrity: sha512-wwkUupWrmKfdZmv6TmnTrskysX37F2SVHcns6BVwPjp6nFD29NAhul71I6u++8496Lq2FrgM1Kb8pEIpG9TV9w==} + '@near-js/tokens@2.0.1': + resolution: {integrity: sha512-Ghb/PV75HGF3lSCh4PP7veFtJreNCEnblSlmy4+Jwu69bxhGjvgsoyUqAfkRalvk/guz4TNGiG4fA4GBkOK7mQ==} - '@near-js/types@0.2.1': - resolution: {integrity: sha512-YygQEGMdFe6d2e/6dtNZer9paH396XeAdIKEhY/RPXDUnjDdfiDQ5DK4mM130sEeID2bAH9X1LQ+7vXGRjvyWw==} + '@near-js/transactions@2.0.1': + resolution: {integrity: sha512-dDS8U0WrtKzEUFiCMQlwS2MDouRIBujNzz+hsafJHMSJ5aT8aFpzHTaQqo17zKF6sOk+QbA+PQFp90G76aWF3A==} + peerDependencies: + '@near-js/crypto': ^2.0.1 + '@near-js/types': ^2.0.1 + '@near-js/utils': ^2.0.1 - '@near-js/utils@0.3.0': - resolution: {integrity: sha512-ExeWqP0b4subLcQuLDIixAZs6tiCWifDBz2OwU9ycntyjZslUUh4EKBaSS3mAEqhJ/t1B9WX80BntE/5PQ+JTg==} + '@near-js/types@2.0.1': + resolution: {integrity: sha512-kXvAqp8oAc9vnhIlUCazfMx/eHhbyBPA0R0rwZ7ItbdV9tuQhI+lbf3C0EHcCG7NgopDLmf5MpbeIqgOcU3iMg==} - '@near-js/wallet-account@1.2.3': - resolution: {integrity: sha512-yuYKKA8D06ztmbTvbajD8HBjP50x2NbMRPInsSSgNjBnvFA9f2J82SarzDLg+nTsayhMJdFGfArnKgIlO+bUaw==} + '@near-js/utils@2.0.1': + resolution: {integrity: sha512-/i8DF5s/cEW77I2iA2SuTpvbG8j4F9ieiO8visCGp5wrjWepSlxWl0B2DxXRlNLkvTui5k8aK9VWTxGK6uni6Q==} + peerDependencies: + '@near-js/types': ^2.0.1 - '@noble/curves@1.2.0': - resolution: {integrity: sha512-oYclrNgRaM9SsBUBVbb8M6DTV7ZHRTKugureoYEncY5c65HOmRzvSiTE3y5CYaPYJA/GVkrhXEoF0M3Ya9PMnw==} + '@noble/curves@1.8.1': + resolution: {integrity: sha512-warwspo+UYUPep0Q+vtdVB4Ugn8GGQj8iyB3gnRWsztmUHTI3S1nhdiWNsPUGL0vud7JlRRk1XEu7Lq1KGTnMQ==} + engines: {node: ^14.21.3 || >=16} - '@noble/hashes@1.3.2': - resolution: {integrity: sha512-MVC8EAQp7MvEcm30KWENFjgR+Mkmf+D189XJTkFIlwohU5hcBbn1ZkKq7KVTi2Hme3PMGF390DaL52beVrIihQ==} - engines: {node: '>= 16'} + '@noble/hashes@1.7.1': + resolution: {integrity: sha512-B8XBPsn4vT/KJAGqDzbwztd+6Yte3P4V7iafm24bxgDe/mlRuK6xmWPuCNrKt2vDafZ8MfJLlchDG/vYafQEjQ==} + engines: {node: ^14.21.3 || >=16} - '@noble/hashes@1.3.3': - resolution: {integrity: sha512-V7/fPHgl+jsVPXqqeOzT8egNj2iBIVt+ECeMMG8TdcnTikP3oaBtUVqpT/gYCR68aEBJSF+XbYUxStjbFMqIIA==} - engines: {node: '>= 16'} + '@scure/base@1.2.5': + resolution: {integrity: sha512-9rE6EOVeIQzt5TSu4v+K523F8u6DhBsoZWPGKlnCshhlDhy0kJzUX4V+tr2dWmzF1GdekvThABoEQBGBQI7xZw==} '@types/json-schema@7.0.15': resolution: {integrity: sha512-5+fP8P8MFNC+AyZCDxrB2pkZFPGzqQWUzpSeuuVLvm8VMcorNYavBqoFcxK8bQz4Qsbn4oUEEem4wDLfcysGHA==} @@ -76,11 +125,6 @@ packages: '@types/node@11.11.6': resolution: {integrity: sha512-Exw4yUWMBXM3X+8oqzJNRqZSwUAaS4+7NdvHqQuFi/d+synz++xmX3QIf+BFqneW8N31R8Ky+sikfZUXq07ggQ==} - base-x@2.0.6: - resolution: {integrity: sha512-UAmjxz9KbK+YIi66xej+pZVo/vxUOh49ubEvZW5egCbxhur05pBb+hwuireQwKO4nDpsNm64/jEei17LEpsr5g==} - engines: {node: '>=4.5.0'} - deprecated: use 3.0.0 instead, safe-buffer has been merged and release for compatability - base-x@3.0.10: resolution: {integrity: sha512-7d0s06rR9rYaIWHkpfLIFICM/tkSVdoPC9qYAQRpxn9DdKNWNsKC0uk++akckyLq16Tx2WIinnZ6WRriAt6njQ==} @@ -90,18 +134,18 @@ packages: bip39@3.0.2: resolution: {integrity: sha512-J4E1r2N0tUylTKt07ibXvhpT2c5pyAFgvuA5q1H9uDy6dEGpjV8jmymh3MTYJDLCNbIVClSB9FbND49I6N24MQ==} - bn.js@4.12.1: - resolution: {integrity: sha512-k8TVBiPkPJT9uHLdOKfFpqcfprwBFOAAXXozRubr7R7PfIuKvQlzcI4M0pALeqXN09vdaMbUdUj+pass+uULAg==} + bn.js@4.12.2: + resolution: {integrity: sha512-n4DSx829VRTRByMRGdjQ9iqsN0Bh4OolPsFnaZBLcbi8iXcB+kJ9s7EnRt4wILZNV3kPLHkRVfOc/HvhC3ovDw==} borsh@1.0.0: resolution: {integrity: sha512-fSVWzzemnyfF89EPwlUNsrS5swF5CrtiN4e+h0/lLf4dz2he4L3ndM20PS9wj7ICSkXJe/TQUHdaPTq15b1mNQ==} + borsh@2.0.0: + resolution: {integrity: sha512-kc9+BgR3zz9+cjbwM8ODoUB4fs3X3I5A/HtX7LZKxCLaMrEeDFoBpnhZY//DTS1VZBSs6S5v46RZRbZjRFspEg==} + brorand@1.1.0: resolution: {integrity: sha512-cKV8tMCEpQs4hK/ik71d6LrPOnpkpGBR0wzxqr68g2m/LB2GxVYQroAjMJZRVM1Y4BCjCKc3vAamxSzOY2RP+w==} - bs58@4.0.0: - resolution: {integrity: sha512-/jcGuUuSebyxwLLfKrbKnCJttxRf9PM51EnHTwmFKBxl4z1SGkoAhrfd6uZKE0dcjQTfm6XzTP8DPr1tzE4KIw==} - bs58@4.0.1: resolution: {integrity: sha512-Ok3Wdf5vOIlBrgCvTq96gBkJw+JUEzdBgyaza5HLtPm7yTHkjRy8+JzNyHF7BHa0bNWOQIp3m5YF0nnFcOIKLw==} @@ -115,10 +159,6 @@ packages: create-hmac@1.1.7: resolution: {integrity: sha512-MJG9liiZ+ogc4TzUwuvbER1JRdgvUFSB5+VR/g5h82fGaIRWMWddtKBHi7/sVhfjQZ6SehlyhvQYrcYkaUIpLg==} - depd@1.1.2: - resolution: {integrity: sha512-7emPTl6Dpo6JRXOXjLRxck+FlLRX5847cLKEn00PLAgc3g2hTZZgr+e4c2v6QpSmLeFP3n5yUo7ft6avBK/5jQ==} - engines: {node: '>= 0.6'} - depd@2.0.0: resolution: {integrity: sha512-g7nH6P6dyDioJogAAGprGpCtVImJhpPk/roCzdb3fIh61/s/nPsfR6onyMwkCAR/OlC3yBC0lESvUoQEAssIrw==} engines: {node: '>= 0.8'} @@ -130,6 +170,9 @@ packages: elliptic@6.6.1: resolution: {integrity: sha512-RaddvvMatK2LJHqFJ+YA4WysVN5Ita9E35botqIYspQ4TkRAlCicdzKOjlyv/1Za5RyTNn7di//eEV0uTAfe3g==} + exponential-backoff@3.1.2: + resolution: {integrity: sha512-8QxYTVXUkuy7fIIoitQkPwGonB8F3Zj8eEO8Sqg9Zv/bkI7RJAzowee4gr81Hak/dUTpA2Z7VfQgoijjPNlUZA==} + generate-function@2.3.1: resolution: {integrity: sha512-eeB5GfMNeevm/GRYq20ShmsaGcmI81kIX2K9XQx5miC8KdHaC6Jm0qQ8ZNeGOi7wYB8OsdxKs+Y2oVuTFuVwKQ==} @@ -146,13 +189,6 @@ packages: hmac-drbg@1.0.1: resolution: {integrity: sha512-Tti3gMqLdZfhOQY1Mzf/AanLiqh1WTiJgEj26ZuYQ9fbkLomzGchCws4FyrSd4VkpBfiNhaE1On+lOz894jvXg==} - http-errors@1.7.2: - resolution: {integrity: sha512-uUQBt3H/cSIVfch6i1EuPNy/YsRSOUBXTVfZ+yR7Zjez3qjBz6i9+i4zjNaoqcoFVI4lQJ5plg63TvGfRSDCRg==} - engines: {node: '>= 0.6'} - - inherits@2.0.3: - resolution: {integrity: sha512-x00IRNXNy63jwGkJmzPigoySHbaqpNuzKbBOmzK+g2OdZpQ9w+sxCN+VSB3ja7IAge2OP2qpfxTjeNcyjmW1uw==} - inherits@2.0.4: resolution: {integrity: sha512-k/vGaX4/Yla3WzyMCvTQOXYeIHvqOKtnqBduzTHpzpQZzAskKMhZ2K+EnBiSM9zGSoIFeMpXKxa4dYeZIQqewQ==} @@ -189,11 +225,8 @@ packages: engines: {npm: '>=1.4.0'} hasBin: true - near-abi@0.1.1: - resolution: {integrity: sha512-RVDI8O+KVxRpC3KycJ1bpfVj9Zv+xvq9PlW1yIFl46GhrnLw83/72HqHGjGDjQ8DtltkcpSjY9X3YIGZ+1QyzQ==} - - near-api-js@4.0.4: - resolution: {integrity: sha512-IG+6NAMtn854palu/cIbVgey0OsIzllcajc3fbEbh7cb2pyPNMsfsBIO5WqsV+rY+7Tqr6lqYQ8f+4BHGUttyg==} + near-abi@0.2.0: + resolution: {integrity: sha512-kCwSf/3fraPU2zENK18sh+kKG4uKbEUEQdyWQkmW8ZofmLarObIz2+zAYjA1teDZLeMvEQew3UysnPDXgjneaA==} near-hd-key@1.2.1: resolution: {integrity: sha512-SIrthcL5Wc0sps+2e1xGj3zceEa68TgNZDLuCx0daxmfTP7sFTB3/mtE2pYhlFsCxWoMn+JfID5E1NlzvvbRJg==} @@ -234,28 +267,17 @@ packages: safe-buffer@5.2.1: resolution: {integrity: sha512-rp3So07KcdmmKbGvgaNxQSJr7bGVSVk5S9Eq1F+ppbRo70+YeaDxkw5Dd8NPN+GD6bjnYm2VuPuCXmpuYvmCXQ==} - secp256k1@5.0.0: - resolution: {integrity: sha512-TKWX8xvoGHrxVdqbYeZM9w+izTF4b9z3NhSaDkdn81btvuh+ivbIMGT/zQvDtTFWhRlThpoz6LEYTr7n8A5GcA==} - engines: {node: '>=14.0.0'} - - setprototypeof@1.1.1: - resolution: {integrity: sha512-JvdAWfbXeIGaZ9cILp38HntZSFSo3mWg6xGcJJsd+d4aRMOqauag1C63dJfDw7OaMYwEbHMOxEZ1lqVRYP2OAw==} + secp256k1@5.0.1: + resolution: {integrity: sha512-lDFs9AAIaWP9UCdtWrotXWWF9t8PWgQDcxqgAnpM9rMqxb3Oaq2J0thzPVSxBwdJgyQtkU/sYtFtbM1RSt/iYA==} + engines: {node: '>=18.0.0'} sha.js@2.4.11: resolution: {integrity: sha512-QMEp5B7cftE7APOjk5Y6xgrbWu+WkLVQwk8JNjZ8nKRciZaByEW6MubieAiToS7+dwvrjGhH8jRXz3MVd0AYqQ==} hasBin: true - statuses@1.5.0: - resolution: {integrity: sha512-OpZ3zP+jT1PI7I8nemJX4AKmAX070ZkYPVWV/AaKTJl+tXCTGyVdC1a4SL8RUQYEwk/f34ZX8UTykN68FwrqAA==} - engines: {node: '>= 0.6'} - string_decoder@1.3.0: resolution: {integrity: sha512-hkRX8U1WjJFd8LsDJ2yQ/wWWxaopEsABU1XfkM8A+j0+85JAGppt16cr1Whg6KIbb4okU6Mql6BOj+uup/wKeA==} - toidentifier@1.0.0: - resolution: {integrity: sha512-yaOH/Pk/VEhBWWTlhI+qXxDFXlejDGcQipMlyxda9nthulaxLZUNcUqFxokp0vcYnvteJln5FNQDRrxj3YcbVw==} - engines: {node: '>=0.6'} - tr46@0.0.3: resolution: {integrity: sha512-N3WMsuqV66lT30CrXNbEjx4GEwlow3v6rr4mCcv6prnfwhS01rkgyFdjPNBYd9br7LpXV1+Emh01fHnq2Gdgrw==} @@ -277,112 +299,93 @@ packages: snapshots: - '@near-js/accounts@1.2.2': + '@near-js/accounts@2.0.1(94f60b238a57a2159112ee1ca73e0c5d)': dependencies: - '@near-js/crypto': 1.3.0 - '@near-js/providers': 0.2.3 - '@near-js/signers': 0.1.5 - '@near-js/transactions': 1.2.3 - '@near-js/types': 0.2.1 - '@near-js/utils': 0.3.0 + '@near-js/crypto': 2.0.1(@near-js/types@2.0.1)(@near-js/utils@2.0.1(@near-js/types@2.0.1)) + '@near-js/providers': 2.0.1(@near-js/crypto@2.0.1(@near-js/types@2.0.1)(@near-js/utils@2.0.1(@near-js/types@2.0.1)))(@near-js/transactions@2.0.1(@near-js/crypto@2.0.1(@near-js/types@2.0.1)(@near-js/utils@2.0.1(@near-js/types@2.0.1)))(@near-js/types@2.0.1)(@near-js/utils@2.0.1(@near-js/types@2.0.1)))(@near-js/types@2.0.1)(@near-js/utils@2.0.1(@near-js/types@2.0.1)) + '@near-js/signers': 2.0.1(@near-js/crypto@2.0.1(@near-js/types@2.0.1)(@near-js/utils@2.0.1(@near-js/types@2.0.1)))(@near-js/keystores@2.0.1(@near-js/crypto@2.0.1(@near-js/types@2.0.1)(@near-js/utils@2.0.1(@near-js/types@2.0.1)))(@near-js/types@2.0.1))(@near-js/transactions@2.0.1(@near-js/crypto@2.0.1(@near-js/types@2.0.1)(@near-js/utils@2.0.1(@near-js/types@2.0.1)))(@near-js/types@2.0.1)(@near-js/utils@2.0.1(@near-js/types@2.0.1))) + '@near-js/tokens': 2.0.1 + '@near-js/transactions': 2.0.1(@near-js/crypto@2.0.1(@near-js/types@2.0.1)(@near-js/utils@2.0.1(@near-js/types@2.0.1)))(@near-js/types@2.0.1)(@near-js/utils@2.0.1(@near-js/types@2.0.1)) + '@near-js/types': 2.0.1 + '@near-js/utils': 2.0.1(@near-js/types@2.0.1) + '@noble/hashes': 1.7.1 borsh: 1.0.0 depd: 2.0.0 is-my-json-valid: 2.20.6 lru_map: 0.4.1 - near-abi: 0.1.1 - transitivePeerDependencies: - - encoding + near-abi: 0.2.0 - '@near-js/crypto@1.3.0': + '@near-js/crypto@2.0.1(@near-js/types@2.0.1)(@near-js/utils@2.0.1(@near-js/types@2.0.1))': dependencies: - '@near-js/types': 0.2.1 - '@near-js/utils': 0.3.0 - '@noble/curves': 1.2.0 + '@near-js/types': 2.0.1 + '@near-js/utils': 2.0.1(@near-js/types@2.0.1) + '@noble/curves': 1.8.1 borsh: 1.0.0 randombytes: 2.1.0 - secp256k1: 5.0.0 - - '@near-js/keystores-browser@0.1.0': - dependencies: - '@near-js/crypto': 1.3.0 - '@near-js/keystores': 0.1.0 + secp256k1: 5.0.1 - '@near-js/keystores-node@0.0.13': + '@near-js/keystores-node@2.0.1(@near-js/crypto@2.0.1(@near-js/types@2.0.1)(@near-js/utils@2.0.1(@near-js/types@2.0.1)))(@near-js/keystores@2.0.1(@near-js/crypto@2.0.1(@near-js/types@2.0.1)(@near-js/utils@2.0.1(@near-js/types@2.0.1)))(@near-js/types@2.0.1))': dependencies: - '@near-js/crypto': 1.3.0 - '@near-js/keystores': 0.1.0 + '@near-js/crypto': 2.0.1(@near-js/types@2.0.1)(@near-js/utils@2.0.1(@near-js/types@2.0.1)) + '@near-js/keystores': 2.0.1(@near-js/crypto@2.0.1(@near-js/types@2.0.1)(@near-js/utils@2.0.1(@near-js/types@2.0.1)))(@near-js/types@2.0.1) - '@near-js/keystores@0.1.0': + '@near-js/keystores@2.0.1(@near-js/crypto@2.0.1(@near-js/types@2.0.1)(@near-js/utils@2.0.1(@near-js/types@2.0.1)))(@near-js/types@2.0.1)': dependencies: - '@near-js/crypto': 1.3.0 - '@near-js/types': 0.2.1 + '@near-js/crypto': 2.0.1(@near-js/types@2.0.1)(@near-js/utils@2.0.1(@near-js/types@2.0.1)) + '@near-js/types': 2.0.1 - '@near-js/providers@0.2.3': + '@near-js/providers@2.0.1(@near-js/crypto@2.0.1(@near-js/types@2.0.1)(@near-js/utils@2.0.1(@near-js/types@2.0.1)))(@near-js/transactions@2.0.1(@near-js/crypto@2.0.1(@near-js/types@2.0.1)(@near-js/utils@2.0.1(@near-js/types@2.0.1)))(@near-js/types@2.0.1)(@near-js/utils@2.0.1(@near-js/types@2.0.1)))(@near-js/types@2.0.1)(@near-js/utils@2.0.1(@near-js/types@2.0.1))': dependencies: - '@near-js/transactions': 1.2.3 - '@near-js/types': 0.2.1 - '@near-js/utils': 0.3.0 + '@near-js/crypto': 2.0.1(@near-js/types@2.0.1)(@near-js/utils@2.0.1(@near-js/types@2.0.1)) + '@near-js/transactions': 2.0.1(@near-js/crypto@2.0.1(@near-js/types@2.0.1)(@near-js/utils@2.0.1(@near-js/types@2.0.1)))(@near-js/types@2.0.1)(@near-js/utils@2.0.1(@near-js/types@2.0.1)) + '@near-js/types': 2.0.1 + '@near-js/utils': 2.0.1(@near-js/types@2.0.1) borsh: 1.0.0 - http-errors: 1.7.2 + exponential-backoff: 3.1.2 optionalDependencies: node-fetch: 2.6.7 transitivePeerDependencies: - encoding - '@near-js/signers@0.1.5': + '@near-js/signers@2.0.1(@near-js/crypto@2.0.1(@near-js/types@2.0.1)(@near-js/utils@2.0.1(@near-js/types@2.0.1)))(@near-js/keystores@2.0.1(@near-js/crypto@2.0.1(@near-js/types@2.0.1)(@near-js/utils@2.0.1(@near-js/types@2.0.1)))(@near-js/types@2.0.1))(@near-js/transactions@2.0.1(@near-js/crypto@2.0.1(@near-js/types@2.0.1)(@near-js/utils@2.0.1(@near-js/types@2.0.1)))(@near-js/types@2.0.1)(@near-js/utils@2.0.1(@near-js/types@2.0.1)))': dependencies: - '@near-js/crypto': 1.3.0 - '@near-js/keystores': 0.1.0 - '@noble/hashes': 1.3.3 + '@near-js/crypto': 2.0.1(@near-js/types@2.0.1)(@near-js/utils@2.0.1(@near-js/types@2.0.1)) + '@near-js/keystores': 2.0.1(@near-js/crypto@2.0.1(@near-js/types@2.0.1)(@near-js/utils@2.0.1(@near-js/types@2.0.1)))(@near-js/types@2.0.1) + '@near-js/transactions': 2.0.1(@near-js/crypto@2.0.1(@near-js/types@2.0.1)(@near-js/utils@2.0.1(@near-js/types@2.0.1)))(@near-js/types@2.0.1)(@near-js/utils@2.0.1(@near-js/types@2.0.1)) + '@noble/hashes': 1.7.1 + borsh: 1.0.0 + + '@near-js/tokens@2.0.1': {} - '@near-js/transactions@1.2.3': + '@near-js/transactions@2.0.1(@near-js/crypto@2.0.1(@near-js/types@2.0.1)(@near-js/utils@2.0.1(@near-js/types@2.0.1)))(@near-js/types@2.0.1)(@near-js/utils@2.0.1(@near-js/types@2.0.1))': dependencies: - '@near-js/crypto': 1.3.0 - '@near-js/signers': 0.1.5 - '@near-js/types': 0.2.1 - '@near-js/utils': 0.3.0 - '@noble/hashes': 1.3.3 + '@near-js/crypto': 2.0.1(@near-js/types@2.0.1)(@near-js/utils@2.0.1(@near-js/types@2.0.1)) + '@near-js/types': 2.0.1 + '@near-js/utils': 2.0.1(@near-js/types@2.0.1) + '@noble/hashes': 1.7.1 borsh: 1.0.0 - '@near-js/types@0.2.1': {} + '@near-js/types@2.0.1': {} - '@near-js/utils@0.3.0': + '@near-js/utils@2.0.1(@near-js/types@2.0.1)': dependencies: - '@near-js/types': 0.2.1 - bs58: 4.0.0 + '@near-js/types': 2.0.1 + '@scure/base': 1.2.5 depd: 2.0.0 mustache: 4.0.0 - '@near-js/wallet-account@1.2.3': + '@noble/curves@1.8.1': dependencies: - '@near-js/accounts': 1.2.2 - '@near-js/crypto': 1.3.0 - '@near-js/keystores': 0.1.0 - '@near-js/providers': 0.2.3 - '@near-js/signers': 0.1.5 - '@near-js/transactions': 1.2.3 - '@near-js/types': 0.2.1 - '@near-js/utils': 0.3.0 - borsh: 1.0.0 - transitivePeerDependencies: - - encoding + '@noble/hashes': 1.7.1 - '@noble/curves@1.2.0': - dependencies: - '@noble/hashes': 1.3.2 + '@noble/hashes@1.7.1': {} - '@noble/hashes@1.3.2': {} - - '@noble/hashes@1.3.3': {} + '@scure/base@1.2.5': {} '@types/json-schema@7.0.15': {} '@types/node@11.11.6': {} - base-x@2.0.6: - dependencies: - safe-buffer: 5.2.1 - base-x@3.0.10: dependencies: safe-buffer: 5.2.1 @@ -399,15 +402,13 @@ snapshots: pbkdf2: 3.1.2 randombytes: 2.1.0 - bn.js@4.12.1: {} + bn.js@4.12.2: {} borsh@1.0.0: {} - brorand@1.1.0: {} + borsh@2.0.0: {} - bs58@4.0.0: - dependencies: - base-x: 2.0.6 + brorand@1.1.0: {} bs58@4.0.1: dependencies: @@ -435,15 +436,13 @@ snapshots: safe-buffer: 5.2.1 sha.js: 2.4.11 - depd@1.1.2: {} - depd@2.0.0: {} dotenv@16.4.7: {} elliptic@6.6.1: dependencies: - bn.js: 4.12.1 + bn.js: 4.12.2 brorand: 1.1.0 hash.js: 1.1.7 hmac-drbg: 1.0.1 @@ -451,6 +450,8 @@ snapshots: minimalistic-assert: 1.0.1 minimalistic-crypto-utils: 1.0.1 + exponential-backoff@3.1.2: {} + generate-function@2.3.1: dependencies: is-property: 1.0.2 @@ -476,16 +477,6 @@ snapshots: minimalistic-assert: 1.0.1 minimalistic-crypto-utils: 1.0.1 - http-errors@1.7.2: - dependencies: - depd: 1.1.2 - inherits: 2.0.3 - setprototypeof: 1.1.1 - statuses: 1.5.0 - toidentifier: 1.0.0 - - inherits@2.0.3: {} - inherits@2.0.4: {} is-my-ip-valid@1.0.1: {} @@ -518,32 +509,10 @@ snapshots: mustache@4.0.0: {} - near-abi@0.1.1: + near-abi@0.2.0: dependencies: '@types/json-schema': 7.0.15 - near-api-js@4.0.4: - dependencies: - '@near-js/accounts': 1.2.2 - '@near-js/crypto': 1.3.0 - '@near-js/keystores': 0.1.0 - '@near-js/keystores-browser': 0.1.0 - '@near-js/keystores-node': 0.0.13 - '@near-js/providers': 0.2.3 - '@near-js/signers': 0.1.5 - '@near-js/transactions': 1.2.3 - '@near-js/types': 0.2.1 - '@near-js/utils': 0.3.0 - '@near-js/wallet-account': 1.2.3 - '@noble/curves': 1.2.0 - borsh: 1.0.0 - depd: 2.0.0 - http-errors: 1.7.2 - near-abi: 0.1.1 - node-fetch: 2.6.7 - transitivePeerDependencies: - - encoding - near-hd-key@1.2.1: dependencies: bip39: 3.0.2 @@ -562,6 +531,7 @@ snapshots: node-fetch@2.6.7: dependencies: whatwg-url: 5.0.0 + optional: true node-gyp-build@4.8.4: {} @@ -590,38 +560,35 @@ snapshots: safe-buffer@5.2.1: {} - secp256k1@5.0.0: + secp256k1@5.0.1: dependencies: elliptic: 6.6.1 node-addon-api: 5.1.0 node-gyp-build: 4.8.4 - setprototypeof@1.1.1: {} - sha.js@2.4.11: dependencies: inherits: 2.0.4 safe-buffer: 5.2.1 - statuses@1.5.0: {} - string_decoder@1.3.0: dependencies: safe-buffer: 5.2.1 - toidentifier@1.0.0: {} - - tr46@0.0.3: {} + tr46@0.0.3: + optional: true tweetnacl@1.0.3: {} util-deprecate@1.0.2: {} - webidl-conversions@3.0.1: {} + webidl-conversions@3.0.1: + optional: true whatwg-url@5.0.0: dependencies: tr46: 0.0.3 webidl-conversions: 3.0.1 + optional: true xtend@4.0.2: {}