Reference for building Starknet applications using starknet.js v9.x SDK, including contract interaction, account management, transaction handling, fee estimation, wallet integration, and paymaster flows.
Standardmäßig ist der Prompt ausgewählt, der zuerst die Quelle prüft. Sie können zu einem direkten Befehl wechseln oder eine lokale Kopie herunterladen.
Quelldateien prüfen
Lesen Sie SKILL.md und alle von SkillsMP angezeigten Begleitdateien, bevor Sie sich für eine Installation entscheiden.
Mit Codex oder Claude installieren Kopieren Sie diesen Prompt, fügen Sie ihn in Codex, Claude oder einen anderen Assistant ein und lassen Sie die Skill-Seite prüfen und installieren.
Ein direkter Befehl überspringt den Prüf-Prompt. Prüfen Sie die Quelle, bevor Sie ihn ausführen.
Reference for building Starknet applications using starknet.js v9.x SDK, including contract interaction, account management, transaction handling, fee estimation, wallet integration, and paymaster flows.
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'; // exampleconst constructorCalldata = CallData.compile({ publicKey });
const address = hash.calculateContractAddressFromHash(publicKey, classHash, constructorCalldata, 0);
Step 2: Fund the address with STRK before deployment.
Step 3: Deploy
import { Account } from'starknet';
// NOTE: Account constructor signature varies across starknet.js versions.// If this doesn't typecheck for your version, refer to the official docs.const account = newAccount({ provider, address, signer: privateKey, cairoVersion: '1' });
const { transaction_hash } = await account.deployAccount({
classHash,
constructorCalldata,
addressSalt: publicKey
});
await provider.waitForTransaction(transaction_hash);
// Get full TypeScript autocomplete and type checking from ABIconst typedContract = contract.typedv2(abi);
const balance = await typedContract.balanceOf(userAddress);
import { CallData, cairo, CairoCustomEnum, CairoOption, CairoOptionVariant } from'starknet';
// Compile with ABIconst calldata = newCallData(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.felt252(1000) // BigInt
cairo.felt('0x123') // hex to felt
cairo.bool(true) // Cairo bool
cairo.byteArray('Hello') // ByteArray for long strings// Short strings (<= 31 chars)import { shortString } from'starknet';
shortString.encodeShortString('hello') // felt252
shortString.decodeShortString('0x...') // 'hello'// Enums and Optionsconst myEnum = newCairoCustomEnum({ Variant1: { value: 123 } });
const some = newCairoOption(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.