Registry / blockchain / starknet

starknet

JSON →
library10.0.2jsnpmunverified

JavaScript/TypeScript library for interacting with Starknet, a ZK-rollup Layer 2 on Ethereum. This library provides a complete interface for account management, contract interaction, and transaction signing. Current stable version 10.0.2 (released November 2024) with monthly releases. It requires Node.js >=22 (breaking from previous 18 support) and is ESM-only from v6. Key differentiators: official SDK from Starkware, supports both RPC and sequencer APIs.

npm install starknet
INSTALL
IMPORT
SIG · STARKNET
S
starknet
blockchainjavascriptv10.0.2
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

Starknet
import { Starknet, Account } from 'starknet'
const starknet = require('starknet')
ESM-only since v6. Default export removed in v4.
cairo
import { cairo, uint256 } from 'starknet'
import cairo from 'starknet'
cairo is a named export, not default. Also exports uint256.
RPCProvider
import { RPCProvider, SequencerProvider } from 'starknet'
import { Provider } from 'starknet'
Provider interface deprecated since v4. Use RPCProvider or SequencerProvider directly.

Demonstrates creating an RPC provider, account, and calling a read function on an ERC20 contract.

import { RPCProvider, Contract, Account, cairo, uint256 } from 'starknet'; const provider = new RPCProvider({ nodeUrl: process.env.STARKNET_RPC_URL ?? 'https://starknet-sepolia.public.blastapi.io/rpc/v0_7' }); const account = new Account(provider, process.env.ADDRESS ?? '', process.env.PRIVATE_KEY ?? ''); const erc20 = new Contract(provider, [ { type: 'function', name: 'balanceOf', inputs: [{ name: 'account', type: 'core::starknet::contract_address::ContractAddress' }], outputs: [{ type: 'core::integer::u256' }], state_mutability: 'view' } ], '0x049d36570d4e46f48e99674bd3fcc84644ddd6b96f7c741b1562b82f9e004dc7'); const balance = await erc20.call('balanceOf', [account.address]); console.log('Balance:', balance);
Debug
Known issues
breakingNode.js <22 is no longer supported as of v10. Requires Node >=22.
fix
Update Node.js to version 22 or later.
affects: >=10.0.0
breakingESM-only: require() will throw. Use dynamic import or switch to ESM.
fix
Use import syntax. If you must use CommonJS, use dynamic import: const starknet = await import('starknet');
affects: >=6.0.0
deprecatedProvider class is deprecated. Use RPCProvider or SequencerProvider.
fix
Replace new Provider(...) with new RPCProvider(...) or new SequencerProvider(...).
affects: >=4.0.0
gotchaWhen using ConnectSession, ensure you call session.authorize() before making requests, otherwise requests will fail with 401.
fix
Always call await session.authorize() after creating a ConnectSession.
affects: *
breakingcairo and uint256 exports changed in v4 from default to named. The old import { cairo } from 'starknet' still works but cairo.default is no longer a function.
fix
Use import { cairo } from 'starknet' and call cairo.felt() etc. Do not use cairo.default.
affects: >=4.0.0
deprecatedStarknet.config function deprecated in v6. Use createStarknetConfig factory.
fix
Use import { createStarknetConfig } from 'starknet' instead of Starknet.config().
affects: >=6.0.0
Errors
Common errors & fixes
Cannot find module 'starknet'
Package not installed, or running in environment without node_modules resolution (e.g., Deno, browser).
fix
Install with npm install starknet. For browser, use a bundler or importmap.
TypeError: starknet.Starknet is not a constructor
Using require with ESM-only package. In v6+, require() fails.
fix
Change to: import { Starknet, Account } from 'starknet';
Error: Invalid RPC node URL
Missing or malformed nodeUrl in RPCProvider constructor.
fix
Provide a valid nodeUrl, e.g., new RPCProvider({ nodeUrl: 'https://starknet-sepolia.public.blastapi.io/rpc/v0_7' }).
Invariant failed: Network name is not supported
Using deprecated Provider with network name string (e.g., 'mainnet-alpha'), but v4+ requires explicit nodeUrl.
fix
Use RPCProvider with nodeUrl or SequencerProvider with baseUrl.
Upgrade
Version history
10.0.2latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
31 hits · last 30 days
node
26
OpenAI (training)
1
Resources