Starknet js

Starknet.js offers integrated support for Starknet ID, enabling you to easily retrieve stark names and addresses.

🔗 View the source code on GitHub (opens in a new tab)

Installation

You can install Starknet.js using npm. You have two options:

# use the main branch
 
npm install starknet
 
# to use latest features (merges in develop branch)
 
npm install starknet@next

Usage

You can access the Starknet ID functions directly via the Provider class.

Functions

getStarkName

This function retrieves the stark name corresponding to a given address.

getStarkName(address, StarknetIdContract?): Promise<string>

Parameters

NameTypeDescription
addressBigNumberish (opens in a new tab)The address to query
StarknetIdContract?stringOptional naming contract address

Returns

Promise<string>

Defined in

src/provider/extensions/starknetId.ts:21 (opens in a new tab)

Example usage

import { Provider, constants } from "starknet";
 
const provider = new Provider({
  sequencer: { network: constants.NetworkName.SN_MAIN },
});
 
const name = await provider.getStarkName(address ?? "");

getAddressFromStarkName

This function retrieves the address corresponding to a given stark name.

getAddressFromStarkName(name, StarknetIdContract?): Promise<string>

Parameters

NameTypeDescription
namestringThe starkname to query
StarknetIdContract?stringOptional naming contract address

Returns

Promise<string>

Defined in

src/provider/extensions/starknetId.ts:30 (opens in a new tab)

Example usage

import { Provider, constants } from "starknet";
 
const provider = new Provider({
  sequencer: { network: constants.NetworkName.SN_MAIN },
});
 
const address = await provider.getAddressFromStarkName("fricoben.stark");

getStarkProfile

This function retrieves the stark profile corresponding to a given address. This function retrieves a user's starkname, profile picture URL, social networks IDs, and proof of personhood verification status. If no specific verifiers are provided, it defaults to using the Starknet ID verifiers contract addresses.

getStarkProfile(address, StarknetIdContract?, StarknetIdIdentityContract?, StarknetIdVerifierContract?, StarknetIdPfpContract?, StarknetIdPopContract?, StarknetIdMulticallContract?): Promise<StarkProfile (opens in a new tab)>

Parameters

NameTypeDescription
addressBigNumberish (opens in a new tab)The address to query
StarknetIdContract?stringOptional naming contract address
StarknetIdIdentityContract?stringOptional identity contract address
StarknetIdVerifierContract?stringOptional verifier contract address
StarknetIdPfpContract?stringOptional profile picture verifier contract address
StarknetIdPopContract?stringOptional proof of personhood contract address
StarknetIdMulticallContract?stringOptional composable multicall contract address

Returns

Promise<StarkProfile (opens in a new tab)>

Defined in

src/provider/extensions/starknetId.ts:39 (opens in a new tab)

Example usage

import { Provider, constants } from "starknet";
 
const provider = new Provider({
  sequencer: { network: constants.NetworkName.SN_MAIN },
});
 
const profile = await provider.getStarkProfile(address);

Utils

The starknetId namespace in starknet.js provides utility functions for encoding and decoding stark names and addresses.

useDecoded

This function decodes a stark name from a given BigInt array.

useDecoded(encoded): string

Parameters

NameTypeDescription
encodedbigint[]BigInt array representing the domain

Returns

string : The decoded stark name

Defined in

src/utils/starknetId.ts:23 (opens in a new tab)

Example usage

import { starknetId } from "starknet";
 
const decodedDomain = starknetId.useDecoded([BigInt(1499554868251)]);
console.log(decodedDomain); // Output: fricoben.stark

useEncoded

Encodes a domain name into a BigInt. Note: Exclude the .stark suffix when passing the domain name.

useEncoded(decoded): bigint

Parameters

NameTypeDescription
decodedstringThe domain name to be encoded

Returns

bigint : The encoded BigInt value

Defined in

src/utils/starknetId.ts:64 (opens in a new tab)

Example usage

import { starknetId } from "starknet";
 
const encoded = starknetId.useEncoded("fricoben);
console.log(encoded); // Output: 1499554868251n

getStarknetIdContract

Retrieves the address of the Starknet ID naming contract based on the chain ID.

getStarknetIdContract(chainId): string

Parameters

NameTypeDescription
chainIdStarknetChainIdThe chain ID to query against

Returns

string : The address of the naming contract

**Defined in

src/utils/starknetId.ts:112 (opens in a new tab)

Example usage

import { starknetId, constants } from "starknet";
 
const namingContract = starknetId.getStarknetIdContract(
  constants.StarknetChainId.SN_MAIN
);
console.log(namingContract); // Output: 0x6ac597f8116f886fa1c97a23fa4e08299975ecaf6b598873ca6792b9bbfb678

getStarknetIdIdentityContract

Retrieves the address of the Starknet ID identity contract based on the chain ID.

getStarknetIdIdentityContract(chainId): string

Parameters

NameTypeDescription
chainIdStarknetChainIdThe chain ID to query against

Returns

string : The address of the identity contract

**Defined in

src/utils/starknetId.ts:134 (opens in a new tab)

Example usage

import { starknetId, constants } from "starknet";
 
const identityContract = starknetId.getStarknetIdContract(
  constants.StarknetChainId.SN_MAIN
);
console.log(identityContract); // Output: 0x05dbdedc203e92749e2e746e2d40a768d966bd243df04a6b712e222bc040a9af

getStarknetIdMulticallContract

Retrieves the address of the Starknet ID composable multicall contract based on the chain ID.

getStarknetIdMulticallContract(chainId): string

Parameters

NameTypeDescription
chainIdStarknetChainIdThe chain ID to query against

Returns

string : The address of the composable multicall contract

**Defined in

src/utils/starknetId.ts:134 (opens in a new tab)

Example usage

import { starknetId, constants } from "starknet";
 
const multicallContract = starknetId.getStarknetIdMulticallContract(
  constants.StarknetChainId.SN_MAIN
);
console.log(multicallContract); // Output: 0x034ffb8f4452df7a613a0210824d6414dbadcddce6c6e19bf4ddc9e22ce5f970

getStarknetIdVerifierContract

Retrieves the address of the Starknet ID verifier contract used to verify social networks, based on the chain ID.

getStarknetIdVerifierContract(chainId): string

Parameters

NameTypeDescription
chainIdStarknetChainIdThe chain ID to query against

Returns

string : The address of the verifier contract

**Defined in

src/utils/starknetId.ts:175 (opens in a new tab)

Example usage

import { starknetId, constants } from "starknet";
 
const verifierContract = starknetId.getStarknetIdVerifierContract(
  constants.StarknetChainId.SN_MAIN
);
console.log(verifierContract); // Output: 0x07d14dfd8ee95b41fce179170d88ba1f0d5a512e13aeb232f19cfeec0a88f8bf

getStarknetIdPfpContract

Retrieves the address of the Starknet ID profile picture verifier contract based on the chain ID.

getStarknetIdPfpContract(chainId): string

Parameters

NameTypeDescription
chainIdStarknetChainIdThe chain ID to query against

Returns

string : The address of the profile picture verifier contract

**Defined in

src/utils/starknetId.ts:197 (opens in a new tab)

Example usage

import { starknetId, constants } from "starknet";
 
const pfpVerifierContract = starknetId.getStarknetIdPfpContract(
  constants.StarknetChainId.SN_MAIN
);
console.log(pfpVerifierContract); // Output: 0x070aaa20ec4a46da57c932d9fd89ca5e6bb9ca3188d3df361a32306aff7d59c7

getStarknetIdPopContract

Retrieves the address of the Starknet ID proof of personhood verifier contract based on the chain ID.

getStarknetIdPopContract(chainId): string

Parameters

NameTypeDescription
chainIdStarknetChainIdThe chain ID to query against

Returns

string : The address of the proof of personhood contract

**Defined in

src/utils/starknetId.ts:221 (opens in a new tab)

Example usage

import { starknetId, constants } from "starknet";
 
const popVerifierContract = starknetId.getStarknetIdPopContract(
  constants.StarknetChainId.SN_MAIN
);
console.log(popVerifierContract); // Output: 0x0293eb2ba9862f762bd3036586d5755a782bd22e6f5028320f1d0405fd47bff4