From 64bcacb2feac82a3956d6c134003f658b280a480 Mon Sep 17 00:00:00 2001 From: Jon C Date: Wed, 16 Oct 2024 14:49:06 +0200 Subject: [PATCH] js-v1: Add runnable example #### Problem As mentioned at #12, it's unclear how to run the example. #### Summary of changes Add a corresponding package.json, making it possible to simply install dependencies, build, and run the example. --- js-v1/examples/README.md | 24 ++++++++++++++++ js-v1/examples/example.ts | 8 ------ js-v1/examples/package.json | 57 +++++++++++++++++++++++++++++++++++++ js-v1/examples/src/index.ts | 10 +++++++ 4 files changed, 91 insertions(+), 8 deletions(-) create mode 100644 js-v1/examples/README.md delete mode 100644 js-v1/examples/example.ts create mode 100644 js-v1/examples/package.json create mode 100644 js-v1/examples/src/index.ts diff --git a/js-v1/examples/README.md b/js-v1/examples/README.md new file mode 100644 index 0000000..60f6015 --- /dev/null +++ b/js-v1/examples/README.md @@ -0,0 +1,24 @@ +# Examples + +There is an example using `getStakeActivation` against a live testnet stake +account. + +## Getting started + +* Install the dependencies + +```console +pnpm install +``` + +* Build the example + +```console +pnpm build +``` + +* Run it + +```console +node dist/src/index.js +``` diff --git a/js-v1/examples/example.ts b/js-v1/examples/example.ts deleted file mode 100644 index 0dba8f3..0000000 --- a/js-v1/examples/example.ts +++ /dev/null @@ -1,8 +0,0 @@ -import { getStakeActivation } from 'solana-rpc-get-stake-activation'; -import { PublicKey } from "@solana/web3.js"; -import { Connection } from '@solana/web3.js'; - -const connection = new Connection('https://api.testnet.solana.com'); -let stake = new PublicKey('25R5p1Qoe4BWW4ru7MQSNxxAzdiPN7zAunpCuF8q5iTz'); -let status = await getStakeActivation(connection, stake); -console.log(status); \ No newline at end of file diff --git a/js-v1/examples/package.json b/js-v1/examples/package.json new file mode 100644 index 0000000..b97e831 --- /dev/null +++ b/js-v1/examples/package.json @@ -0,0 +1,57 @@ +{ + "name": "@anza-xyz/solana-rpc-get-stake-activation-example", + "version": "1.0.0", + "description": "Example using getStakeActivation", + "sideEffects": false, + "module": "./dist/src/index.mjs", + "main": "./dist/src/index.js", + "types": "./dist/types/index.d.ts", + "type": "commonjs", + "keywords": [ + "blockchain", + "solana", + "rpc", + "web3" + ], + "author": "Anza Maintainers ", + "license": "Apache-2.0", + "packageManager": "pnpm@9.1.0", + "repository": { + "type": "git", + "url": "https://github.com/anza-xyz/solana-rpc-client-extensions" + }, + "bugs": { + "url": "https://github.com/anza-xyz/solana-rpc-client-extensions/issues" + }, + "publishConfig": { + "access": "private" + }, + "exports": { + ".": { + "types": "./dist/types/index.d.ts", + "import": "./dist/src/index.mjs", + "require": "./dist/src/index.js" + } + }, + "files": [ + "./dist/src", + "./dist/types" + ], + "scripts": { + "build": "rimraf dist && tsup && tsc", + "lint": "eslint --ext js,ts,tsx src", + "lint:fix": "eslint --fix --ext js,ts,tsx src", + "format": "prettier --check src", + "format:fix": "prettier --write src", + "prepublishOnly": "pnpm build" + }, + "dependencies": { + "@anza-xyz/solana-rpc-get-stake-activation": "1.0.1", + "@solana/web3.js": "1.95" + }, + "devDependencies": { + "rimraf": "^5.0.5", + "tsup": "^8.1.2", + "typescript": "^5.5.3" + } +} diff --git a/js-v1/examples/src/index.ts b/js-v1/examples/src/index.ts new file mode 100644 index 0000000..4b9f853 --- /dev/null +++ b/js-v1/examples/src/index.ts @@ -0,0 +1,10 @@ +import { getStakeActivation } from '@anza-xyz/solana-rpc-get-stake-activation'; +import { PublicKey } from '@solana/web3.js'; +import { Connection } from '@solana/web3.js'; + +(async () => { + const connection = new Connection('https://api.testnet.solana.com'); + let stake = new PublicKey('25R5p1Qoe4BWW4ru7MQSNxxAzdiPN7zAunpCuF8q5iTz'); + let status = await getStakeActivation(connection, stake); + console.log(status); +})();