npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@getsafle/safle-gaming-sdk

v1.0.1

Published

Package for interacting with the SafleId Smart Contracts.

Downloads

69

Readme

SafleID SDK

The SafleID SDK is a JavaScript library designed to interact with the SafleID ecosystem. It provides functionality to validate, register, and resolve SafleIDs on blockchain networks through smart contracts and a relayer API.


Features

  • Validate SafleIDs against predefined rules.
  • Check the registration status of SafleIDs.
  • Resolve user addresses to SafleIDs and vice versa.
  • Retrieve SafleID registration fees.
  • Register a new SafleID using a relayer service.

Installation

Install the required dependencies:

npm install @getsafle/safle-gaming-sdk

Add this SDK to your project:

const { SafleID } = require('@getsafle/safle-gaming-sdk');

Usage

Import and Initialize the SafleID SDK

const { SafleID } = require("@getsafle/safle-gaming-sdk");

const config = {
  env: "testnet", // Options: 'testnet' or 'mainnet'
  rpcUrl: "https://your-rpc-url.com",
  mainContractAddress: "0xMainContractAddress",
  storageContractAddress: "0xStorageContractAddress",
  chainId: 1, // Ethereum Mainnet or Testnet Chain ID
  relayerUrl: "https://your-relayer-url.com",
  relayerApiKey: "your-api-key",
};

const safleID = new SafleID(config);

Methods

1. isSafleIdValid(safleId)

Validates if the given SafleID is valid based on its length and characters.

  • Parameters:

    • safleId (string): SafleID to validate.
  • Returns:

    • true if valid, otherwise false.

2. isRegistrationPaused()

Checks if SafleID registration is paused.

  • Returns:
    • true if registration is paused, otherwise false.

3. getSafleId(userAddress)

Fetches the SafleID associated with a user's address.

  • Parameters:

    • userAddress (string): Ethereum address.
  • Returns:

    • SafleID (string) or an error message.

4. getAddress(safleId)

Fetches the Ethereum address associated with a SafleID.

  • Parameters:

    • safleId (string): The SafleID to resolve.
  • Returns:

    • Ethereum address (string) or a fallback value.

5. safleIdFees()

Fetches the SafleID registration fee.

  • Returns:
    • Registration fee (string).

6. setSafleId(payload)

Registers a new SafleID through the relayer.

  • Parameters:

    • payload (object): Contains userAddress and safleId.
  • Returns:

    • Registration response (object) or an error message.

Example Usage

(async () => {
  const safleId = "mySafleId";
  const userAddress = "0xYourEthereumAddress";

  // Check if a SafleID is valid
  const isValid = await safleID.isSafleIdValid(safleId);
  console.log(`Is SafleID valid: ${isValid}`);

  // Check registration status
  const isPaused = await safleID.isRegistrationPaused();
  console.log(`Registration Paused: ${isPaused}`);

  // Fetch the SafleID for an address
  const userSafleID = await safleID.getSafleId(userAddress);
  console.log(`User's SafleID: ${userSafleID}`);

  // Fetch the address for an SafleID
  const userAddress = await safleID.getAddress(safleId);
  console.log(`User's Address: ${userAddress}`);

  // Register a new SafleID
  const response = await safleID.setSafleId({ userAddress, safleId });
  console.log("Registration Response:", response);
})();

Error Messages

The SDK includes predefined error messages stored in ./constants/errors.js. These errors handle invalid inputs, paused registration, already-taken SafleIDs, and more.


Notes

  • Ensure the relayerUrl and relayerApiKey are configured correctly.
  • Use a secure environment to store API keys and sensitive configurations.
  • The rejectUnauthorized: false option is for testing purposes only. For production, ensure the HTTPS connection is secure.

License

MIT

Feel free to contribute to the project or report issues. Happy coding! 🎉