Starknet Js logo

Starknet Js

Organization
keep-starknet-strange
starknet-js

Reference for building Starknet applications using starknet.js v10 SDK, including contract interaction, account management, transaction handling, fee estimation, wallet integration, and paymaster flows.

Overview

Publisherkeep-starknet-strange
Repositorystarknet-agentic
Skill namestarknet-js
Stars
81
Forks
26
Bundled files
7
LicenseApache-2.0
Links
  • Markdown instructions

    A SKILL.md file the model loads on demand, so it only costs tokens when a request actually matches.

  • Works with any LLM

    AI skills are plain Markdown, not provider-specific code, so this works with GPT, Claude, Gemini, Grok, or a local model.

  • 7 bundled files

    Scripts, templates, and references the model can read while it works. Files are read-only and never executed.

  • Open source

    Published by keep-starknet-strange on GitHub. Read the source before you install it.

Installation

Install the Starknet Js AI skill in TypingMind to use it with any LLM, or drop it into another agent that reads SKILL.md.

1

Install in TypingMind

TypingMind installs a skill straight from its GitHub folder — it reads SKILL.md, bundles the resource files, and stores the result locally.

  1. Open the app and go to Plugins → Skills.
  2. Choose "Install from GitHub".
  3. Paste the skill folder URL below and confirm.
    https://github.com/keep-starknet-strange/starknet-agentic/tree/main/skills/starknet-js
  4. Enable the skill in any chat where you want it available.
Plugins → Skills → Add skill → From GitHub URL, then paste the folder URL and press Continue.
2

Install in another agent

Any agent that reads the Agent Skills format can use this skill — copy the folder into that agent's skills directory.

Claude Code — .claude/skills
git clone --depth 1 https://github.com/keep-starknet-strange/starknet-agentic.git /tmp/starknet-agentic
mkdir -p .claude/skills
cp -r /tmp/starknet-agentic/skills/starknet-js .claude/skills/starknet-js
Restart Claude Code after copying so it picks up the new skill.

Use it in TypingMind

Enable Starknet Js in any TypingMind chat and the model takes it from there. Its name and description sit in the system prompt, and the moment a request matches, the model loads the full instructions itself — you never invoke it by hand, and it costs no tokens until it is actually used.

The model loads Starknet Js on its own as soon as a request matches it.

Works with any AI model

AI skills are plain Markdown instructions rather than provider-specific code, so Starknet Js is not tied to the model it was written for. Install it once in TypingMind and use it with GPT-5, Claude, Gemini, Grok, DeepSeek, Mistral, Llama, or a local model you run yourself — all on your own API keys.

  • Loaded only when it is needed

    The system prompt carries just the name and description. The instructions are fetched on the first matching request, so an idle skill costs nothing.

  • Switch models mid-chat

    Because the skill is instructions rather than code, changing model does not break it — the next model reads the same SKILL.md.

Skill instructions

This is the SKILL.md content the model loads. Read it before installing — a skill is instructions your model will follow.

starknet.js v10 SDK

Related modules: skills catalog.

When to Use

  • Building Starknet apps with provider, account, contract, wallet, or paymaster flows.

When NOT to Use

  • Cairo contract authoring, deployment-only runbooks, or security audits.

Quick Start

bash
npm install starknet@^10.8.0

Minimal setup to read from Starknet:

typescript
import { RpcProvider, Contract } from 'starknet';

const provider = await RpcProvider.create({ nodeUrl: 'https://api.cartridge.gg/x/starknet/mainnet/rpc/v0_10' });
const contract = new Contract({ abi, address: contractAddress, providerOrAccount: provider });
const result = await contract.get_balance();

Core Architecture

Provider -> Account -> Contract
   |          |          |
Network   Identity   Interaction
  • Provider: Read-only network connection (RpcProvider)
  • Account: Signs and sends transactions; in v10 it no longer extends Provider, so call provider methods through account.provider
  • Contract: Type-safe interface to deployed contracts

Use Provider for read operations, Account for write operations.

Provider Setup

typescript
import { RpcProvider } from 'starknet';

// Recommended: Auto-detect RPC spec version
const provider = await RpcProvider.create({
  nodeUrl: 'https://api.cartridge.gg/x/starknet/mainnet/rpc/v0_10'
});

Networks (keyless public Cartridge endpoints on RPC spec 0.10, rate limited; use your own provider in production):

  • Mainnet: https://api.cartridge.gg/x/starknet/mainnet/rpc/v0_10
  • Sepolia: https://api.cartridge.gg/x/starknet/sepolia/rpc/v0_10

Key Methods:

typescript
const chainId = await provider.getChainId();
const block = await provider.getBlock('latest');
const nonce = await provider.getNonceForAddress(accountAddress);
await provider.waitForTransaction(txHash);

// Read storage directly (v10 returns { value, last_update_block }, not a bare felt)
const { value } = await provider.getStorageAt(contractAddress, storageKey);

Account Management

Account Creation (4 Steps)

Step 1: Compute address

typescript
import { hash, ec, encode, CallData } from 'starknet';

// IMPORTANT: `stark.randomAddress()` returns an address-like random felt and is NOT a private key.
// Use a real stark curve private key generator.
const privateKey = '0x' + encode.buf2hex(ec.starkCurve.utils.randomPrivateKey());
const publicKey = ec.starkCurve.getStarkKey(privateKey);

// NOTE: account class hashes are network/account-type dependent.
// Treat this as an example only (verify the correct class hash for your setup).
const classHash = '0x540d7f5ec7ecf317e68d48564934cb99259781b1ee3cedbbc37ec5337f8e688'; // example

const constructorCalldata = CallData.compile({ publicKey });
const address = hash.calculateContractAddressFromHash(publicKey, classHash, constructorCalldata, 0);

Step 2: Fund the address with STRK before deployment.

Step 3: Deploy

typescript
import { Account } from 'starknet';

// v10: the Account constructor takes a single options object
const account = new Account({ provider, address, signer: privateKey, cairoVersion: '1' });
const { transaction_hash } = await account.deployAccount({
  classHash,
  constructorCalldata,
  addressSalt: publicKey
});
await provider.waitForTransaction(transaction_hash);

Step 4: Use the account for transactions.

Connect to Existing Account

typescript
const account = new Account({
  provider,
  address: '0x123...',
  signer: privateKey,
  cairoVersion: '1'  // Optional, auto-detected if omitted
});

Contract Interaction

Connect to Contract

typescript
import { Contract } from 'starknet';

const contract = new Contract({ abi, address: contractAddress, providerOrAccount: provider });  // Read-only
const writeContract = new Contract({ abi, address: contractAddress, providerOrAccount: account });   // Read-write

Typed Contract (Type-Safe)

typescript
// Get full TypeScript autocomplete and type checking from ABI
const typedContract = contract.typedv2(abi);
const balance = await typedContract.balanceOf(userAddress);

Read State

typescript
const balance = await contract.get_balance();
const userBalance = await contract.balanceOf(userAddress);

Write (Execute)

typescript
const tx = await contract.increase_balance(100);
await provider.waitForTransaction(tx.transaction_hash);

Multicall (Batch Transactions)

typescript
import { CallData, cairo } from 'starknet';

const calls = [
  {
    contractAddress: tokenAddress,
    entrypoint: 'approve',
    calldata: CallData.compile({ spender: bridgeAddress, amount: cairo.uint256(1000n) })
  },
  {
    contractAddress: bridgeAddress,
    entrypoint: 'deposit',
    calldata: CallData.compile({ amount: cairo.uint256(1000n) })
  }
];

const tx = await account.execute(calls);

Using populate() for type-safety:

typescript
const approveCall = tokenContract.populate('approve', {
  spender: bridgeAddress,
  amount: cairo.uint256(1000n)
});
const depositCall = bridgeContract.populate('deposit', { amount: cairo.uint256(1000n) });
const tx = await account.execute([approveCall, depositCall]);

Parse Events

typescript
const receipt = await provider.getTransactionReceipt(txHash);
const events = contract.parseEvents(receipt);
// Events are keyed by full Cairo path, e.g. '...::ERC20Component::Transfer'
const transferEvents = events.filter((e) => Object.keys(e).some((name) => name.endsWith('::Transfer')));

Transaction Simulation

Simulate before executing to catch reverts and inspect state changes:

typescript
// v10 returns { simulated_transactions, initial_reads? } instead of an array
const { simulated_transactions: [sim] } = await account.simulateTransaction(
  [{ type: 'INVOKE', payload: calls }], { skipValidate: false }
);

console.log('Fee estimate:', sim.overall_fee, sim.resourceBounds);
console.log('Trace:', sim.transaction_trace);

// Check state changes before execution
const trace = sim.transaction_trace;
if ('state_diff' in trace && trace.state_diff) {
  console.log('Storage changes:', trace.state_diff.storage_diffs);
}

Fee Estimation

typescript
const fee = await account.estimateInvokeFee(calls);
console.log({
  overallFee: fee.overall_fee,
  resourceBounds: fee.resourceBounds  // V3: l1_gas, l2_gas, l1_data_gas
});

Execute with custom bounds (each resource is { max_amount, max_price_per_unit } as bigint; by default v10 already adds a 50% margin to estimated bounds via config.get('resourceBoundsOverhead')):

typescript
const { resourceBounds } = await account.estimateInvokeFee(calls);
const tx = await account.execute(calls, {
  resourceBounds: {
    ...resourceBounds,
    l2_gas: { ...resourceBounds.l2_gas, max_amount: resourceBounds.l2_gas.max_amount * 2n }
  }
});

With priority tip (v10 applies recommendedTip by default via config defaultTipType; pass tip to override). getEstimateTip() returns { minTip, maxTip, averageTip, medianTip, modeTip, recommendedTip, p90Tip, p95Tip }:

typescript
const tipStats = await provider.getEstimateTip();
const tx = await account.execute(calls, { tip: tipStats.p90Tip });

Transaction Receipt Handling

typescript
const receipt = await provider.waitForTransaction(txHash);

// Status check helpers
if (receipt.isSuccess()) {
  console.log('Transaction succeeded');
} else if (receipt.isReverted()) {
  console.log('Reverted:', receipt.revert_reason);
} else if (receipt.isError()) {
  console.log('Error');
}

Wallet Integration

Connect to browser wallets (ArgentX, Braavos):

typescript
import { connect } from '@starknet-io/get-starknet';
import { WalletAccount } from 'starknet';

const selectedWallet = await connect({ modalMode: 'alwaysAsk' });
if (!selectedWallet) throw new Error('No wallet selected');
// get-starknet 4.x bundles older wallet-API types than v10; strict TS may need a cast here
const walletAccount = await WalletAccount.connect(
  { nodeUrl: 'https://api.cartridge.gg/x/starknet/mainnet/rpc/v0_10' },
  selectedWallet
);

// Use like regular Account
const tx = await walletAccount.execute(calls);

// Event handlers
walletAccount.onAccountChange((accounts) => console.log('New account:', accounts?.[0]));
walletAccount.onNetworkChanged((chainId) => console.log('Network changed:', chainId));

Paymaster (Gas Sponsorship)

Setup paymaster for sponsored or alternative gas token transactions:

typescript
import { PaymasterRpc, Account } from 'starknet';

const paymaster = new PaymasterRpc({ nodeUrl: 'https://sepolia.paymaster.avnu.fi' });
const account = new Account({ provider, address, signer: privateKey, paymaster });

Sponsored (dApp pays gas):

typescript
const tx = await account.executePaymasterTransaction(calls, { feeMode: { mode: 'sponsored' } });

Alternative token (e.g., USDC):

typescript
import type { PaymasterDetails } from 'starknet';
const tokens = await account.paymaster.getSupportedTokens();
const feeDetails: PaymasterDetails = { feeMode: { mode: 'default', gasToken: USDC_ADDRESS } };
const estimate = await account.estimatePaymasterTransactionFee(calls, feeDetails);
const tx = await account.executePaymasterTransaction(calls, feeDetails, estimate.suggested_max_fee_in_gas_token);

Message Signing (SNIP-12)

typescript
const typedData = {
  types: {
    StarknetDomain: [
      { name: 'name', type: 'shortstring' },
      { name: 'version', type: 'shortstring' },
      { name: 'chainId', type: 'shortstring' },
      { name: 'revision', type: 'shortstring' }
    ],
    Message: [{ name: 'content', type: 'shortstring' }]
  },
  primaryType: 'Message',
  domain: { name: 'MyDapp', version: '1', chainId: 'SN_SEPOLIA', revision: '1' },
  message: { content: 'Hello Starknet' }
};

const signature = await account.signMessage(typedData);
const msgHash = await account.hashMessage(typedData);
// Verify via the account contract's is_valid_signature (works for any account type)
const isValid = await provider.verifyMessageInStarknet(typedData, signature, account.address);

CallData & Cairo Types

typescript
import { CallData, cairo, byteArray, CairoCustomEnum, CairoOption, CairoOptionVariant } from 'starknet';

// Compile with ABI
const calldata = new CallData(abi);
const compiled = calldata.compile('transfer', { recipient: '0x...', amount: cairo.uint256(1000n) });

// Cairo type helpers - always use BigInt (n suffix) for token amounts
cairo.uint256(1000n)          // { low, high } - ALWAYS use BigInt for precision
cairo.felt('0x123')           // felt252 as a decimal string ('291'); throws outside [0, P)
byteArray.byteArrayFromString('Hello')  // ByteArray for long strings
// Cairo bool: pass true / false directly

// Short strings (<= 31 chars)
import { shortString } from 'starknet';
shortString.encodeShortString('hello')  // felt252
shortString.decodeShortString('0x...')  // 'hello'

// Enums and Options
const myEnum = new CairoCustomEnum({ Variant1: { value: 123 } });
const some = new CairoOption(CairoOptionVariant.Some, value);

Important: Always use BigInt (e.g., 1000n) for token amounts and balances. Never use Number() or parseFloat() on wei values -- JavaScript numbers lose precision above 2^53.

ERC-20 Token Operations

typescript
const erc20 = new Contract({ abi: erc20Abi, address: tokenAddress, providerOrAccount: account });

// Read balance (returns BigInt - do NOT convert with Number())
const balance = await erc20.balanceOf(account.address);
console.log('Balance (wei):', balance.toString());

// Transfer (use BigInt for amount)
const amount = 10n ** 18n; // 1 token (18 decimals)
const tx = await erc20.transfer(recipientAddress, cairo.uint256(amount));
await provider.waitForTransaction(tx.transaction_hash);

// Approve + transferFrom pattern
await erc20.approve(spenderAddress, cairo.uint256(amount));

Utility Functions

typescript
import { stark, ec, encode, num, hash } from 'starknet';

// Key generation
const privateKey = '0x' + encode.buf2hex(ec.starkCurve.utils.randomPrivateKey());
const publicKey = ec.starkCurve.getStarkKey(privateKey);

// Number conversions
num.toHex(123);           // '0x7b'
num.toBigInt('0x7b');     // 123n

// Hashing
hash.getSelectorFromName('transfer');
hash.calculateContractAddressFromHash(salt, classHash, calldata, deployer);

Contract Deployment

typescript
// Deploy via UDC
const { transaction_hash, contract_address } = await account.deploy({
  classHash: '0x...',
  constructorCalldata: CallData.compile({ owner: account.address }),
  salt: stark.randomAddress(), // random felt252 salt (not a private key)
  unique: true
});

// Declare first, then deploy
const declareResponse = await account.declare({
  contract: compiledSierra,
  casm: compiledCasm
});
await provider.waitForTransaction(declareResponse.transaction_hash);

const deployResponse = await account.deploy({
  classHash: declareResponse.class_hash,
  constructorCalldata: CallData.compile({ owner: account.address })
});

// Or combined
const result = await account.declareAndDeploy({
  contract: compiledContract,
  casm: compiledCasm,
  constructorCalldata: CallData.compile({ owner: account.address })
});

Outside Execution (SNIP-9)

Execute transactions on behalf of another account (gasless/delegated):

typescript
import { OutsideExecutionVersion } from 'starknet';
const version = await account.getSnip9Version();  // OutsideExecutionVersion: '0' | '1' | '2'

const outsideTransaction = await account.getOutsideTransaction(
  { caller: executorAddress, execute_after: now, execute_before: now + 3600 },
  calls,
  OutsideExecutionVersion.V2
);

// Executor submits the pre-signed transaction
const result = await executorAccount.executeFromOutside(outsideTransaction);

Error Handling

typescript
import { LibraryError, RpcError } from 'starknet';

try {
  const tx = await account.execute(calls);
} catch (error) {
  if (error instanceof RpcError) {
    console.error('RPC error:', error.code, error.message);
  } else if (error instanceof LibraryError) {
    console.error('Library error:', error.message);
  }
}

Logging & Configuration

typescript
import { config, logger } from 'starknet';

// Global config (v10 only sends V3 transactions)
config.set('defaultTipType', 'p90Tip');   // tip applied when execute() gets no `tip`
config.get('resourceBoundsOverhead');     // margin added to estimated resource bounds
logger.setLogLevel('DEBUG');  // DEBUG | INFO | WARN | ERROR | FATAL | OFF

Bundled files

The model reads these on demand while the skill is loaded. They are exposed as readable files and are never executed.

Frequently asked questions

What does the Starknet Js AI skill do?

Reference for building Starknet applications using starknet.js v10 SDK, including contract interaction, account management, transaction handling, fee estimation, wallet integration, and paymaster flows.

Why use Starknet Js on TypingMind?

Because you install it once and use it with any model. Starknet Js is plain Markdown rather than provider-specific code, so the same skill runs on GPT-5, Claude, Gemini, Grok, or a local model — and you can switch model mid-chat without it breaking. TypingMind runs on your own API keys, so you pay providers directly instead of a per-seat subscription, and your skills and chats stay in your own storage.

How do I install Starknet Js in TypingMind?

Open Plugins → Skills → Install from GitHub in TypingMind and paste https://github.com/keep-starknet-strange/starknet-agentic/tree/main/skills/starknet-js. TypingMind reads its SKILL.md and bundles its files and installs it as a skill you can enable per chat.

Which AI models can use Starknet Js?

Any model you connect in TypingMind. AI skills are plain Markdown instructions rather than provider-specific code, so GPT, Claude, Gemini, Grok, and local models can all load this skill when a request matches it.

How many AI models can I use with Starknet Js?

As many as you like. As long as a model supports skills, you can use Starknet Js with it — GPT, Claude, Gemini, Grok, DeepSeek, Mistral, Llama and more — all on TypingMind with your own API keys.

Is the Starknet Js AI skill free?

Yes. It is published on GitHub by keep-starknet-strange under the Apache-2.0 license. You only pay your own AI provider for the tokens you use.

What are AI skills?

An AI skill is a reusable instruction bundle that teaches an AI model how to do one specific task. It follows the open Agent Skills format: a SKILL.md file with a name and description, plus any scripts, templates or reference files the model may need. The model reads the instructions only when your request matches the skill, so an installed skill costs nothing until it is used.

How are AI skills different from plugins or MCP servers?

A plugin or MCP server gives a model new tools to call — code that runs somewhere and returns a result. An AI skill gives the model knowledge and process instead: how to approach a task, which steps to follow, what good output looks like. Skills are plain Markdown, so they need no server, no API key and no runtime, and they work with any model.

View all

Set up your own AI workspace now

Get notified about new features and future giveaways by subscribing to our newsletter 👇