Skip to content

Conversation

@NLJinchuriki
Copy link

@NLJinchuriki NLJinchuriki commented Dec 11, 2024

This PR introduces significant improvements to the SDK’s error handling, logging, code structure, and documentation, aiming to deliver a more intuitive and transparent experience for developers integrating with the Supra blockchain.

Changes Made

Refactored Code Structure
- Introduced dedicated AccountService, TransactionService, and RequestService classes for clearer separation of concerns and improved maintainability.
- Added a clean interface for the SupraClient
- Added a clean request handler for making request and handling various errors
- Extracted utility functions (e.g., address normalization, sleeping, and type argument parsing) into a utils/helpers.ts module.

Streamlined Logging
- Introduced a built-in Logger with configurable log levels and a customizable ILogTransport. So you can pas your own logger, and use the transport to log elsewhere for example within your application
- Ensured consistent logging for all network requests, responses, and errors to facilitate easier debugging.

Documentation & Developer Experience
- Overhauled the README.md for improved clarity and detailed usage instructions.
- Added a comprehensive example demonstrating initialization, transaction simulation, and logging setup.
- Introduced vitest tests

Backward Compatibility
- Maintained the public API of ISupraClient while streamlining internal error handling and logging.
- Users upgrading to this version will experience clearer error messages and enhanced logs without requiring changes to their existing code.

**example.js fully working with the new setup!**

Why Merge?

These updates make the SDK more transparent, maintainable, and developer-friendly by:
1. Improving error visibility and clarity.
2. Simplifying code structure for easier maintenance and extension.
3. Providing better logging and debugging tools for developers.

Next Steps
1. Review for consistency and adherence to code standards.
2. Address feedback regarding further refactoring or interface changes.
3. Upon approval, merge to release an improved SDK to users.
4. Add correct return types instead of

Breaking change:

old:

let supraClient = await SupraClient.init(
  "https://rpc-testnet.supra.com/"
);
  
let supraClient = new supraSDK.SupraClient(
  "https://rpc-wallet.supra.com/",
  3
);

---

new: 
const client = await SupraClient.init({
  url: 'https://rpc.supra.com',
  chainId: 1 // Optional: defaults to the RPC node's chain ID
})

let supraClient = new SupraClient({
  url: 'https://rpc-wallet.supra.com/',
  chainId: 3
})

// To Create Instance Of Supra Client, But In This Method We Don't Need To Pass ChainId.
// ChainId Will Be Identified At Instance Creation Time By Making RPC Call.
let supraClient = await SupraClient.init({
  url: 'https://rpc-testnet.supra.com/'
})

options object:

interface SupraClientOptions {
  /**
   * RPC URL of the Supra node. If not provided, a default URL is used.
   */
  url?: string

  /**
   * Chain ID of the network. If not provided, it will be fetched from the RPC node.
   */
  chainId?: number

  /**
   * Custom RequestService instance. If not provided, a default instance is created.
   */
  /**
   * @internal
   * Custom RequestService instance. If not provided, a default instance is created.
   */
  requestService?: RequestService

  /**
   * Custom AccountService instance. If not provided, a default instance is created.
   */
  /**
   * @internal
   * Custom RequestService instance. If not provided, a default instance is created.
   */
  accountService?: AccountService

  /**
   * Custom TransactionService instance. If not provided, a default instance is created.
   */
  /**
   * @internal
   * Custom RequestService instance. If not provided, a default instance is created.
   */
  transactionService?: TransactionService

  /**
   * Logger instance. If not provided, a default logger is created.
   */
  logger?: Logger

  /**
   * Logging level. Defaults to 'WARN' if not provided.
   * Ignored if a custom logger is provided.
   */
  logLevel?: LogLevel

  /**
   * Log transport function. Ignored if a custom logger is provided.
   */
  logTransport?: (log: any) => void
}
  

old: supraClient.isAccountExists
new supraClient.accountExists (renamed to proper function name)

This PR significantly enhances the development experience, making it easier and more reliable for developers to build with the Supra blockchain SDK.

Team Jinchuriki out!
image

Feel free to mail me at [email protected]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant