@cedra-labs/ts-sdk
v2.2.8
Published
Cedra TypeScript SDK
Readme
TypeScript SDK for Cedra
The TypeScript SDK allows you to connect, explore, and interact with the Cedra blockchain. You can use it to request data, send transactions, set up test environments, and more!
Prerequisites
- Node.js: Version 16.0 or higher
- npm/yarn/pnpm: A package manager for installing dependencies
- TypeScript (optional): For TypeScript projects, ensure your
tsconfig.jsonuses"moduleResolution": "node"
Essential Links
- Cedra Documentation - Official Cedra blockchain documentation
- Code Examples - Practical code examples for common tasks
- NPM Package - Latest SDK version and stats
- GitHub Repository - Source code and issues
- Discord Community - Get help and connect with developers
Network Information
| Network | RPC Endpoint | Chain ID | Faucet |
|---------|-------------|----------|--------|
| Testnet | https://testnet.cedra.dev/v1 | TBD | Available via CLI |
| Mainnet | Coming Soon | TBD | N/A |
| Devnet | https://devnet.cedra.dev/v1 | TBD | Available via CLI |
Installation
For use in Node.js or a web application
Install with your favorite package manager such as npm, yarn, or pnpm:
pnpm install @cedra-labs/ts-sdkFor use in a browser (<= version 1.9.1 only)
You can add the SDK to your web application using a script tag:
<script src="https://unpkg.com/@cedra-labs/ts-sdk/dist/browser/index.global.js"></script>Then, the SDK can be accessed through window.cedraSDK.
Quick Start for Newcomers
Follow these steps to connect to Cedra blockchain and make your first transaction:
Step 1: Install the SDK
npm install @cedra-labs/ts-sdk
# or
yarn add @cedra-labs/ts-sdk
# or
pnpm install @cedra-labs/ts-sdkStep 2: Connect to the Network
Create an Cedra client to connect to the blockchain:
import { Cedra, CedraConfig, Network } from "@cedra-labs/ts-sdk"
// You can use CedraConfig to choose which network to connect to
const config = new CedraConfig({ network: Network.TESTNET });
// Cedra is the main entrypoint for all functions
const cedra = new Cedra(config);
// Verify connection
const ledgerInfo = await cedra.getLedgerInfo();
console.log("Connected to Cedra blockchain!");
console.log("Chain ID:", ledgerInfo.chain_id);
console.log("Latest block:", ledgerInfo.block_height);Step 3: Create Your First Account
import { Account } from "@cedra-labs/ts-sdk";
// Generate a new account
const account = Account.generate();
console.log("New account address:", account.accountAddress);
// Fund it with test tokens
await cedra.fundAccount({
accountAddress: account.accountAddress,
amount: 100_000_000, // 1 CEDRA
});Step 4: Send Your First Transaction
See the complete example in the Transfer examples section below.
Reading Data From Onchain
// Check account balance
const accountInfo = await cedra.getAccountInfo({ accountAddress: "0x123" });
console.log("Account balance:", accountInfo.coin.value);
// Get account modules
const modules = await cedra.getAccountModules({ accountAddress: "0x123" });
// Get owned tokens
const tokens = await cedra.getAccountOwnedTokens({ accountAddress: "0x123" });
// Get recent transactions
const transactions = await cedra.getAccountTransactions({ accountAddress: "0x123" });Next Steps
Learn more from the official Cedra documentation:
- Your First Transaction - Step-by-step guide to sending your first CEDRA tokens
- Build Your First Cedra App - Complete tutorial for building a full dApp on Cedra
- Smart Contract Development - Learn Move language for writing Cedra smart contracts
- CLI Installation & Usage - Set up the Cedra CLI for advanced development
Troubleshooting
TypeScript Import Errors
If you see import errors, ensure your tsconfig.json uses:
{
"compilerOptions": {
"moduleResolution": "node"
}
}Connection Issues
- Timeout errors: Increase timeout in CedraConfig or check network connectivity
- Rate limiting: Implement exponential backoff for retries
- Invalid endpoint: Verify you're using the correct network endpoint
Common Errors
INSUFFICIENT_BALANCE: Account needs more tokens. Use the faucet on testnet.SEQUENCE_NUMBER_MISMATCH: Transaction ordering issue. Fetch latest account state.MODULE_NOT_FOUND: Smart contract not deployed at specified address.
Contributing
We welcome contributions! Please:
- Check existing issues or create a new one to discuss your idea
- Fork the repository and create a pull request
- Follow our contributing guidelines
For questions or support, join our Discord community.
Running unit tests
To run a unit test in this repo, for example, the keyless end-to-end unit test in tests/e2e/api/keyless.test.ts:
pnpm jest keyless.test.ts