@1money/ts-sdk
The TS-SDK for 1Money Network Protocol

Quick start
Install
npm i -S @1money/ts-sdk axios viem @ethereumjs/rlp
# or
yarn add @1money/ts-sdk axios viem @ethereumjs/rlp
# or
pnpm i @1money/ts-sdk axios viem @ethereumjs/rlp
Initialize the API Client
import { api } from '@1money/ts-sdk';
const apiClient = api();
const testnetClient = api({ network: 'testnet' });
const apiClient = api({
network: 'testnet',
timeout: 5000
});
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 0;
});
Get checkpoint by number
const checkpoint = await apiClient.checkpoints.getByNumber(1)
.success(response => {
console.log('checkpoint', response);
});
CDN
<script src="https://unpkg.com/@1money/ts-sdk@latest/umd/1money-ts-sdk.min.js"></script>
<script>
const apiClient = window.$1money.api({
network: 'testnet'
});
async function getNumber () {
const res = await apiClient.checkpoints.getNumber();
console.log('res: ', res);
}
getNumber();
</script>
Error Handling
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 => {
})
.timeout(err => {
})
.error(err => {
});
You can use rest to handle all other errors:
apiClient.someMethod()
.success(response => {
})
.rest(err => {
});
Async/Await
You also can use async/await to handle the response:
import { api } from '@1money/ts-sdk';
const apiClient = api();
try {
const response = await apiClient.someMethod();
console.log('Response:', response);
} catch (err) {
console.error('Error:', err);
}
Promise
You also can use standard promise to handle the response:
import { api } from '@1money/ts-sdk';
const apiClient = api();
apiClient.someMethod()
.then(response => {
console.log('Response:', response);
})
.catch(err => {
console.error('Error:', err);
});
API Methods
State API
Get Latest Epoch Checkpoint
The state API provides access to the latest epoch and checkpoint values that are required for all POST operations. The response includes both the epoch/checkpoint numbers and their cryptographic hashes.
apiClient.state.getLatestEpochCheckpoint()
.success(response => {
console.log('Latest epoch:', response.epoch);
console.log('Latest checkpoint:', response.checkpoint);
console.log('Checkpoint hash:', response.checkpoint_hash);
console.log('Parent checkpoint hash:', response.checkpoint_parent_hash);
})
.error(err => {
console.error('Error:', err);
});
Chain API
Get Chain ID
apiClient.chain.getChainId()
.success(response => {
console.log('Current chain id:', response.chain_id);
})
.error(err => {
console.error('Error:', err);
});
Accounts API
Get Account Nonce
const address = '0x9E1E9688A44D058fF181Ed64ddFAFbBE5CC74ff3';
apiClient.accounts.getNonce(address)
.success(response => {
console.log('Account nonce:', response);
})
.error(err => {
console.error('Error:', err);
});
Get Associated Token Account
const address = '0x9E1E9688A44D058fF181Ed64ddFAFbBE5CC74ff3';
const token = '0x2cd8999Be299373D7881f4aDD11510030ad1412F';
apiClient.accounts.getTokenAccount(address, token)
.success(response => {
console.log('Associated token account:', response);
})
.error(err => {
console.error('Error:', err);
});
Tokens API
Get Token Metadata
const tokenAddress = '0x2cd8999Be299373D7881f4aDD11510030ad1412F';
apiClient.tokens.getTokenMetadata(tokenAddress)
.success(response => {
console.log('Token metadata:', response);
})
.error(err => {
console.error('Error:', err);
});
Issue New Token
import { signMessage, toHex } from '@1money/ts-sdk';
const privateKey = 'YOUR_PRIVATE_KEY';
const epochData = await apiClient.state.getLatestEpochCheckpoint()
.success(response => response);
const payload = [
epochData.epoch,
epochData.checkpoint,
1,
1,
'MTK',
'My Token',
18,
'0x9E1E9688A44D058fF181Ed64ddFAFbBE5CC74ff3',
true,
];
const signature = await signMessage(payload, privateKey);
if (!signature) {
throw new Error('Failed to generate signature');
}
const issuePayload = {
recent_epoch: epochData.epoch,
recent_checkpoint: epochData.checkpoint,
chain_id: 1,
nonce: 1,
name: 'My Token',
symbol: 'MTK',
decimals: 18,
master_authority: '0x9E1E9688A44D058fF181Ed64ddFAFbBE5CC74ff3',
is_private: true,
signature
};
apiClient.tokens.issueToken(issuePayload)
.success(response => {
console.log('Token issued:', response);
})
.error(err => {
console.error('Error:', err);
});
Manage Token Blacklist/Whitelist
import { signMessage, toHex } from '@1money/ts-sdk';
import type { ManageListAction } from '@1money/ts-sdk/api';
const privateKey = 'YOUR_PRIVATE_KEY';
const epochData = await apiClient.state.getLatestEpochCheckpoint()
.success(response => response);
const payload = [
epochData.epoch,
epochData.checkpoint,
1,
1,
ManageListAction.Add,
'0x9E1E9688A44D058fF181Ed64ddFAFbBE5CC74ff3',
'0x2cd8999Be299373D7881f4aDD11510030ad1412F',
];
const signature = await signMessage(payload, privateKey);
if (!signature) {
throw new Error('Failed to generate signature');
}
const manageListPayload = {
recent_epoch: epochData.epoch,
recent_checkpoint: epochData.checkpoint,
chain_id: 1,
nonce: 1,
action: ManageListAction.Add,
address: '0x9E1E9688A44D058fF181Ed64ddFAFbBE5CC74ff3',
token: '0x2cd8999Be299373D7881f4aDD11510030ad1412F',
signature
};
apiClient.tokens.manageBlacklist(manageListPayload)
.success(response => {
console.log('Blacklist update transaction hash:', response.hash);
})
.error(err => {
console.error('Error:', err);
});
apiClient.tokens.manageWhitelist(manageListPayload)
.success(response => {
console.log('Whitelist update transaction hash:', response.hash);
})
.error(err => {
console.error('Error:', err);
});
Burn Tokens
import { signMessage, toHex } from '@1money/ts-sdk';
const privateKey = 'YOUR_PRIVATE_KEY';
const epochData = await apiClient.state.getLatestEpochCheckpoint()
.success(response => response);
const payload = [
epochData.epoch,
epochData.checkpoint,
1,
1,
'0x2cd8999Be299373D7881f4aDD11510030ad1412F',
'1000000000000000000',
];
const signature = await signMessage(payload, privateKey);
if (!signature) {
throw new Error('Failed to generate signature');
}
const burnPayload = {
recent_epoch: epochData.epoch,
recent_checkpoint: epochData.checkpoint,
chain_id: 1,
nonce: 1,
token: '0x2cd8999Be299373D7881f4aDD11510030ad1412F',
value: '1000000000000000000',
signature
};
apiClient.tokens.burnToken(burnPayload)
.success(response => {
console.log('Burn transaction hash:', response.hash);
})
.error(err => {
console.error('Error:', err);
});
Grant Token Authority
import { signMessage, toHex } from '@1money/ts-sdk';
import type { AuthorityType, AuthorityAction } from '@1money/ts-sdk/api';
const privateKey = 'YOUR_PRIVATE_KEY';
const epochData = await apiClient.state.getLatestEpochCheckpoint()
.success(response => response);
const payload = [
epochData.epoch,
epochData.checkpoint,
1,
1,
'0x2cd8999Be299373D7881f4aDD11510030ad1412F',
'0x9E1E9688A44D058fF181Ed64ddFAFbBE5CC74ff3',
AuthorityAction.Grant,
AuthorityType.MasterMint,
];
const signature = await signMessage(payload, privateKey);
if (!signature) {
throw new Error('Failed to generate signature');
}
const authorityPayload = {
recent_epoch: epochData.epoch,
recent_checkpoint: epochData.checkpoint,
chain_id: 1,
nonce: 1,
token: '0x2cd8999Be299373D7881f4aDD11510030ad1412F',
authority_address: '0x9E1E9688A44D058fF181Ed64ddFAFbBE5CC74ff3',
action: AuthorityAction.Grant,
authority_type: AuthorityType.MasterMint,
signature
};
apiClient.tokens.grantAuthority(authorityPayload)
.success(response => {
console.log('Authority update transaction hash:', response.hash);
})
.error(err => {
console.error('Error:', err);
});
Transactions API
Get Transaction Details
const txHash = '0xf55f9525be94633b56f954d3252d52b8ef42f5fd5f9491b243708471c15cc40c';
apiClient.transactions.getByHash(txHash)
.success(response => {
console.log('Transaction details:', response);
})
.error(err => {
console.error('Error:', err);
});
Get Transaction Receipt
const txHash = '0xf55f9525be94633b56f954d3252d52b8ef42f5fd5f9491b243708471c15cc40c';
apiClient.transactions.getReceiptByHash(txHash)
.success(response => {
console.log('Transaction receipt:', response);
})
.error(err => {
console.error('Error:', err);
});
Estimate Transaction Fee
const fromAddress = '0x9E1E9688A44D058fF181Ed64ddFAFbBE5CC74ff3';
const value = '1000000000';
const tokenAddress = '0x2cd8999Be299373D7881f4aDD11510030ad1412F';
apiClient.transactions.estimateFee(fromAddress, value, tokenAddress)
.success(response => {
console.log('Estimated fee:', response);
})
.error(err => {
console.error('Error:', err);
});
Submit Payment Transaction
import { signMessage, toHex } from '@1money/ts-sdk';
const privateKey = 'YOUR_PRIVATE_KEY';
const epochData = await apiClient.state.getLatestEpochCheckpoint()
.success(response => response);
const payload = [
epochData.epoch,
epochData.checkpoint,
1,
1,
'0x2cd8999Be299373D7881f4aDD11510030ad1412F',
'1000000000',
'0x2cd8999Be299373D7881f4aDD11510030ad1412F',
];
const signature = await signMessage(payload, privateKey);
if (!signature) {
throw new Error('Failed to generate signature');
}
const paymentPayload = {
recent_epoch: epochData.epoch,
recent_checkpoint: epochData.checkpoint,
chain_id: 1,
nonce: 1,
recipient: '0x2cd8999Be299373D7881f4aDD11510030ad1412F',
value: '1000000000',
token: '0x2cd8999Be299373D7881f4aDD11510030ad1412F',
signature
};
apiClient.transactions.payment(paymentPayload)
.success(response => {
console.log('Payment transaction hash:', response.hash);
})
.error(err => {
console.error('Error:', err);
});
Utility Functions
Calculate Transaction Hash
import { calcTxHash } from '@1money/ts-sdk';
const payload = [
1212101,
2,
'0x0000000000000000000000000000000000000000',
1024,
'0x0000000000000000000000000000000000000000',
];
const signature = {
r: '0xe9ef6ce7aaeb4656f197b63a96c932ab5e0fd2df0913f6af1c8e7b1879e5ed0a',
s: '0x68a9cbaa35af5e3d896a2841d19a42dba729380a1c91864403de872578f6f6c3',
v: 0,
};
const hash = calcTxHash(payload, signature);
console.log('Transaction hash:', hash);
Derive Token Address
import { deriveTokenAddress } from '@1money/ts-sdk';
const walletAddress = '0xA634dfba8c7550550817898bC4820cD10888Aac5';
const mintAddress = '0x8E9d1b45293e30EF38564582979195DD16A16E13';
const tokenAddress = deriveTokenAddress(walletAddress, mintAddress);
console.log('Token account address:', tokenAddress);
Convert to Hex
import { toHex } from '@1money/ts-sdk';
const boolHex = toHex(true);
const numHex = toHex(123);
const strHex = toHex('hello');
const arrHex = toHex([1, 2, 3]);
Sign Message
import { signMessage } from '@1money/ts-sdk';
const privateKey = 'YOUR_PRIVATE_KEY';
const payload = [
1212101,
2,
'0x0000000000000000000000000000000000000000',
'1000000000000000000',
'0x0000000000000000000000000000000000000000',
];
const signature = await signMessage(payload, privateKey);
License
MIT