Security News
Research
Data Theft Repackaged: A Case Study in Malicious Wrapper Packages on npm
The Socket Research Team breaks down a malicious wrapper package that uses obfuscation to harvest credentials and exfiltrate sensitive data.
airstack-web-sdk-test
Advanced tools
The Airstack Web SDK provides a set of react hooks and components for web developers to easily integrate Airstack's blockchain functionalities into their web applications. With this SDK, developers can perform various tasks, such as querying and fetching
The Airstack Web SDK provides a set of react hooks and components for web developers to easily integrate Airstack's blockchain functionalities into their web applications. With this SDK, developers can perform various tasks, such as querying and fetching data from smart contracts, displaying NFT assets.
npm install airstack-web-sdk
yarn add airstack-web-sdk
To use the SDK you will need airstack api-key, which you can find in your profile setting section in airstack web, once you have it you can call the init
function with the api-key.
init
must be called before any of the SDK hook or component is used, we recommend to use init
in the App.ts file.
import { init, useQuery } from "airstack-web-sdk";
init('api-key');
const MyComponent = () => {
const { data, loading, error } = useQuery(query, variables, { cache: false });
if (loading) {
return <p>Loading...</p>;
}
if (error) {
return <p>Error: {error.message}</p>;
}
// Render your component using the data returned by the query
};
All the hooks take 3 parameters
query
(required): A string that represents the Airstack GraphQL query to be executed.variables
: An object that contains variables used in the query.config
(optional): An object that contains optional configuration parameters for the request. Currently, the only available parameter is cache
, which is a boolean that determines whether to cache the response or not.const { data, loading, error } = useQuery(query, variables, {cache:false});
The useQuery
hook loads query data as soon as the component is mounted. It returns an object with the following properties:
data
: the data returned by the query.loading
: a boolean indicating whether the query is currently loading.error
: any error that occurred while loading the query.import { useQuery } from "airstack-web-sdk";
const MyComponent = () => {
const { data, loading, error } = useQuery(query, variables);
if (loading) {
return <p>Loading...</p>;
}
if (error) {
return <p>Error: {error.message}</p>;
}
// Render your component using the data returned by the query
};
The useLazyQuery
hook is used when you want to fetch query data manually, instead of automatically when the component mounts. It returns an array with two items:
fetch
: a function that can be called to execute the query.useQuery
: data
, loading
, and error
.import { useLazyQuery } from "airstack-web-sdk";
const MyComponent = () => {
const [fetch, { data, loading, error }] = useLazyQuery(query, variables);
const handleClick = () => {
fetch();
};
if (loading) {
return <p>Loading...</p>;
}
if (error) {
return <p>Error: {error.message}</p>;
}
// Render your component using the data returned by the query
};
The useQueryWithPagination
hook provides a simple way to paginate the data returned by a query. It works the same as the useQuery
hook, but also returns an object with the following properties:
pagination
: an object with the following properties:
hasNextPage
: a boolean indicating whether there is another page of data after the current page.hasPrevPage
: a boolean indicating whether there is another page of data before the current page.getNextPage
: a function that can be called to fetch the next page of data.getPrevPage
: a function that can be called to fetch the previous page of data.Note:
useQueryWithPagination
only works with queries that support pagination.
import { useQueryWithPagination } from "airstack-web-sdk";
const MyComponent = () => {
const { data, loading, pagination } = useQueryWithPagination(query, variables);
const { hasNextPage, hasPrevPage, getNextPage, getPrevPage } = pagination;
const handleNextPage = () => {
getNextPage();
};
const handlePrevPage = () => {
getPrevPage();
};
if (loading) {
return <p>Loading...</p>;
}
if (error) {
return <p>Error: {error.message}</p>;
}
// Render your component using the data returned by the query
};
The useLazyQueryWithPagination hook is used when you want to manually fetch paginated data. It returns an array with two items:
fetch
: a function that can be called to execute the query.data
, loading
, and pagination
.The fetch
function can be called whenever you want to execute the query, for example, in response to a user action like clicking a button to load more data. The hook returns the data
, loading
, and pagination
properties just like useQueryWithPagination.
Here's an example of using useLazyQueryWithPagination:
import { useLazyQueryWithPagination } from "airstack-web-sdk";
function Component() {
const [fetchData, { data, loading, pagination }] = useLazyQueryWithPagination(
query,
variables
);
const loadMore = () => {
if (pagination.hasNextPage) {
pagination.getNextPage();
}
};
return (
<div>
<button onClick={fetchData}>Fetch Data</button>
<ul>
{data.map((item) => (
<li key={item.id}>{item.name}</li>
))}
</ul>
{pagination.hasNextPage && <button onClick={loadMore}>Load More</button>}
{loading && <p>Loading...</p>}
</div>
);
}
In the example, we define a loadMore
function that gets called when a user clicks a "Load More" button. The loadMore
function checks if there is a next page using pagination.hasNextPage
and calls pagination.getNextPage()
to fetch the next page of data.
Note that when using useLazyQueryWithPagination
, you will need to handle the fetching of the initial data yourself. In the example, we call the fetchData
function to fetch the initial data when the user clicks the "Fetch Data" button.
The NftAsset
component can be used to load and display NFT assets in your React application.
chain
(optional): a string representing the blockchain network to use. Defaults to "ethereum"
.address
(required): a string representing the contract address of the NFT.tokenId
(required): a string representing the token ID of the NFT.loading
(optional): a React node to show while the asset is loading.error
(optional): a React node to show if there is an error loading the asset.imgProps
(optional): an object of HTML image attributes to pass to the underlying image element.preset
(optional): a string representing the size of the asset image to display. Can be one of "extraSmall"
, "small"
, "medium"
, "large"
, or "original"
. Defaults to "medium"
.import { NftAsset } from "airstack-web-sdk";
function App() {
return (
<div>
<NftAsset
chain="ethereum"
address="0x...",
tokenId="tokenId"
loading={<div>Loading...</div>}
error={<div>Error loading asset.</div>}
imgProps={{alt: "my asset"}}
preset="medium"
/>
</div>
);
}
fetchQuery can be used in places where using hooks is not possible. fetchQuery
take same parameter as hooks.
fetchQuery
returns a promise with an object, which contains the following properties:
data
: The response data returned by the server.error
: An error object, if an error occurred during the network request.hasNextPage
: A boolean that indicates whether there is a next page of data available.hasPrevPage
: A boolean that indicates whether there is a previous page of data available.getNextPage()
: A function that returns a next page of data. Returns null
if there is no next page.getPrevPage()
: A function that returns previous page of data. Returns null
if there is no previous page.Note: you must pass a query which supports pagination, the query must have pageInfo
field for pagination to work.
import { fetchQuery } from './fetchQuery';
const { data, error, hasNextPage, hasPrevPage, getNextPage, getPrevPage } = await fetchQuery(query, variables, config);
FAQs
The Airstack Web SDK provides a set of react hooks and components for web developers to easily integrate Airstack's blockchain functionalities into their web applications. With this SDK, developers can perform various tasks, such as querying and fetching
The npm package airstack-web-sdk-test receives a total of 6 weekly downloads. As such, airstack-web-sdk-test popularity was classified as not popular.
We found that airstack-web-sdk-test demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Research
The Socket Research Team breaks down a malicious wrapper package that uses obfuscation to harvest credentials and exfiltrate sensitive data.
Research
Security News
Attackers used a malicious npm package typosquatting a popular ESLint plugin to steal sensitive data, execute commands, and exploit developer systems.
Security News
The Ultralytics' PyPI Package was compromised four times in one weekend through GitHub Actions cache poisoning and failure to rotate previously compromised API tokens.