Getting Started
Overview
Starkweb Core is a VanillaJS library for Starknet. You can learn more about the rationale behind the project in the Why Starkweb section.
Manual Installation
To manually add Starkweb to your project, install the required packages:
pnpm
pnpm add starkweb
- Starknet React Core is a collection of interfaces for linking accounts/wallets to Starkweb
- Starknet is a TypeScript interface for Starknet that performs blockchain operations
- TypeScript is optional, but highly recommended. Learn more about TypeScript support
Create Config
Create and export a new Starkweb config using createConfig
:
config.ts
import { http, createConfig } from "starkweb/core";
import { mainnet, sepolia } from "starkweb/chains";
export const config = createConfig({
chains: [mainnet, sepolia],
transports: {
[mainnet.chain_id]: http(),
[sepolia.chain_id]: http(),
},
});
In this example, Starkweb is configured to use the Mainnet and Sepolia chains.
Use Starkweb
Now that everything is set up, you can pass the config
to use actions:
index.ts
import { getAccount, getBalance } from "starkweb/core";
import { config } from "./config";
const { address } = getAccount(config);
const balance = await getBalance(config, { address });
Core Concepts
Config
The Config
instance is the heart of Starkweb Core. It manages:
- Chain configurations
- Transport clients (HTTP/WebSocket)
- Connector state
- Account state
Actions
Actions are functions that interact with Starknet:
import { getBalance, readContract } from 'starkweb/core'
// Read account balance
const balance = await getBalance(config, {
address: '0x123...'
})
// Read contract data
const data = await readContract(config, {
address: '0x456...',
abi: [...],
functionName: 'balanceOf'
})
Connectors
Connectors are bridges between Starkweb and wallets. They handle account management and signing:
import { injected } from "starkweb/connectors";
const connector = injected();
await connector.connect();
Transports
Transports define how Starkweb communicates with Starknet nodes:
import { http, webSocket } from "starkweb/core";
const transport = http(); // HTTP transport
const wsTransport = webSocket(); // WebSocket transport
Next Steps
For more information on what to do next, check out:
- TypeScript - Learn how to get the most out of Starkweb's type-safety and inference
- Actions - Browse the collection of actions and learn how to use them