diff --git a/.eslintrc.js b/.eslintrc.js index e44d7d1..1088b61 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -2,14 +2,24 @@ module.exports = { env: { browser: true, amd: true, - node: true, // Add this line to specify the Node.js environment + node: true, }, + parser: '@typescript-eslint/parser', // Specify the TypeScript parser parserOptions: { ecmaVersion: 6, + sourceType: 'module', // Ensure this is set for ECMAScript modules }, - extends: 'eslint:recommended', + extends: [ + 'eslint:recommended', + 'plugin:@typescript-eslint/eslint-recommended', + 'plugin:@typescript-eslint/recommended', + ], + plugins: [ + '@typescript-eslint', // Include the TypeScript plugin + ], rules: { 'no-console': 'off', + '@typescript-eslint/no-var-requires': 'off', indent: ['error', 'tab'], 'linebreak-style': ['error', 'windows'], quotes: ['error', 'single'], diff --git a/package-lock.json b/package-lock.json index b9fde71..ae65d2c 100644 --- a/package-lock.json +++ b/package-lock.json @@ -20,8 +20,8 @@ "dotenv": "^16.0.3" }, "devDependencies": { - "@typescript-eslint/eslint-plugin": "^7.3.1", - "@typescript-eslint/parser": "^7.3.1", + "@typescript-eslint/eslint-plugin": "^7.4.0", + "@typescript-eslint/parser": "^7.4.0", "eslint": "^8.57.0", "husky": "^8.0.3", "lint-staged": "^15.2.2", @@ -1959,16 +1959,16 @@ } }, "node_modules/@typescript-eslint/eslint-plugin": { - "version": "7.3.1", - "resolved": "https://registry.npmjs.org/@typescript-eslint/eslint-plugin/-/eslint-plugin-7.3.1.tgz", - "integrity": "sha512-STEDMVQGww5lhCuNXVSQfbfuNII5E08QWkvAw5Qwf+bj2WT+JkG1uc+5/vXA3AOYMDHVOSpL+9rcbEUiHIm2dw==", + "version": "7.4.0", + "resolved": "https://registry.npmjs.org/@typescript-eslint/eslint-plugin/-/eslint-plugin-7.4.0.tgz", + "integrity": "sha512-yHMQ/oFaM7HZdVrVm/M2WHaNPgyuJH4WelkSVEWSSsir34kxW2kDJCxlXRhhGWEsMN0WAW/vLpKfKVcm8k+MPw==", "dev": true, "dependencies": { "@eslint-community/regexpp": "^4.5.1", - "@typescript-eslint/scope-manager": "7.3.1", - "@typescript-eslint/type-utils": "7.3.1", - "@typescript-eslint/utils": "7.3.1", - "@typescript-eslint/visitor-keys": "7.3.1", + "@typescript-eslint/scope-manager": "7.4.0", + "@typescript-eslint/type-utils": "7.4.0", + "@typescript-eslint/utils": "7.4.0", + "@typescript-eslint/visitor-keys": "7.4.0", "debug": "^4.3.4", "graphemer": "^1.4.0", "ignore": "^5.2.4", @@ -1994,15 +1994,15 @@ } }, "node_modules/@typescript-eslint/parser": { - "version": "7.3.1", - "resolved": "https://registry.npmjs.org/@typescript-eslint/parser/-/parser-7.3.1.tgz", - "integrity": "sha512-Rq49+pq7viTRCH48XAbTA+wdLRrB/3sRq4Lpk0oGDm0VmnjBrAOVXH/Laalmwsv2VpekiEfVFwJYVk6/e8uvQw==", + "version": "7.4.0", + "resolved": "https://registry.npmjs.org/@typescript-eslint/parser/-/parser-7.4.0.tgz", + "integrity": "sha512-ZvKHxHLusweEUVwrGRXXUVzFgnWhigo4JurEj0dGF1tbcGh6buL+ejDdjxOQxv6ytcY1uhun1p2sm8iWStlgLQ==", "dev": true, "dependencies": { - "@typescript-eslint/scope-manager": "7.3.1", - "@typescript-eslint/types": "7.3.1", - "@typescript-eslint/typescript-estree": "7.3.1", - "@typescript-eslint/visitor-keys": "7.3.1", + "@typescript-eslint/scope-manager": "7.4.0", + "@typescript-eslint/types": "7.4.0", + "@typescript-eslint/typescript-estree": "7.4.0", + "@typescript-eslint/visitor-keys": "7.4.0", "debug": "^4.3.4" }, "engines": { @@ -2022,13 +2022,13 @@ } }, "node_modules/@typescript-eslint/scope-manager": { - "version": "7.3.1", - "resolved": "https://registry.npmjs.org/@typescript-eslint/scope-manager/-/scope-manager-7.3.1.tgz", - "integrity": "sha512-fVS6fPxldsKY2nFvyT7IP78UO1/I2huG+AYu5AMjCT9wtl6JFiDnsv4uad4jQ0GTFzcUV5HShVeN96/17bTBag==", + "version": "7.4.0", + "resolved": "https://registry.npmjs.org/@typescript-eslint/scope-manager/-/scope-manager-7.4.0.tgz", + "integrity": "sha512-68VqENG5HK27ypafqLVs8qO+RkNc7TezCduYrx8YJpXq2QGZ30vmNZGJJJC48+MVn4G2dCV8m5ZTVnzRexTVtw==", "dev": true, "dependencies": { - "@typescript-eslint/types": "7.3.1", - "@typescript-eslint/visitor-keys": "7.3.1" + "@typescript-eslint/types": "7.4.0", + "@typescript-eslint/visitor-keys": "7.4.0" }, "engines": { "node": "^18.18.0 || >=20.0.0" @@ -2039,13 +2039,13 @@ } }, "node_modules/@typescript-eslint/type-utils": { - "version": "7.3.1", - "resolved": "https://registry.npmjs.org/@typescript-eslint/type-utils/-/type-utils-7.3.1.tgz", - "integrity": "sha512-iFhaysxFsMDQlzJn+vr3OrxN8NmdQkHks4WaqD4QBnt5hsq234wcYdyQ9uquzJJIDAj5W4wQne3yEsYA6OmXGw==", + "version": "7.4.0", + "resolved": "https://registry.npmjs.org/@typescript-eslint/type-utils/-/type-utils-7.4.0.tgz", + "integrity": "sha512-247ETeHgr9WTRMqHbbQdzwzhuyaJ8dPTuyuUEMANqzMRB1rj/9qFIuIXK7l0FX9i9FXbHeBQl/4uz6mYuCE7Aw==", "dev": true, "dependencies": { - "@typescript-eslint/typescript-estree": "7.3.1", - "@typescript-eslint/utils": "7.3.1", + "@typescript-eslint/typescript-estree": "7.4.0", + "@typescript-eslint/utils": "7.4.0", "debug": "^4.3.4", "ts-api-utils": "^1.0.1" }, @@ -2066,9 +2066,9 @@ } }, "node_modules/@typescript-eslint/types": { - "version": "7.3.1", - "resolved": "https://registry.npmjs.org/@typescript-eslint/types/-/types-7.3.1.tgz", - "integrity": "sha512-2tUf3uWggBDl4S4183nivWQ2HqceOZh1U4hhu4p1tPiIJoRRXrab7Y+Y0p+dozYwZVvLPRI6r5wKe9kToF9FIw==", + "version": "7.4.0", + "resolved": "https://registry.npmjs.org/@typescript-eslint/types/-/types-7.4.0.tgz", + "integrity": "sha512-mjQopsbffzJskos5B4HmbsadSJQWaRK0UxqQ7GuNA9Ga4bEKeiO6b2DnB6cM6bpc8lemaPseh0H9B/wyg+J7rw==", "dev": true, "engines": { "node": "^18.18.0 || >=20.0.0" @@ -2079,13 +2079,13 @@ } }, "node_modules/@typescript-eslint/typescript-estree": { - "version": "7.3.1", - "resolved": "https://registry.npmjs.org/@typescript-eslint/typescript-estree/-/typescript-estree-7.3.1.tgz", - "integrity": "sha512-tLpuqM46LVkduWP7JO7yVoWshpJuJzxDOPYIVWUUZbW+4dBpgGeUdl/fQkhuV0A8eGnphYw3pp8d2EnvPOfxmQ==", + "version": "7.4.0", + "resolved": "https://registry.npmjs.org/@typescript-eslint/typescript-estree/-/typescript-estree-7.4.0.tgz", + "integrity": "sha512-A99j5AYoME/UBQ1ucEbbMEmGkN7SE0BvZFreSnTd1luq7yulcHdyGamZKizU7canpGDWGJ+Q6ZA9SyQobipePg==", "dev": true, "dependencies": { - "@typescript-eslint/types": "7.3.1", - "@typescript-eslint/visitor-keys": "7.3.1", + "@typescript-eslint/types": "7.4.0", + "@typescript-eslint/visitor-keys": "7.4.0", "debug": "^4.3.4", "globby": "^11.1.0", "is-glob": "^4.0.3", @@ -2131,17 +2131,17 @@ } }, "node_modules/@typescript-eslint/utils": { - "version": "7.3.1", - "resolved": "https://registry.npmjs.org/@typescript-eslint/utils/-/utils-7.3.1.tgz", - "integrity": "sha512-jIERm/6bYQ9HkynYlNZvXpzmXWZGhMbrOvq3jJzOSOlKXsVjrrolzWBjDW6/TvT5Q3WqaN4EkmcfdQwi9tDjBQ==", + "version": "7.4.0", + "resolved": "https://registry.npmjs.org/@typescript-eslint/utils/-/utils-7.4.0.tgz", + "integrity": "sha512-NQt9QLM4Tt8qrlBVY9lkMYzfYtNz8/6qwZg8pI3cMGlPnj6mOpRxxAm7BMJN9K0AiY+1BwJ5lVC650YJqYOuNg==", "dev": true, "dependencies": { "@eslint-community/eslint-utils": "^4.4.0", "@types/json-schema": "^7.0.12", "@types/semver": "^7.5.0", - "@typescript-eslint/scope-manager": "7.3.1", - "@typescript-eslint/types": "7.3.1", - "@typescript-eslint/typescript-estree": "7.3.1", + "@typescript-eslint/scope-manager": "7.4.0", + "@typescript-eslint/types": "7.4.0", + "@typescript-eslint/typescript-estree": "7.4.0", "semver": "^7.5.4" }, "engines": { @@ -2156,12 +2156,12 @@ } }, "node_modules/@typescript-eslint/visitor-keys": { - "version": "7.3.1", - "resolved": "https://registry.npmjs.org/@typescript-eslint/visitor-keys/-/visitor-keys-7.3.1.tgz", - "integrity": "sha512-9RMXwQF8knsZvfv9tdi+4D/j7dMG28X/wMJ8Jj6eOHyHWwDW4ngQJcqEczSsqIKKjFiLFr40Mnr7a5ulDD3vmw==", + "version": "7.4.0", + "resolved": "https://registry.npmjs.org/@typescript-eslint/visitor-keys/-/visitor-keys-7.4.0.tgz", + "integrity": "sha512-0zkC7YM0iX5Y41homUUeW1CHtZR01K3ybjM1l6QczoMuay0XKtrb93kv95AxUGwdjGr64nNqnOCwmEl616N8CA==", "dev": true, "dependencies": { - "@typescript-eslint/types": "7.3.1", + "@typescript-eslint/types": "7.4.0", "eslint-visitor-keys": "^3.4.1" }, "engines": { diff --git a/package.json b/package.json index 634e9e1..857c3ad 100644 --- a/package.json +++ b/package.json @@ -29,8 +29,8 @@ ] }, "devDependencies": { - "@typescript-eslint/eslint-plugin": "^7.3.1", - "@typescript-eslint/parser": "^7.3.1", + "@typescript-eslint/eslint-plugin": "^7.4.0", + "@typescript-eslint/parser": "^7.4.0", "eslint": "^8.57.0", "husky": "^8.0.3", "lint-staged": "^15.2.2", @@ -39,4 +39,4 @@ "tsconfig-paths": "^4.1.2", "typescript": "^4.8.4" } -} \ No newline at end of file +} diff --git a/scripts/account.ts b/scripts/account.ts new file mode 100644 index 0000000..4186159 --- /dev/null +++ b/scripts/account.ts @@ -0,0 +1,7 @@ +import { PublicKey } from '@solana/web3.js'; +import { getAdminAccount } from '../lib/helpers'; +require('dotenv').config(); + +const adminAccountPrivKey = process.env.ADMIN_PRIV_KEY; +const adminAccount = getAdminAccount(adminAccountPrivKey); +console.log(`Admin public key: ${new PublicKey(adminAccount.publicKey)}`); diff --git a/scripts/transferTokens.ts b/scripts/transferTokens.ts index 1dbb049..e913eb0 100644 --- a/scripts/transferTokens.ts +++ b/scripts/transferTokens.ts @@ -1,68 +1,74 @@ -//** NOTE: THIS SCRIPT HELPS TO TRANSFER SOLANA SPL TOKEN FROM ONE ACCOUNT TO ANOTHER */ - -const { Connection, PublicKey, Keypair } = require('@solana/web3.js'); -const { getOrCreateAssociatedTokenAccount, transfer } = require('@solana/spl-token'); -import {connection} from '../lib/vars'; -import { getAdminAccount,loadPublicKeysFromFile } from '../lib/helpers'; - - - - // load the stored PublicKeys for ease of use - let localKeys = loadPublicKeysFromFile(); - - // ensure the desired script was already run - if (!localKeys?.tokenMint) - console.warn("No local keys were found. Please run '3.createTokenWithMetadata.ts'"); - - -// Replace these with your actual values -const DESTINATION_WALLET = '4tEfs9QjdCiZBEuZfSbshnYQZzenDpYP4GzrSiKHjiqJ'; -const MINT_ADDRESS = new PublicKey(localKeys.tokenMint); // Replace with your token's mint address -const TRANSFER_AMOUNT = 26666666.64; // Amount of tokens to transfer - -// Initialize connection - - -// Sender's wallet keypair -const adminAccountPrivKey = process.env.ADMIN_PRIV_KEY; -const adminAccount =getAdminAccount(adminAccountPrivKey); - - -// Receiver's public key -const receiverPubkey = new PublicKey(DESTINATION_WALLET); - -// Mint address -const mintAddress = new PublicKey(MINT_ADDRESS); - -(async () => { - try { - // Get or create associated token accounts for sender and receiver - const senderTokenAccount = await getOrCreateAssociatedTokenAccount( - connection, - adminAccount, - mintAddress, - adminAccount.publicKey - ); - - const receiverTokenAccount = await getOrCreateAssociatedTokenAccount( - connection, - adminAccount, - mintAddress, - receiverPubkey - ); - - // Transfer tokens - const transferSignature = await transfer( - connection, - adminAccount, - senderTokenAccount.address, - receiverTokenAccount.address, - adminAccount.publicKey, - TRANSFER_AMOUNT * 1000000 // Adjust for token decimals - ); - - console.log(`Transfer successful. Signature: ${transferSignature}`); - } catch (error) { - console.error("Error transferring tokens:", error); - } -})(); \ No newline at end of file +//** NOTE: THIS SCRIPT HELPS TO TRANSFER SOLANA SPL TOKEN FROM ONE ACCOUNT TO ANOTHER */ + +const { PublicKey } = require('@solana/web3.js'); +const { + getOrCreateAssociatedTokenAccount, + transfer, +} = require('@solana/spl-token'); +import { connection } from '../lib/vars'; +import { + getAdminAccount, + loadPublicKeysFromFile, + explorerURL, +} from '../lib/helpers'; + +// load the stored PublicKeys for ease of use +const localKeys = loadPublicKeysFromFile(); + +// ensure the desired script was already run +if (!localKeys?.tokenMint) + console.warn( + 'No local keys were found. Please run \'3.createTokenWithMetadata.ts\'', + ); + +// Replace these with your actual values +const DESTINATION_WALLET = '4tEfs9QjdCiZBEuZfSbshnYQZzenDpYP4GzrSiKHjiqJ'; +const MINT_ADDRESS = new PublicKey(localKeys.tokenMint); // Replace with your token's mint address +const TRANSFER_AMOUNT = 26666666640; // Amount of tokens to transfer + +// Initialize connection + +// Sender's wallet keypair +const adminAccountPrivKey = process.env.ADMIN_PRIV_KEY; +const adminAccount = getAdminAccount(adminAccountPrivKey); + +// Receiver's public key +const receiverPubkey = new PublicKey(DESTINATION_WALLET); + +// Mint address +const mintAddress = new PublicKey(MINT_ADDRESS); + +(async () => { + try { + // Get or create associated token accounts for sender and receiver + const senderTokenAccount = await getOrCreateAssociatedTokenAccount( + connection, + adminAccount, + mintAddress, + adminAccount.publicKey, + ); + + const receiverTokenAccount = await getOrCreateAssociatedTokenAccount( + connection, + adminAccount, + mintAddress, + receiverPubkey, + ); + + // Transfer tokens + const transferSignature = await transfer( + connection, + adminAccount, + senderTokenAccount.address, + receiverTokenAccount.address, + adminAccount.publicKey, + TRANSFER_AMOUNT, // Adjust for token decimals + ); + + console.log( + `Transfer successful. Signature: ${explorerURL({ txSignature: transferSignature })}`, + ); + } catch (error) { + console.error('Error transferring tokens:', error); + } +})();