A JavaScript/TypeScript SDK for interacting with Self Crypto names and their metadata.
npm install @selfcrypto/sdk ethers@5.7.2or
yarn add @selfcrypto/sdk ethers@5.7.2or
pnpm add @selfcrypto/sdk ethers@5.7.2import { SelfSDK } from "@selfcrypto/sdk";
const sdk = new SelfSDK();
// Resolve a name to its BSC address
const address = await sdk.resolveName("ricomaverick");
console.log(address); // 0x383D8ee00c3Ea31dd4eb6e5eCf649Bc9C08D8e31
// Get cross-chain address
const ethAddress = await sdk.resolveCrossChain("ricomaverick", "eth");
console.log(ethAddress); // 0x383D8ee00c3Ea31dd4eb6e5eCf649Bc9C08D8e31
// Get complete metadata
const metadata = await sdk.resolveMetadata("ricomaverick");
console.log(metadata);You can customize the SDK with your own RPC URL and IPFS gateway:
const sdk = new SelfSDK({
rpcUrl: "https://your-rpc-url",
ipfsGateway: "https://your-ipfs-gateway/ipfs/"
});Resolves a SELF name to default address i.e owner of the name(NFT).
Resolves a SELF name to its address on a specific chain.
Resolves a SELF name to its metadata.
The metadata includes:
- Name
- Description
- Profile image
- Email (if available)
- Cross-chain addresses
Utility method to hash a name.
Utility method to validate a name.
interface ResolverOptions {
rpcUrl?: string;
ipfsGateway?: string;
}
interface Metadata {
name: string;
description: string;
image: string;
email?: string;
foreignAddresses: {
[key in ChainIntegrationKey]?: {
address: string;
};
};
}
type ChainIntegrationKey = "eth" | "bsc" | "btc" | /* ... other chains ... */;The SDK throws errors in these cases:
- Invalid name format
- Non-existent name
- Network errors
- Invalid RPC URL
- Failed metadata resolution
- EVM:
eth,bsc,polygon,avax,arb - Non-EVM:
btc,ltc,xmr,trx,nim,ada,sol,xlm,xrp,eos,klv,dot - Other:
bnb,strk
The following features are planned for future releases:
hasChainAddress()- Check if name has an address for a specific chaingetConfiguredChains()- Get all chains with configured addressesgetSummary()- Get a quick summary of name metadatagetDescription()- Get name descriptiongetEmail()- Get associated emailgetImage()- Get profile image URL
- Node.js 16+
- pnpm (
npm install -g pnpm)
# Install dependencies
pnpm install# Watch mode - rebuilds on file changes
pnpm dev
# Run tests
pnpm test
# Run tests in watch mode
pnpm test:watch
# Type checking
pnpm lint# Build the package
pnpm buildThis package uses changesets for versioning and publishing.
# Create a new changeset
pnpm changeset
# Push your changes
git push origin mainThe publishing process is automated through GitHub Actions:
-
After pushing changes with a changeset:
- GitHub Actions will build and test the code
- If tests pass, it creates a "Version Packages" PR
- The PR includes version bumps and CHANGELOG updates
-
When the PR is merged:
- GitHub Actions automatically publishes to npm
- Creates a new git tag
- Updates the CHANGELOG.md
Note: Make sure your changes include a changeset file (created with
pnpm changeset) describing the changes. This is required for the automated release process.
NPM_TOKEN- Required for publishing to npm
src/
├── constants/ # Constants and configuration
├── resolvers/ # Core resolver implementations
├── types/ # TypeScript type definitions
├── utils/ # Internal utilities
└── index.ts # Main entry point
Tests are written using Jest. Each resolver has its own test file in a __tests__ directory.
src/
├── resolvers/
│ ├── __tests__/
│ │ ├── nameResolver.test.ts
│ │ ├── metadataResolver.test.ts
│ │ └── integration.test.ts
└── utils/
└── __tests__/
└── utils.test.ts