Security News
Maven Central Adds Sigstore Signature Validation
Maven Central now validates Sigstore signatures, making it easier for developers to verify the provenance of Java packages.
@snag/snag-sdk
Advanced tools
Welcome to the Snag Solutions SDK! This software development kit allows you to seamlessly integrate the Snag platform into your applications, enabling users to buy and list tokens with ease. The SDK provides a simple interface for both purchasing and listing tokens on supported chains.
To use the Snag SDK in your project, follow these steps:
npm install @snag/snag-sdk
SnagSDK
class into your project:import '@snag/snag-sdk/dist/styles.css';
import { SnagSDK } from '@snag/snag-sdk';
To initiate a token purchase, create a new instance of the SnagSDK
class and call the buyNow
method:
const snagInstance = new SnagSDK({
chainId: YOUR_CHAIN_ID,
});
snagInstance.buyNow({
collectionId: TARGET_COLLECTION_ID,
tokenId: TARGET_TOKEN_ID,
});
To list a token, use the listItem
method:
const snagInstance = new SnagSDK({
chainId: YOUR_CHAIN_ID,
});
snagInstance.listItem({
collectionId: TARGET_COLLECTION_ID,
tokenId: TARGET_TOKEN_ID,
});
You can pass an optional twitterAccount
property to the SnagSDK
constructor:
const snagInstance = new SnagSDK({
chainId: YOUR_CHAIN_ID,
twitterAccount: YOUR_TWITTER_ACCOUNT_ID,
});
If you provide a Twitter account ID, you'll be able to share purchase news on Twitter after purchase.
If you want to support gasless transactions you can pass an optional gaslessApiKey
property to the SnagSDK
constructor with your Gelato Relay api key. You can also force user to buy tokens with different currency if native doesn't support gasless. You can pass forceGaslessCurrency
which is ERC20 address.
const snagInstance = new SnagSDK({
chainId: YOUR_CHAIN_ID,
gaslessApiKey: YOUR_GELATO_API_KEY,
forceGaslessCurrency: YOUR_CURRENCY_ADDRESS_FOR_ABOVE_CHAIN_ID,
});
Both buyNow
and listItem
methods support the following optional callbacks:
snagInstance.buyNow({
collectionId: TARGET_COLLECTION_ID,
tokenId: TARGET_TOKEN_ID,
onSuccess: (response) => {
// Handle successful execution
},
onFailure: (response) => {
// Handle execution failure
},
onValidationFailure: (error) => {
// Handle validation errors
},
});
To use the Snag SDK with your marketplace theme, follow these steps:
Pass Additional Parameter to Class Constructor:
When initializing the Snag SDK, make sure to pass an additional parameter to the class constructor with domain
set to your marketplace domain url. For example:
const snagInstance = new SnagSDK({
chainId: YOUR_CHAIN_ID,
domain: 'https://domain.marketplace.com',
});
To use the Snag SDK with a custom theme where you can set all of the colours on your own, follow these steps:
Include Custom Theme in CSS:
Add the following CSS code to your stylesheets to apply a custom theme to the Snag SDK Components. This example sets a custom color palette and styling:
<style type="text/css">
#snag-modal[data-theme='custom'] {
--snag-font-family: 'Inter', sans-serif;
--snag-primary: 83 109 254;
--snag-secondary: 206 18 18;
--snag-primary-text: 255 255 255;
--snag-secondary-text: 100 138 180;
--snag-separator: 56 56 56;
--snag-success: 76 175 80;
--snag-error: 146 21 12;
--snag-modal-background: 47 45 45;
--snag-modal-border-radius: 16px;
--snag-button-border-radius: 50px;
--snag-input-border-radius: 4px;
}
</style>
Note: The color values in the custom theme are specified in RGB format without commas between the numbers.
Pass Additional Parameter to Class Constructor:
When initializing the Snag SDK, make sure to pass an additional parameter to the class constructor with withCustomTheme
set to true
. For example:
const snagInstance = new SnagSDK({
chainId: YOUR_CHAIN_ID,
withCustomTheme: true
});```
Here's a complete example demonstrating the usage of the Snag SDK:
import '@snag/snag-sdk/dist/styles.css';
import { SnagSDK } from '@snag/snag-sdk';
const snagInstance = new SnagSDK({
chainId: YOUR_CHAIN_ID,
});
snagInstance.buyNow({
collectionId: TARGET_COLLECTION_ID,
tokenId: TARGET_TOKEN_ID,
onSuccess: (response) => {
console.log('Token purchased successfully!', response.txHash);
},
onFailure: (response) => {
console.error('Token purchase failed:', response?.errors);
},
});
Happy coding with Snag SDK! If you encounter any issues or have questions, please refer to our documentation or contact support.
FAQs
<!-- # Snag Solutions SDK -->
The npm package @snag/snag-sdk receives a total of 0 weekly downloads. As such, @snag/snag-sdk popularity was classified as not popular.
We found that @snag/snag-sdk demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 4 open source maintainers 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
Maven Central now validates Sigstore signatures, making it easier for developers to verify the provenance of Java packages.
Security News
CISOs are racing to adopt AI for cybersecurity, but hurdles in budgets and governance may leave some falling behind in the fight against cyber threats.
Research
Security News
Socket researchers uncovered a backdoored typosquat of BoltDB in the Go ecosystem, exploiting Go Module Proxy caching to persist undetected for years.