@tiplink/util
v0.0.1
Published
Shared TypeScript code accross TipLink products.
Downloads
82
Keywords
Readme
TipLink Util
Shared TypeScript code accross TipLink products.
Notes
This is an evolving package but some initial proposals:
- This package is meant for internal use, published on npm for convenience, not maintained for third parties
- Keep a low dependency footprint; that said, we'll have core libraries like
@solana/web3.js
- Libraries of functions over classes
- Higher code quality
- JSDocs over complicated functions
- Performant, reliable, clean functions
- Good test coverage, linting
Style Guide
- For exported functions, params, constants, fields, etc., use full words
Examples
Common transaction
Custom transaction using modular parts
try {
const instructions = [
SystemProgram.transfer({
fromPubkey,
toPubkey: to,
lamports: amount,
}),
];
const { transaction } = await buildTransaction({
connection,
instructions,
feePayer: fromPubkey,
priorityFeesConfig: prioFeesConfig,
signers,
signTransaction: signFn,
});
await simulateTransaction({
connection,
transaction,
simulateTransactionConfig: {
sigVerify: true,
},
});
const { signature } = await sendTransaction({
connection,
rawTransaction: transaction.serialize(),
});
} catch (err) {
if (err instanceof TxnError) {
if (err instanceof InsufficientFundsError) {
// Handle
}
if (err instanceof UnexpectedSendError) {
// Handle
}
// etc.
}
}
Pre-built common transaction
try {
const { sig } = await sendLamports({
connection: CONNECTION,
from: TEST_KEYPAIR,
to,
amount,
prioFeesConfig: { cuPrice: DEFAULT_CU_PRICE },
});
} catch (err) {
// Similar to above
}