Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@nfteyez/sol-rayz

Package Overview
Dependencies
Maintainers
2
Versions
14
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@nfteyez/sol-rayz - npm Package Compare versions

Comparing version 0.8.2 to 0.9.1

dist/resolveToWalletAddress.d.ts

13

dist/getParsedNftAccountsByOwner.d.ts

@@ -20,8 +20,2 @@ import { Connection } from "@solana/web3.js";

/**
* TODO: Add description within README and link here
* Default is false - slow method
* true - is fast method
*/
strictNftStandard?: boolean;
/**
* Convert all PublicKey objects to string versions.

@@ -36,4 +30,9 @@ * Default is true

sort?: boolean;
/**
* Limit response by this number
* by default response limited by 5000 NFTs
*/
limit?: number;
};
export declare const getParsedNftAccountsByOwner: ({ publicAddress, connection, sanitize, strictNftStandard, stringifyPubKeys, sort, }: Options) => Promise<{
export declare const getParsedNftAccountsByOwner: ({ publicAddress, connection, sanitize, stringifyPubKeys, sort, limit, }: Options) => Promise<{
mint: string;

@@ -40,0 +39,0 @@ updateAuthority: string;

@@ -64,5 +64,5 @@ "use strict";

var getParsedNftAccountsByOwner = function (_a) {
var publicAddress = _a.publicAddress, _b = _a.connection, connection = _b === void 0 ? (0, utils_1.createConnectionConfig)() : _b, _c = _a.sanitize, sanitize = _c === void 0 ? true : _c, _d = _a.strictNftStandard, strictNftStandard = _d === void 0 ? false : _d, _e = _a.stringifyPubKeys, stringifyPubKeys = _e === void 0 ? true : _e, _f = _a.sort, sort = _f === void 0 ? true : _f;
var publicAddress = _a.publicAddress, _b = _a.connection, connection = _b === void 0 ? (0, utils_1.createConnectionConfig)() : _b, _c = _a.sanitize, sanitize = _c === void 0 ? true : _c, _d = _a.stringifyPubKeys, stringifyPubKeys = _d === void 0 ? true : _d, _e = _a.sort, sort = _e === void 0 ? true : _e, _f = _a.limit, limit = _f === void 0 ? 5000 : _f;
return __awaiter(void 0, void 0, void 0, function () {
var isValidAddress, splAccounts, nftAccounts, acountsMetaAddressPromises, acountsMetaAddress, accountsRawMetaResponse, accountsRawMeta, accountsDecodedMeta, accountsFiltered, accountsSorted;
var isValidAddress, splAccounts, nftAccounts, accountsSlice, metadataAcountsAddressPromises, metadataAccounts, metaAccountsRawPromises, accountsRawMeta, accountsDecodedMeta, accountsFiltered, accountsSorted;
return __generator(this, function (_g) {

@@ -80,46 +80,27 @@ switch (_g.label) {

splAccounts = (_g.sent()).value;
nftAccounts = splAccounts.filter(function (_a) {
var _b, _c, _d, _e, _f, _g, _h, _j;
var account = _a.account;
var amount = (_e = (_d = (_c = (_b = account === null || account === void 0 ? void 0 : account.data) === null || _b === void 0 ? void 0 : _b.parsed) === null || _c === void 0 ? void 0 : _c.info) === null || _d === void 0 ? void 0 : _d.tokenAmount) === null || _e === void 0 ? void 0 : _e.uiAmount;
var decimals = (_j = (_h = (_g = (_f = account === null || account === void 0 ? void 0 : account.data) === null || _f === void 0 ? void 0 : _f.parsed) === null || _g === void 0 ? void 0 : _g.info) === null || _h === void 0 ? void 0 : _h.tokenAmount) === null || _j === void 0 ? void 0 : _j.decimals;
if (strictNftStandard) {
// Here is correct way to do it. it is described by Solana
// faster way, will filter out most unrelivant SPL-tokens
return decimals === 0 && amount >= 1;
}
// Weak method to find NFT tokens
// some older NFTs can be found only this way, like Solarians e.g.
return amount > 0;
nftAccounts = splAccounts
.filter(function (t) {
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k;
var amount = (_e = (_d = (_c = (_b = (_a = t.account) === null || _a === void 0 ? void 0 : _a.data) === null || _b === void 0 ? void 0 : _b.parsed) === null || _c === void 0 ? void 0 : _c.info) === null || _d === void 0 ? void 0 : _d.tokenAmount) === null || _e === void 0 ? void 0 : _e.uiAmount;
var decimals = (_k = (_j = (_h = (_g = (_f = t.account) === null || _f === void 0 ? void 0 : _f.data) === null || _g === void 0 ? void 0 : _g.parsed) === null || _h === void 0 ? void 0 : _h.info) === null || _j === void 0 ? void 0 : _j.tokenAmount) === null || _k === void 0 ? void 0 : _k.decimals;
return decimals === 0 && amount >= 1;
})
.map(function (t) {
var _a, _b, _c, _d;
var address = (_d = (_c = (_b = (_a = t.account) === null || _a === void 0 ? void 0 : _a.data) === null || _b === void 0 ? void 0 : _b.parsed) === null || _c === void 0 ? void 0 : _c.info) === null || _d === void 0 ? void 0 : _d.mint;
return new web3_js_1.PublicKey(address);
});
return [4 /*yield*/, Promise.allSettled(nftAccounts.map(function (_a) {
var _b, _c, _d;
var account = _a.account;
var address = (_d = (_c = (_b = account === null || account === void 0 ? void 0 : account.data) === null || _b === void 0 ? void 0 : _b.parsed) === null || _c === void 0 ? void 0 : _c.info) === null || _d === void 0 ? void 0 : _d.mint;
return address ? (0, utils_1.getSolanaMetadataAddress)(new web3_js_1.PublicKey(address)) : null;
}))];
accountsSlice = nftAccounts === null || nftAccounts === void 0 ? void 0 : nftAccounts.slice(0, limit);
return [4 /*yield*/, Promise.allSettled(accountsSlice.map(utils_1.getSolanaMetadataAddress))];
case 2:
acountsMetaAddressPromises = _g.sent();
acountsMetaAddress = acountsMetaAddressPromises
metadataAcountsAddressPromises = _g.sent();
metadataAccounts = metadataAcountsAddressPromises
.filter(onlySuccessfullPromises)
.map(function (p) { return p.value; });
return [4 /*yield*/, Promise.allSettled((0, lodash_chunk_1.default)(acountsMetaAddress, 99).map(function (chunk) { return __awaiter(void 0, void 0, void 0, function () {
var err_1;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
_a.trys.push([0, 2, , 3]);
return [4 /*yield*/, connection.getMultipleAccountsInfo(chunk)];
case 1: return [2 /*return*/, _a.sent()];
case 2:
err_1 = _a.sent();
console.log(err_1); // eslint-disable-line
return [2 /*return*/, false];
case 3: return [2 /*return*/];
}
});
}); }))];
return [4 /*yield*/, Promise.allSettled((0, lodash_chunk_1.default)(metadataAccounts, 99).map(function (chunk) {
return connection.getMultipleAccountsInfo(chunk);
}))];
case 3:
accountsRawMetaResponse = _g.sent();
accountsRawMeta = accountsRawMetaResponse
metaAccountsRawPromises = _g.sent();
accountsRawMeta = metaAccountsRawPromises
.filter(function (_a) {

@@ -130,2 +111,7 @@ var status = _a.status;

.flatMap(function (p) { return p.value; });
// There is no reason to continue processing
// if Mints doesn't have associated metadata account. just return []
if (!(accountsRawMeta === null || accountsRawMeta === void 0 ? void 0 : accountsRawMeta.length) || (accountsRawMeta === null || accountsRawMeta === void 0 ? void 0 : accountsRawMeta.length) === 0) {
return [2 /*return*/, []];
}
return [4 /*yield*/, Promise.allSettled(accountsRawMeta.map(function (accountInfo) { var _a; return (0, utils_1.decodeTokenMetadata)((_a = accountInfo) === null || _a === void 0 ? void 0 : _a.data); }))];

@@ -158,2 +144,3 @@ case 4:

};
// Convert all PublicKey to string
var publicKeyToString = function (tokenData) {

@@ -166,2 +153,5 @@ var _a, _b, _c, _d, _e, _f;

};
// Remove all empty space, new line, etc. symbols
// In some reason such symbols parsed back from Buffer looks weird
// like "\x0000" instead of usual spaces.
var sanitizeMetaStrings = function (metaString) {

@@ -172,2 +162,4 @@ return metaString.replace(/\0/g, "");

var onlySuccessfullPromises = function (result) { return result && result.status === "fulfilled"; };
// Remove any NFT Metadata Account which doesn't have uri field
// We can assume such NFTs are broken or invalid.
var onlyNftsWithMetadata = function (t) {

@@ -174,0 +166,0 @@ var _a, _b, _c;

export { getParsedNftAccountsByOwner } from "./getParsedNftAccountsByOwner";
export { getParsedNftAccountsByUpdateAuthority } from "./getParsedNftAccountsByUpdateAuthority";
export { getParsedAccountByMint } from "./getParsedAccountByMint";
export { resolveToWalletAddrress } from "./resolveToWalletAddrress";
export { resolveToWalletAddress } from "./resolveToWalletAddress";
export { isValidSolanaAddress, createConnectionConfig, getSolanaMetadataAddress, decodeTokenMetadata, } from "./utils";
export declare type Options = import("./getParsedNftAccountsByOwner").Options;
//# sourceMappingURL=index.d.ts.map
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.decodeTokenMetadata = exports.getSolanaMetadataAddress = exports.createConnectionConfig = exports.isValidSolanaAddress = exports.resolveToWalletAddrress = exports.getParsedAccountByMint = exports.getParsedNftAccountsByUpdateAuthority = exports.getParsedNftAccountsByOwner = void 0;
exports.decodeTokenMetadata = exports.getSolanaMetadataAddress = exports.createConnectionConfig = exports.isValidSolanaAddress = exports.resolveToWalletAddress = exports.getParsedAccountByMint = exports.getParsedNftAccountsByUpdateAuthority = exports.getParsedNftAccountsByOwner = void 0;
var getParsedNftAccountsByOwner_1 = require("./getParsedNftAccountsByOwner");

@@ -10,4 +10,4 @@ Object.defineProperty(exports, "getParsedNftAccountsByOwner", { enumerable: true, get: function () { return getParsedNftAccountsByOwner_1.getParsedNftAccountsByOwner; } });

Object.defineProperty(exports, "getParsedAccountByMint", { enumerable: true, get: function () { return getParsedAccountByMint_1.getParsedAccountByMint; } });
var resolveToWalletAddrress_1 = require("./resolveToWalletAddrress");
Object.defineProperty(exports, "resolveToWalletAddrress", { enumerable: true, get: function () { return resolveToWalletAddrress_1.resolveToWalletAddrress; } });
var resolveToWalletAddress_1 = require("./resolveToWalletAddress");
Object.defineProperty(exports, "resolveToWalletAddress", { enumerable: true, get: function () { return resolveToWalletAddress_1.resolveToWalletAddress; } });
var utils_1 = require("./utils");

@@ -14,0 +14,0 @@ Object.defineProperty(exports, "isValidSolanaAddress", { enumerable: true, get: function () { return utils_1.isValidSolanaAddress; } });

import { Connection, PublicKey } from "@solana/web3.js";
import { Metadata } from "./config/metaplex";
export declare const decodeTokenMetadata: (buffer: Buffer) => Promise<Metadata>;
/**
* Get Addresses of Metadata account assosiated with Mint Token
*/
export declare function getSolanaMetadataAddress(tokenMint: PublicKey): Promise<PublicKey>;

@@ -5,0 +8,0 @@ /**

@@ -52,2 +52,5 @@ "use strict";

exports.decodeTokenMetadata = decodeTokenMetadata;
/**
* Get Addresses of Metadata account assosiated with Mint Token
*/
function getSolanaMetadataAddress(tokenMint) {

@@ -54,0 +57,0 @@ return __awaiter(this, void 0, void 0, function () {

{
"name": "@nfteyez/sol-rayz",
"version": "0.8.2",
"version": "0.9.1",
"license": "MIT",

@@ -44,3 +44,3 @@ "author": {

},
"gitHead": "32ef6dcfdebb3cd32c7d1385f80114fbddb8dc12"
"gitHead": "2da688f71bcf5392acb13622ac30acef57c2af9a"
}

@@ -19,2 +19,56 @@ # @nfteyez/sol-rayz

The very basic example looks like this:
```javascript
import {
resolveToWalletAddress,
getParsedNftAccountsByOwner,
} from "@nfteyez/sol-rayz";
try {
// const address = "3EqUrFrjgABCWAnqMYjZ36GcktiwDtFdkNYwY6C6cDzy;
// or use Solana Domain
const address = "NftEyez.sol";
const publicAddress = await resolveToWalletAddress(address);
const nftArray = await getParsedNftAccountsByOwner({
publicAddress,
});
} catch (error) {
console.log("Error thrown, while fetching NFTs", error.message);
}
```
1. First, we import methods from "@nfteyez/sol-rayz".
2. Then we use `resolveToWalletAddress()` fn to check if passed string is [Solana Domain Names](https://docs.bonfida.org/collection/v/help/an-introduction-to-the-solana-name-service) or just usual Solana address, it also checks if such address is valid Solana public key. Otherwise, it throw the error. You can also skip this method if you are sure you have correct Solana wallet public key.
3. Finaly, we fetch all NFTs for this address with `getParsedNftAccountsByOwner()` method, passing object with only 1 argument `publicAddress`.
### Some Notes
In this example we pass object with single 1 argument `publicAddress`.
However, in real-life scenario, most times you will also wish to pass at least `Connection` object with your custom rpc-node. By default `getParsedNftAccountsByOwner()` fetches NFTs from Solana `mainnet` rpc-node, but since this method may do thousands of rpc-node calls for single wallet (depends of number of NFTs it holds), you may be quickly banned by network for abusing it. Custom RPC-nodes doesn't have such restrictions.
Keep in mind most methods from the package throw an error in case of any issues, so you might need to wrap them with `try-catch` block. This done intentionaly to force you handle possible errors and to provide you with proper error message.
## Available Methods
Here is the list of available methods:
| Method Name | Returns | |
| ------------------------------------- | -------------------------------------------------------------------------- | --- |
| getParsedNftAccountsByOwner | List of valid NFTs holded by passed wallet | |
| getParsedAccountByMint | Mint information. Finding the token owner is main purpose of using this fn | |
| getParsedNftAccountsByUpdateAuthority | ???? | |
| Utils Method Name | Returns | |
| ------------------------ | -------------------------------------------------------------------------------------------------------------------------------- | --- |
| resolveToWalletAddress | Can be used to to check and resolve provided text (like Solana Domain name ) into valid Solana wallet address. or fail otherwise | |
| isValidSolanaAddress | Check if passed address is valid Solana address | |
| createConnectionConfig | ??? | |
| getSolanaMetadataAddress | Get Addresses of Metadata account assosiated with Mint Token | |
| decodeTokenMetadata | Decode Buffer-type data into readable object | |
### `getParsedNftAccountsByOwner`
`getParsedNftAccountsByOwner` - return parsed list of NFTs (SPL Tokens) for given wallet public address. Each item in array have all data specified on the blockchain. The NFT metadata stored separately, you need to pick `uri` property for each token and fetch data youself.

@@ -50,11 +104,6 @@

/**
* Convert all PublicKey objects to string versions.
* Default is true
* Limit response by this number
* by default response limited by 5000 NFTs
*/
stringifyPubKeys?: boolean;
/**
* Sort tokens by Update Authority (read by Collection)
* Default is true
*/
sort?: boolean;
limit?: number;
});

@@ -61,0 +110,0 @@ ```

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc