npm i -S @1money/ts-sdk axios ethers
# or
yarn add @1money/ts-sdk axios ethers
# or
pnpm i @1money/ts-sdk axios ethers
Initialize the API Client
import { api } from '@1money/ts-sdk';
// Initialize with default settings (mainnet)
const apiClient = api();
// Or specify testnet network
const testnetClient = api({ network: 'testnet' });
// You can also set a custom timeout (in milliseconds)
const apiClient = api({
network: 'testnet',
timeout: 5000 // 5 seconds
});
Fetch the current checkpoint number
const number = await apiClient.checkpoints.getNumber()
.success(response => {
console.log('number', response.number);
return response.number;
})
.error(err => {
console.error('Error:', err);
// return a default value
return 0;
});
// do something with the number
// ...
All API methods return a promise-like object with .success(), .timeout(), .error() and .rest() handlers. Always implement both handlers for proper error management:
.success(): Handles successful API responses
.timeout(): Specifically handles timeout errors
.error(): Handles all other types of errors
.rest(): A final handler that runs after any of the above handlers complete
import { api } from '@1money/ts-sdk';
const apiClient = api();
apiClient.someMethod()
.success(response => {
// Handle successful response
})
.timeout(err => {
// Handle timeout case
})
.error(err => {
// Handle other errors
});