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

@starkware-industries/starknet-connect

v1.0.0

Published

This library provides a set of classes to interact with the Starknet blockchain. With it, you can connect to different Starknet networks, manage accounts, and query transactions.

Downloads

1,141

Readme

Starknet Connect Library

This library provides a set of classes to interact with the Starknet blockchain. With it, you can connect to different Starknet networks, manage accounts, and query transactions.

Compatibility Note: This version is only compatible with Starknet RPC v7. Please ensure that your Starknet network is running on RPC v7 to utilize the features provided by this library effectively.

Features

  • Connect to Starknet networks (main, sepolia or a custom one).
  • Create and manage Starknet accounts.
  • Create and manage RPC Provider.

Classes and Types

  • StarknetConnect: Main class to establish connections and create accounts.
  • Provider: Handles RPC calls to the Starknet network. Various types for configuration and network interactions.

Configuration

The configuration of the Starknet connection library involves several key objects that allow you to set up and customize your interaction with the Starknet blockchain. Below are details on the primary configuration objects and how to use them.

StarknetConnectConfig

This configuration object defines the parameters needed to establish a connection to a specific Starknet network. It can come in two flavors:

A standard network

  • network: Specifies the network to connect to. Acceptable values are main for the main network and sepolia for the Sepolia test network.
  • providers: An optional array of ProviderConfig objects that detail the blockchain providers you wish to use for connecting to the Starknet network.

Example usage:

const starknetConnectConfig = {
  network: 'main',
  providers: [
    // Provider configurations
  ]
};

A custom network

  • chainId: The chain ID corresponding to the Starknet network, typically obtained from constants.StarknetChainId, but can be custom
  • providers: An optional array of URLProviderConfig objects that detail the blockchain providers you wish to use for connecting to the Starknet network.

ProvidersConfig

This object provides a configuration for the Provider class, which manages RPC calls to the Starknet network.

  • chainId: The chain ID corresponding to the Starknet network, typically obtained from constants.StarknetChainId.

  • providers: An array of ProviderConfig objects, each containing details for a specific provider. These can be specified by name of the provider and api key and optionally a node ID, or, by the base url of the provider.

  • Example usage:

const providersConfig = {
  chainId: constants.StarknetChainId.MAINNET,
  providers: [
    {
      name: StarknetConnect.Provider.ALCHEMY,
      apiKey: 'your-alchemy-api-key'
    },
    {
      baseUrl: 'https://private.custom-provider.com'
    }
    // Additional provider configurations
  ]
};

ProviderConfig

This object details individual configurations for blockchain providers. It can take the form of either ApiKeyProviderConfig or URLProviderConfig, depending on the provider.

  • name: The name of the provider, referenced using the StarknetConnect.Provider enum.

  • apiKey: The API key provided by the service (used by ApiKeyProviderConfig).

  • baseUrl: The base URL of the provider (used by URLProviderConfig).

  • Example usage:

const apiKeyProviderConfig = {
  name: StarknetConnect.Provider.INFURA,
  apiKey: 'your-infura-api-key'
};

const urlProviderConfig = {
  baseUrl: 'https://private.custom-provider.com'
};

Usage

Connecting to Starknet

To connect to a Starknet network:

import {StarknetConnect} from '@starkware-industries/starknet-connect';

const config = {
  network: 'main',
  providers: [
    // Your provider configurations
  ]
};

const starknetConnect = StarknetConnect.create(config);

Managing Accounts

To create a new Starknet account:

const accountParams = {
  address: '0x...',
  privateKey: '0x...'
};

const account = starknetConnect.createAccount(accountParams);

Using the Provider

To get the configured provider:

import {StarknetConnect} from '@starkware-industries/starknet-connect';

// Example provider configuration for StarknetConnect using the Provider enum
const starknetConnectConfig = {
  network: 'main', // or 'sepolia' for the test network
  providers: [
    {
      name: StarknetConnect.Provider.ALCHEMY,
      apiKey: 'your-alchemy-api-key'
    },
    {
      name: StarknetConnect.Provider.BLAST,
      apiKey: 'your-blast-api-key'
    },
    {
      name: StarknetConnect.Provider.CHAINSTACK,
      apiKey: 'your-chainstack-api-key'
    },
    {
      name: StarknetConnect.Provider.INFURA,
      apiKey: 'your-infura-api-key'
    }
  ]
};

// To create a connection with the above configuration
const starknetConnect = StarknetConnect.create(starknetConnectConfig);

// Use the getProvider() method to get the configured provider
const provider = starknetConnect.getProvider();

// Assuming that the provider has a method to get transaction by hash
// Note: You need to implement this functionality if it's not already present
const txHash = '0x123...'; // replace with an actual transaction hash
const transactionDetails = await provider.getTransactionByHash(txHash);

// Log the transaction details to the console
console.log(transactionDetails);