2. Getting Started
This page covers installation, project setup, connecting to a node, and a first query and transaction.
Installation
Install the SDK with your package manager:
# npm
npm install @amadeus-protocol/sdk
# yarn
yarn add @amadeus-protocol/sdk
# pnpm
pnpm add @amadeus-protocol/sdk
# bun
bun add @amadeus-protocol/sdk
Check the installed version
npm list @amadeus-protocol/sdk
From code:
import { AmadeusSDK, SDK_VERSION } from '@amadeus-protocol/sdk'
console.log(AmadeusSDK.getVersion()) // '1.8.0'
console.log(SDK_VERSION) // same value
Requirements
Node.js
The SDK requires Node.js 20 or later ("engines": { "node": ">=20.0.0" }).
node --version
ESM-only package
The SDK is published as pure ESM ("type": "module"). It has no CommonJS build, and its exports map has an import entry but no require entry.
- Node.js projects: set
"type": "module"inpackage.json, or use the.mjsextension for entry files. - TypeScript: use
"module": "NodeNext"with"moduleResolution": "NodeNext", or"moduleResolution": "Bundler"if a bundler builds your code. See TypeScript configuration. - Browser bundlers (Vite, webpack, esbuild): no extra configuration. React Native (Metro) needs some; see Browsers and other runtimes.
Calling require('@amadeus-protocol/sdk') from CommonJS fails with ERR_PACKAGE_PATH_NOT_EXPORTED (No "exports" main defined). If you cannot move the project to ESM, load the SDK with a dynamic import(), which works from CommonJS:
// index.cjs
async function main() {
const { AmadeusSDK } = await import('@amadeus-protocol/sdk')
console.log(AmadeusSDK.getVersion())
}
main()
You can also run a TypeScript entry file with tsx (npx tsx index.ts) in a project that has "type": "module".
Versions 1.0.x had a packaging bug that caused ERR_MODULE_NOT_FOUND under plain node; it was fixed in 1.1.0. Install 1.8.0. See Troubleshooting for details.
Browsers and other runtimes
The SDK needs these platform APIs, all available in current browsers and in Node.js 20+:
fetchandAbortControllerfor node requestscrypto.getRandomValuesfor key generationcrypto.subtle(Web Crypto) for password encryptionTextEncoder/TextDecoderbtoa/atobfor Base64 when Node.jsBufferis not available
React Native has neither crypto.getRandomValues nor crypto.subtle built in, and Metro must resolve the package exports map. The Amadeus mobile wallet sets config.resolver.unstable_enablePackageExports = true in metro.config.js, loads react-native-get-random-values before the SDK, and installs its own crypto.subtle polyfill for encryption.
Connect to a node
new AmadeusSDK() with no arguments connects to mainnet at https://mainnet-rpc.ama.one/api with a 30-second request timeout. Pass baseUrl to use testnet or your own node:
import { AmadeusSDK } from '@amadeus-protocol/sdk'
// Mainnet with defaults (30 s timeout)
const sdk = new AmadeusSDK()
// Testnet, with an explicit timeout in milliseconds
const testnet = new AmadeusSDK({
baseUrl: 'https://testnet-rpc.ama.one/api',
timeout: 30000
})
console.log(sdk.getConfig().baseUrl) // https://mainnet-rpc.ama.one/api
console.log(testnet.getConfig().baseUrl) // https://testnet-rpc.ama.one/api
| Network | baseUrl | Explorer |
|---|---|---|
| Mainnet (default) | https://mainnet-rpc.ama.one/api | explorer.ama.one |
| Testnet | https://testnet-rpc.ama.one/api | testnet.explorer.ama.one |
Reading from testnet only needs the testnet baseUrl. Sending a testnet transaction also needs testnet signing: create the builder with new TransactionBuilder(privateKey, { network: NetworkType.TESTNET }), because it signs for mainnet by default. See Networks and testnet, which also covers the faucet.
Your first query
Read the chain tip and chain statistics:
import { AmadeusSDK } from '@amadeus-protocol/sdk'
const sdk = new AmadeusSDK()
const tip = await sdk.chain.getTip()
console.log('Height:', tip.entry.header.height)
console.log('Hash:', tip.entry.hash)
console.log('Finalized:', tip.entry.consensus?.finality_reached ?? false)
const { stats } = await sdk.chain.getStats()
console.log('Rooted height:', stats.rooted_height)
console.log('Mempool size:', stats.tx_pool_size)
Output looks like this:
Height: 90324142
Hash: 2qQ9PsGaZTNxTn3YsiY9n5xb2YmnxfX3y3fPbkAPc1c5
Finalized: false
Rooted height: 90324140
Mempool size: 2
The height lives at entry.header.height; there is no top-level entry.height.
Check a balance
import { AmadeusSDK } from '@amadeus-protocol/sdk'
const sdk = new AmadeusSDK()
const address = '6969GaCysicYUFd6JQhxG1QPwRvXdTGtWVCCAEgM6Kq1jcSMX7RySrSFU9WRHWbJyE'
const { balance } = await sdk.wallet.getBalance(address, 'AMA')
console.log(balance.float, balance.symbol) // human-readable amount
console.log(balance.flat) // atomic units (9 decimals)
Your first transaction
Sending a transaction needs the sender's seed: the Base58 private key of the account, for example from generateKeypair() or a recovery phrase. The account must hold the amount plus at least 0.01 AMA: every transaction locks a 0.01 AMA budget and refunds what it does not use. A plain transfer costs a fraction of that (see Transaction fees).
import { AmadeusSDK, TransactionBuilder, AmadeusSDKError } from '@amadeus-protocol/sdk'
const sdk = new AmadeusSDK()
// Base58 seed of the sending account; never commit it or ship it to a browser
const privateKey = '<your Base58 seed>'
const builder = new TransactionBuilder(privateKey)
const { txHash, txPacked } = builder.transfer({
recipient: '<recipient address>',
amount: 10.5, // AMA, converted to atomic units for you
symbol: 'AMA'
})
console.log('Transaction hash:', txHash)
try {
const { hash } = await sdk.transaction.submit(txPacked)
console.log('Submitted:', hash)
} catch (error) {
if (error instanceof AmadeusSDKError) {
console.error('Rejected:', error.message, error.status)
} else {
throw error
}
}
submit resolves with { hash } once the node accepts the transaction, and throws AmadeusSDKError when the node rejects it. The response has no error field to check: the SDK removes the node's error: 'ok' on success.
To wait until the transaction is in an entry and get its receipt, use submitAndWait:
import { AmadeusSDK, TransactionBuilder } from '@amadeus-protocol/sdk'
const sdk = new AmadeusSDK()
const builder = new TransactionBuilder('<your Base58 seed>')
const { txPacked } = builder.transfer({ recipient: '<recipient address>', amount: 1, symbol: 'AMA' })
// Resolves once the transaction is in an entry
const { hash, metadata, receipt } = await sdk.transaction.submitAndWait(txPacked)
console.log(hash, metadata.entry_height, metadata.status, receipt.success)
Pass { finalized: true } to wait for finality instead. Core Concepts explains the difference.
TypeScript configuration
For a Node.js project, set "type": "module" in package.json and use:
{
"compilerOptions": {
"target": "ES2022",
"module": "NodeNext",
"moduleResolution": "NodeNext",
"strict": true,
"outDir": "dist"
},
"include": ["src"]
}
With "module": "NodeNext" and "type": "module" you can use top-level await, as the samples on these pages do. If a bundler (Vite, webpack, esbuild) builds your code, use "module": "ESNext" with "moduleResolution": "Bundler" instead.
Common imports
// Client and transactions
import { AmadeusSDK, AmadeusSDKError, TransactionBuilder } from '@amadeus-protocol/sdk'
// Keys and recovery phrases
import {
generateKeypair,
derivePublicKeyFromSeedBase58,
generateMnemonic,
validateMnemonic,
mnemonicToSeedBase58
} from '@amadeus-protocol/sdk'
// Networks and network-bound signing
import { NetworkType, NETWORK_URLS, signContractCall, buildCoinTransfer } from '@amadeus-protocol/sdk'
// Encoding, amounts and validation
import { toBase58, fromBase58, toAtomicAma, fromAtomicAma, isValidAddress } from '@amadeus-protocol/sdk'
// Contracts
import { createContract, NFT_ABI, LOCKUP_PRIME_ABI } from '@amadeus-protocol/sdk'
// Encryption at rest
import { encryptWithPassword, decryptWithPassword } from '@amadeus-protocol/sdk'
Troubleshooting installation
Cannot find module '@amadeus-protocol/sdk'
-
Check that the package is installed and that
package.jsonasks for the current version:{"dependencies": {"@amadeus-protocol/sdk": "^1.8.0"}} -
Reinstall from a clean state:
rm -rf node_modules package-lock.jsonnpm install
ERR_PACKAGE_PATH_NOT_EXPORTED
Your code is loading the SDK with require(), as CommonJS. Move the project to ESM or use a dynamic import(), as described in ESM-only package.
TypeScript cannot resolve the types
Use "moduleResolution": "NodeNext" or "Bundler" as shown in TypeScript configuration, then restart your editor's TypeScript server.
Node.js version
Check node --version and upgrade to Node.js 20 or later, for example with nvm:
nvm install 20
nvm use 20
Next steps
- Core Concepts: keys, addresses, transactions and finality
- Transaction Building: every way to build and sign a transaction
- API Modules: reference for each
sdk.*module - Examples: end-to-end samples