Initial commit: add .gitignore and README
This commit is contained in:
29
packages/blockchain/package.json
Normal file
29
packages/blockchain/package.json
Normal file
@@ -0,0 +1,29 @@
|
||||
{
|
||||
"name": "@workspace/blockchain",
|
||||
"version": "1.0.0",
|
||||
"description": "Blockchain utilities and helpers",
|
||||
"main": "./dist/index.js",
|
||||
"types": "./dist/index.d.ts",
|
||||
"scripts": {
|
||||
"build": "tsc",
|
||||
"test": "vitest",
|
||||
"lint": "eslint src",
|
||||
"type-check": "tsc --noEmit",
|
||||
"clean": "rm -rf dist"
|
||||
},
|
||||
"dependencies": {
|
||||
"ethers": "^6.9.0",
|
||||
"@workspace/shared-types": "workspace:*"
|
||||
},
|
||||
"devDependencies": {
|
||||
"typescript": "^5.5.4",
|
||||
"vitest": "^1.2.0"
|
||||
},
|
||||
"files": [
|
||||
"dist"
|
||||
],
|
||||
"publishConfig": {
|
||||
"access": "restricted"
|
||||
}
|
||||
}
|
||||
|
||||
30
packages/blockchain/src/contracts.ts
Normal file
30
packages/blockchain/src/contracts.ts
Normal file
@@ -0,0 +1,30 @@
|
||||
/**
|
||||
* Contract utilities
|
||||
*/
|
||||
|
||||
import { ethers } from 'ethers';
|
||||
|
||||
/**
|
||||
* Get contract instance
|
||||
*/
|
||||
export function getContract(
|
||||
address: string,
|
||||
abi: ethers.InterfaceAbi,
|
||||
signerOrProvider: ethers.Signer | ethers.Provider
|
||||
): ethers.Contract {
|
||||
return new ethers.Contract(address, abi, signerOrProvider);
|
||||
}
|
||||
|
||||
/**
|
||||
* Deploy contract
|
||||
*/
|
||||
export async function deployContract(
|
||||
signer: ethers.Signer,
|
||||
contractFactory: ethers.ContractFactory,
|
||||
...args: unknown[]
|
||||
): Promise<ethers.Contract> {
|
||||
const contract = await contractFactory.deploy(...args);
|
||||
await contract.waitForDeployment();
|
||||
return contract;
|
||||
}
|
||||
|
||||
51
packages/blockchain/src/ethers.ts
Normal file
51
packages/blockchain/src/ethers.ts
Normal file
@@ -0,0 +1,51 @@
|
||||
/**
|
||||
* Ethers.js utilities
|
||||
*/
|
||||
|
||||
import { ethers } from 'ethers';
|
||||
|
||||
/**
|
||||
* Create provider from RPC URL
|
||||
*/
|
||||
export function createProvider(rpcUrl: string): ethers.JsonRpcProvider {
|
||||
return new ethers.JsonRpcProvider(rpcUrl);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create wallet from private key
|
||||
*/
|
||||
export function createWallet(
|
||||
privateKey: string,
|
||||
provider?: ethers.Provider
|
||||
): ethers.Wallet {
|
||||
return new ethers.Wallet(privateKey, provider);
|
||||
}
|
||||
|
||||
/**
|
||||
* Format ether value
|
||||
*/
|
||||
export function formatEther(value: bigint): string {
|
||||
return ethers.formatEther(value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse ether value
|
||||
*/
|
||||
export function parseEther(value: string): bigint {
|
||||
return ethers.parseEther(value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Format units
|
||||
*/
|
||||
export function formatUnits(value: bigint, decimals: number = 18): string {
|
||||
return ethers.formatUnits(value, decimals);
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse units
|
||||
*/
|
||||
export function parseUnits(value: string, decimals: number = 18): bigint {
|
||||
return ethers.parseUnits(value, decimals);
|
||||
}
|
||||
|
||||
10
packages/blockchain/src/index.ts
Normal file
10
packages/blockchain/src/index.ts
Normal file
@@ -0,0 +1,10 @@
|
||||
/**
|
||||
* @workspace/blockchain
|
||||
* Blockchain utilities and helpers
|
||||
*/
|
||||
|
||||
export * from './ethers';
|
||||
export * from './transactions';
|
||||
export * from './contracts';
|
||||
export * from './types';
|
||||
|
||||
45
packages/blockchain/src/transactions.ts
Normal file
45
packages/blockchain/src/transactions.ts
Normal file
@@ -0,0 +1,45 @@
|
||||
/**
|
||||
* Transaction utilities
|
||||
*/
|
||||
|
||||
import { ethers } from 'ethers';
|
||||
|
||||
export interface TransactionOptions {
|
||||
gasLimit?: bigint;
|
||||
gasPrice?: bigint;
|
||||
maxFeePerGas?: bigint;
|
||||
maxPriorityFeePerGas?: bigint;
|
||||
value?: bigint;
|
||||
}
|
||||
|
||||
/**
|
||||
* Wait for transaction confirmation
|
||||
*/
|
||||
export async function waitForTransaction(
|
||||
provider: ethers.Provider,
|
||||
txHash: string,
|
||||
confirmations: number = 1
|
||||
): Promise<ethers.TransactionReceipt | null> {
|
||||
return provider.waitForTransaction(txHash, confirmations);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get transaction receipt
|
||||
*/
|
||||
export async function getTransactionReceipt(
|
||||
provider: ethers.Provider,
|
||||
txHash: string
|
||||
): Promise<ethers.TransactionReceipt | null> {
|
||||
return provider.getTransactionReceipt(txHash);
|
||||
}
|
||||
|
||||
/**
|
||||
* Estimate gas for transaction
|
||||
*/
|
||||
export async function estimateGas(
|
||||
provider: ethers.Provider,
|
||||
transaction: ethers.TransactionRequest
|
||||
): Promise<bigint> {
|
||||
return provider.estimateGas(transaction);
|
||||
}
|
||||
|
||||
25
packages/blockchain/src/types.ts
Normal file
25
packages/blockchain/src/types.ts
Normal file
@@ -0,0 +1,25 @@
|
||||
/**
|
||||
* Blockchain types
|
||||
*/
|
||||
|
||||
export interface NetworkConfig {
|
||||
name: string;
|
||||
chainId: number;
|
||||
rpcUrl: string;
|
||||
explorerUrl?: string;
|
||||
}
|
||||
|
||||
export interface TokenInfo {
|
||||
address: string;
|
||||
symbol: string;
|
||||
name: string;
|
||||
decimals: number;
|
||||
}
|
||||
|
||||
export interface TransactionStatus {
|
||||
hash: string;
|
||||
status: 'pending' | 'confirmed' | 'failed';
|
||||
blockNumber?: number;
|
||||
confirmations: number;
|
||||
}
|
||||
|
||||
20
packages/blockchain/tsconfig.json
Normal file
20
packages/blockchain/tsconfig.json
Normal file
@@ -0,0 +1,20 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"target": "ES2022",
|
||||
"module": "ESNext",
|
||||
"lib": ["ES2022"],
|
||||
"declaration": true,
|
||||
"declarationMap": true,
|
||||
"outDir": "./dist",
|
||||
"rootDir": "./src",
|
||||
"strict": true,
|
||||
"esModuleInterop": true,
|
||||
"skipLibCheck": true,
|
||||
"forceConsistentCasingInFileNames": true,
|
||||
"moduleResolution": "node",
|
||||
"resolveJsonModule": true
|
||||
},
|
||||
"include": ["src/**/*"],
|
||||
"exclude": ["node_modules", "dist", "**/*.test.ts"]
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user