# casper-js-sdk

> SDK to interact with the Casper blockchain

Latest version **5.3.1** (published 2026-11-02) · Apache 2.0 license · 0 weekly downloads

## Install

```sh
npm install casper-js-sdk
pnpm add casper-js-sdk
yarn add casper-js-sdk
bun add casper-js-sdk
```

## Health

**Score 75/100 (B)** — status: active.

Positive: has types; esm support; no vulnerabilities; has provenance; recently updated; high maintenance score; high quality score.

Warnings: low downloads.

## Facts

| | |
|---|---|
| Version | 5.3.1 |
| Published | 2026-11-02 |
| First published | 2021-06-18 |
| Weekly downloads | 0 |
| License | Apache 2.0 |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Node | >=18 |
| Dependencies | 15 |
| Unpacked size | 7.4 MB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Provenance | attested (GitHub Actions) |
| GitHub stars | 74 |
| Author | Jan Hoffmann |
| Maintainers | burlachenko, michaelsteuer, davidatwhiletrue, yevhenbilov, alex_myshchyshyn, casper-sre, tvasile |
| Keywords | Casper, BlockChain, sdk |

## Links

- npm: https://www.npmjs.com/package/casper-js-sdk
- Repository: https://github.com/casper-ecosystem/casper-js-sdk
- Homepage: https://github.com/casper-ecosystem/casper-js-sdk#README.md
- Issues: https://github.com/casper-ecosystem/casper-js-sdk/issues
- npm.io page: https://npm.io/package/casper-js-sdk

## Dependencies (15)

- [axios](https://npm.io/package/axios.md) ^1.20.0
- [typedjson](https://npm.io/package/typedjson.md) ^1.8.0
- [ts-results](https://npm.io/package/ts-results.md) npm:@casperlabs/ts-results@^3.3.5
- [eventsource](https://npm.io/package/eventsource.md) ^3.0.7
- [@noble/curves](https://npm.io/package/@noble/curves.md) ^1.9.7
- [@noble/hashes](https://npm.io/package/@noble/hashes.md) ^1.8.0
- [@noble/ed25519](https://npm.io/package/@noble/ed25519.md) ^1.7.5
- [@noble/secp256k1](https://npm.io/package/@noble/secp256k1.md) ^1.7.2
- [humanize-duration](https://npm.io/package/humanize-duration.md) ^3.34.0
- [@peculiar/asn1-ecc](https://npm.io/package/@peculiar/asn1-ecc.md) ^2.8.0
- [@peculiar/asn1-x509](https://npm.io/package/@peculiar/asn1-x509.md) ^2.8.0
- [@ethersproject/bytes](https://npm.io/package/@ethersproject/bytes.md) ^5.8.0
- [@peculiar/asn1-schema](https://npm.io/package/@peculiar/asn1-schema.md) ^2.8.0
- [@ethersproject/bignumber](https://npm.io/package/@ethersproject/bignumber.md) ^5.8.0
- [@ethersproject/constants](https://npm.io/package/@ethersproject/constants.md) ^5.8.0

## Recent versions

- 5.3.1 (latest) — 2026-11-02
- 5.0.16-beta2 (condor) — 2025-03-19
- 1.4.3 (legacy) — 2021-06-18
- 5.3.0 — 2026-10-16
- 5.2.0 — 2026-10-09
- 5.1.1 — 2026-09-02
- 5.1.0 — 2026-08-11
- 5.0.13 — 2026-08-07
- 5.0.12 — 2026-04-29
- 5.0.11 — 2026-04-01
- 5.0.10 — 2026-02-24
- 5.0.9 — 2026-01-19
- 5.0.8 — 2026-01-08
- 5.0.7 — 2025-12-04
- 5.0.6 — 2025-05-01
- … 89 more at https://npm.io/package/casper-js-sdk/versions

## README

# Casper JS SDK

[![npm version](https://img.shields.io/npm/v/casper-js-sdk.svg?style=flat-square)](https://www.npmjs.com/package/casper-js-sdk) [![npm downloads](https://img.shields.io/npm/dm/casper-js-sdk.svg?style=flat-square)](https://www.npmjs.com/package/casper-js-sdk) [![License](https://img.shields.io/npm/l/casper-js-sdk.svg?style=flat-square)](https://github.com/casper-ecosystem/casper-js-sdk/blob/master/LICENSE) [![TypeScript](https://img.shields.io/badge/TypeScript-Ready-blue.svg?style=flat-square&logo=typescript)](https://www.typescriptlang.org/) [![GitHub stars](https://img.shields.io/github/stars/casper-ecosystem/casper-js-sdk.svg?style=flat-square&logo=github)](https://github.com/casper-ecosystem/casper-js-sdk) [![Build Status](https://img.shields.io/github/actions/workflow/status/casper-ecosystem/casper-js-sdk/ci.yml?style=flat-square&logo=github)](https://github.com/casper-ecosystem/casper-js-sdk/actions)

The Casper JS SDK provides a convenient way to interact with the Casper Network using JavaScript.

## Get started

```bash
# Basic Node.JS installation
npm install casper-js-sdk --save
```

## Base usage

- [Public and private keys](#public-and-private-keys)
- [RPC client](#rpc-client)
- [SSE](#sse)
- [Creating a transaction](#creating-a-transaction)
- [Creating a legacy deploy](#creating-a-legacy-deploy)
- [Creating and sending CSPR transfer deploy](#creating-and-sending-cspr-transfer-deploy)
- [Creating and sending Auction manager deploy](#creating-and-sending-auction-manager-deploy)
- [Creating and sending CEP-18 transfer deploy](#creating-and-sending-cep-18-transfer-deploy)
- [Creating and sending NFT transfer deploy](#creating-and-sending-nft-transfer-deploy)

## Migration guides

### [v2 to v5](resources/migration-guide-v2-v5.md)

## Usage examples

### Public and private keys

Provides functionality for working with public and private key cryptography in Casper. [See more details here](src/types/keypair/README.md)

```ts
import { KeyAlgorithm, PrivateKey, PublicKey } from 'casper-js-sdk';

const privateKeyAlgoritm = KeyAlgorithm.SECP256K1;

// Generate new
const privateKey = await PrivateKey.generate(privateKeyAlgoritm);

// Recreate from hex string
const privateHex = 'PRIVATE-KEY-HEX...';
const privateKeyFromHex = await PrivateKey.fromHex(
  privateHex,
  privateKeyAlgoritm
);

// Public key from PrivateKey
const publicKey = privateKey.publicKey;

// Public key from hex string
const publicKeyHex =
  '02039daee95ef2cd54a23bd201febc495dc1404bc300c572e77dc55cf8ff53ac4823';
const publicKeyFromHex = PublicKey.fromHex(publicKeyHex);
```

### RPC client

Provides access to the exported methods of RPC Client and data structures where the response is serialized. [See more details here](src/rpc/README.md)

Example:

```ts
import { HttpHandler, RpcClient } from 'casper-js-sdk';

const rpcHandler = new HttpHandler('http://<Node Address>:7777/rpc');
const rpcCient = new RpcClient(rpcHandler);
const deployHash =
  '3facbc4133e722c5c5630b6ad2331383ba849ef719da582cc026e9dd85e72ac9';

try {
  const deployResult = await rpcCient.getDeploy(deployHash);
} catch (e) {}
```

### SSE

Provides basic functionality to work with Casper events that streamed by SSE server. [See more details here](src/sse/README.md)

Example:

```ts
import { SseClient, EventName } from 'casper-js-sdk';

const sseClient = new SseClient('http://<Node Address>:9999/events');

sseClient.subscribe(EventName.BlockAddedEventType, rawEvent => {
  try {
    const parsedEvent = rawEvent.parseAsBlockAddedEvent();
    console.log(`Block hash: ${parsedEvent.BlockAdded.blockHash}`);
  } catch (error) {
    console.error('Error processing event:', error);
  }
});

// Start the client with the last known event ID ( Optional )
const lastEventID = 1234;

sseClient.start(lastEventID);
```

### Creating a transaction

Example of how to construct a transaction and push it to the network:

```ts
import {
  HttpHandler,
  RpcClient,
  NativeTransferBuilder,
  PrivateKey,
  KeyAlgorithm,
  PublicKey
} from 'casper-js-sdk';

const rpcHandler = new HttpHandler('http://<Node Address>:7777/rpc');
const rpcClient = new RpcClient(rpcHandler);

const privateKey = await PrivateKey.generate(KeyAlgorithm.ED25519);

const transaction = new NativeTransferBuilder()
  .from(privateKey.publicKey)
  .target(
    PublicKey.fromHex(
      '0202f5a92ab6da536e7b1a351406f3744224bec85d7acbab1497b65de48a1a707b64'
    )
  )
  .amount('25000000000') // Amount in motes
  .id(Date.now())
  .chainName('casper-net-1')
  .payment(100_000_000)
  .build();

transaction.sign(privateKey);

try {
  const result = await rpcClient.putTransaction(transaction);
  console.log(`Transaction Hash: ${result.transactionHash}`);
} catch (e) {
  console.error(e);
}
```

### Creating a legacy deploy

Example of how to construct a deploy and push it to the network:

```ts
import {
  Deploy,
  DeployHeader,
  ExecutableDeployItem,
  HttpHandler,
  PublicKey,
  KeyAlgorithm,
  PrivateKey,
  RpcClient,
  TransferDeployItem
} from 'casper-js-sdk';

const rpcHandler = new HttpHandler('http://<Node Address>:7777/rpc');
const rpcClient = new RpcClient(rpcHandler);

const senderKey = await PrivateKey.generate(KeyAlgorithm.ED25519);
const recipientKey = PublicKey.fromHex(
  '010068920746ecf5870e18911EE1fC5db975E0e97fFFcBBF52f5045Ad6C9838D2F'
);
const paymentAmount = '10000000000000';
const transferAmount = '10';
const transferId = 35;

const session = new ExecutableDeployItem();

session.transfer = TransferDeployItem.newTransfer(
  transferAmount,
  recipientKey,
  undefined,
  transferId
);

const payment = ExecutableDeployItem.standardPayment(paymentAmount);

const deployHeader = DeployHeader.default();
deployHeader.account = senderKey.publicKey;
deployHeader.chainName = 'casper-test';

const deploy = Deploy.makeDeploy(deployHeader, payment, session);
deploy.sign(senderKey);

const result = await rpcClient.putDeploy(deploy);

console.log(`Deploy Hash: ${result.deployHash}`);
```

### Creating and sending CSPR transfer deploy

Example of how to construct a CSPR transfer deploy and push it to the network:

```ts
import {
  HttpHandler,
  RpcClient,
  KeyAlgorithm,
  PrivateKey,
  makeCsprTransferDeploy
} from 'casper-js-sdk';

// get private key fromHex, fromPem or generate it
const privateKey = await PrivateKey.fromHex(
  'privateKeyHex',
  KeyAlgorithm.SECP256K1 // or KeyAlgorithm.ED25519, depends on your private key
);

const deploy = makeCsprTransferDeploy({
  senderPublicKeyHex: privateKey.publicKey.toHex(),
  recipientPublicKeyHex: '0123456789abcdef...',
  transferAmount: '2500000000' // 2.5 CSPR
});

deploy.sign(privateKey);

const rpcHandler = new HttpHandler('http://<Node Address>:7777/rpc');
const rpcClient = new RpcClient(rpcHandler);

const result = await rpcClient.putDeploy(deploy);

console.log(`Deploy Hash: ${result.deployHash}`);
```

### Creating and sending Auction manager deploy

Example of how to construct a Auction manager deploy (delegate/undelegate/redelegate CSPR) and push it to the network:

```ts
import {
  HttpHandler,
  RpcClient,
  KeyAlgorithm,
  PrivateKey,
  makeAuctionManagerDeploy,
  AuctionManagerEntryPoint
} from 'casper-js-sdk';

// get private key fromHex, fromPem or generate it
const privateKey = await PrivateKey.fromHex(
  'privateKeyHex',
  KeyAlgorithm.SECP256K1 // or KeyAlgorithm.ED25519, depends on your private key
);

const deploy = makeAuctionManagerDeploy({
  contractEntryPoint: AuctionManagerEntryPoint.delegate,
  delegatorPublicKeyHex: privateKey.publicKey.toHex(),
  validatorPublicKeyHex: '0123456789awedef...',
  amount: '500000000000' // 500 CSPR
});

deploy.sign(privateKey);

const rpcHandler = new HttpHandler('http://<Node Address>:7777/rpc');
const rpcClient = new RpcClient(rpcHandler);

const result = await rpcClient.putDeploy(deploy);

console.log(`Deploy Hash: ${result.deployHash}`);
```

### Creating and sending CEP-18 transfer deploy

Example of how to construct a CEP-18 transfer deploy and push it to the network:

```ts
import {
  HttpHandler,
  RpcClient,
  KeyAlgorithm,
  PrivateKey,
  makeCep18TransferDeploy
} from 'casper-js-sdk';

// get private key fromHex, fromPem or generate it
const privateKey = await PrivateKey.fromHex(
  'privateKeyHex',
  KeyAlgorithm.SECP256K1 // or KeyAlgorithm.ED25519, depends on your private key
);

const deploy = await makeCep18TransferDeploy({
  contractHash: '0123456789asdfbcdef...',
  senderPublicKeyHex: '0123456789asdfbcdef...',
  recipientPublicKeyHex: '0123456789abcdef...',
  transferAmount: '25000000000', // 25 CEP-18 with 9 decimals
  paymentAmount: '3000000000' // 3 CSPR
});

deploy.sign(privateKey);

const rpcHandler = new HttpHandler('http://<Node Address>:7777/rpc');
const rpcClient = new RpcClient(rpcHandler);

const result = await rpcClient.putDeploy(deploy);

console.log(`Deploy Hash: ${result.deployHash}`);
```

### Creating and sending NFT transfer deploy

Example of how to construct a NFT transfer deploy and push it to the network:

```ts
import {
  HttpHandler,
  RpcClient,
  KeyAlgorithm,
  PrivateKey,
  makeNftTransferDeploy,
  NFTTokenStandard
} from 'casper-js-sdk';

// get private key fromHex, fromPem or generate it
const privateKey = await PrivateKey.fromHex(
  'privateKeyHex',
  KeyAlgorithm.SECP256K1 // or KeyAlgorithm.ED25519, depends on your private key
);

const deploy = await makeNftTransferDeploy({
  nftStandard: NFTTokenStandard.CEP47,
  contractPackageHash: '0123456789asdfbcdef...',
  senderPublicKeyHex: '0123456789asdfbcdef...',
  recipientPublicKeyHex: '0123456789abcdef...',
  paymentAmount: '3000000000', // 3 CSPR
  tokenId: 234
});

deploy.sign(privateKey);

const rpcHandler = new HttpHandler('http://<Node Address>:7777/rpc');
const rpcClient = new RpcClient(rpcHandler);

const result = await rpcClient.putDeploy(deploy);

console.log(`Deploy Hash: ${result.deployHash}`);
```

## Contributing

Clone and set up with:

```bash
npm run setup
```

Not `npm install` on its own. `.npmrc` sets `ignore-scripts=true`, so npm runs no dependency lifecycle script during an install — a malicious `postinstall` in any package in the tree is the most direct supply-chain attack there is, and it needs no cooperation from this repo's code. `npm run setup` installs, then runs only the scripts allowlisted under `lavamoat.allowScripts` in `package.json` (currently none), then installs the git hooks. `@lavamoat/preinstall-always-fail` fails the install loudly if that protection is ever switched back off.

The same flag means npm no longer runs `pre`/`post` scripts around a task, so package.json scripts chain their steps explicitly — `build` calls `clean` and `lint` itself rather than relying on a `prebuild` hook. Add new steps the same way; a `pre<task>` script here would silently never run.

---
_Source: https://npm.io/package/casper-js-sdk · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
