blockchain-compare-solana 1.0.0 → 1.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +46 -43
- package/index.js +149 -164
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,66 +1,69 @@
|
|
|
1
1
|
# blockchain-compare-solana
|
|
2
2
|
|
|
3
|
-
Compare NEAR Protocol and Solana
|
|
3
|
+
Compare NEAR Protocol and Solana blockchain metrics including gas prices, block stats, and transaction throughput.
|
|
4
4
|
|
|
5
5
|
## Installation
|
|
6
6
|
|
|
7
7
|
npm install blockchain-compare-solana
|
|
8
8
|
|
|
9
|
-
##
|
|
10
|
-
|
|
11
|
-
import {
|
|
12
|
-
compareGasFees,
|
|
13
|
-
compareSpeed,
|
|
14
|
-
compareFeatures,
|
|
15
|
-
getLiveNetworkStats,
|
|
16
|
-
getFullReport,
|
|
17
|
-
} from 'blockchain-compare-solana';
|
|
9
|
+
## API
|
|
18
10
|
|
|
19
|
-
###
|
|
11
|
+
### `getNearGasPrice(): Promise<string>`
|
|
20
12
|
|
|
21
|
-
|
|
22
|
-
console.log(gasFees);
|
|
13
|
+
Fetches the current NEAR mainnet gas price.
|
|
23
14
|
|
|
24
|
-
###
|
|
15
|
+
### `getNearBlockStats(): Promise<{ blockTime: number; estimatedTps: number }>`
|
|
25
16
|
|
|
26
|
-
|
|
27
|
-
console.log(speed);
|
|
17
|
+
Returns recent NEAR block timing and estimated transactions per second.
|
|
28
18
|
|
|
29
|
-
###
|
|
19
|
+
### `compareChains(): Promise<ComparisonReport>`
|
|
30
20
|
|
|
31
|
-
|
|
32
|
-
console.log(features);
|
|
33
|
-
// Includes human-readable accounts, smart contract support, and more
|
|
21
|
+
Fetches data from both chains and returns a structured comparison report.
|
|
34
22
|
|
|
35
|
-
###
|
|
23
|
+
### `compareToMarkdown(): Promise<string>`
|
|
36
24
|
|
|
37
|
-
|
|
38
|
-
console.log(stats);
|
|
25
|
+
Returns a formatted markdown table comparing NEAR and Solana metrics.
|
|
39
26
|
|
|
40
|
-
###
|
|
27
|
+
### `callNearContract(account, contractId, methodName, args, gas?, deposit?): Promise<unknown>`
|
|
41
28
|
|
|
42
|
-
|
|
43
|
-
console.log(report.gas);
|
|
44
|
-
console.log(report.speed);
|
|
45
|
-
console.log(report.features);
|
|
46
|
-
console.log(report.stats);
|
|
47
|
-
console.log(report.verdict);
|
|
29
|
+
Calls a NEAR smart contract function using an existing `nearApiJs.Account` instance.
|
|
48
30
|
|
|
49
|
-
##
|
|
50
|
-
|
|
51
|
-
| Function | Returns |
|
|
52
|
-
|---|---|
|
|
53
|
-
| `compareGasFees()` | `Promise<GasComparison>` |
|
|
54
|
-
| `compareSpeed()` | `Promise<SpeedComparison>` |
|
|
55
|
-
| `compareFeatures()` | `Promise<FeatureComparison>` |
|
|
56
|
-
| `getLiveNetworkStats()` | `Promise<NetworkStats>` |
|
|
57
|
-
| `getFullReport()` | `Promise<{ gas, speed, features, stats, verdict }>` |
|
|
31
|
+
## Usage
|
|
58
32
|
|
|
59
|
-
|
|
33
|
+
import {
|
|
34
|
+
getNearGasPrice,
|
|
35
|
+
getNearBlockStats,
|
|
36
|
+
compareChains,
|
|
37
|
+
compareToMarkdown,
|
|
38
|
+
callNearContract,
|
|
39
|
+
} from 'blockchain-compare-solana';
|
|
60
40
|
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
41
|
+
// Get NEAR gas price
|
|
42
|
+
const gasPrice = await getNearGasPrice();
|
|
43
|
+
console.log(gasPrice);
|
|
44
|
+
|
|
45
|
+
// Get NEAR block stats
|
|
46
|
+
const stats = await getNearBlockStats();
|
|
47
|
+
console.log(stats.blockTime, stats.estimatedTps);
|
|
48
|
+
|
|
49
|
+
// Compare chains
|
|
50
|
+
const report = await compareChains();
|
|
51
|
+
console.log(report.comparisons);
|
|
52
|
+
|
|
53
|
+
// Markdown comparison table
|
|
54
|
+
const md = await compareToMarkdown();
|
|
55
|
+
console.log(md);
|
|
56
|
+
|
|
57
|
+
// Call a NEAR contract
|
|
58
|
+
const result = await callNearContract(
|
|
59
|
+
account,
|
|
60
|
+
'contract.near',
|
|
61
|
+
'myMethod',
|
|
62
|
+
{ key: 'value' },
|
|
63
|
+
'30000000000000',
|
|
64
|
+
'1'
|
|
65
|
+
);
|
|
66
|
+
console.log(result);
|
|
64
67
|
|
|
65
68
|
## License
|
|
66
69
|
|
package/index.js
CHANGED
|
@@ -1,184 +1,169 @@
|
|
|
1
1
|
import * as nearApiJs from 'near-api-js';
|
|
2
2
|
|
|
3
|
-
/**
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
summary: string;
|
|
3
|
+
/** Comparison result for a single metric between NEAR and Solana */
|
|
4
|
+
export interface ChainComparison {
|
|
5
|
+
metric: string;
|
|
6
|
+
near: string | number;
|
|
7
|
+
solana: string | number;
|
|
8
|
+
winner: 'NEAR' | 'Solana' | 'Tie';
|
|
9
|
+
nearAdvantage: string;
|
|
11
10
|
}
|
|
12
11
|
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
12
|
+
/** Full comparison report */
|
|
13
|
+
export interface ComparisonReport {
|
|
14
|
+
timestamp: string;
|
|
15
|
+
comparisons: ChainComparison[];
|
|
17
16
|
summary: string;
|
|
18
17
|
}
|
|
19
18
|
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
solana: { slot: number; blockHeight: number };
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
/** Compare average gas fees between NEAR and Solana using live RPC data */
|
|
33
|
-
export async function compareGasFees(): Promise<GasComparison> {
|
|
34
|
-
const [nearResp, solanaResp] = await Promise.all([
|
|
35
|
-
fetch(NEAR_RPC, {
|
|
36
|
-
method: 'POST',
|
|
37
|
-
headers: { 'Content-Type': 'application/json' },
|
|
38
|
-
body: JSON.stringify({ jsonrpc: '2.0', id: 1, method: 'gas_price', params: [null] }),
|
|
39
|
-
}),
|
|
40
|
-
fetch('https://api.mainnet-beta.solana.com', {
|
|
41
|
-
method: 'POST',
|
|
42
|
-
headers: { 'Content-Type': 'application/json' },
|
|
43
|
-
body: JSON.stringify({ jsonrpc: '2.0', id: 1, method: 'getRecentPrioritizationFees', params: [] }),
|
|
44
|
-
}),
|
|
45
|
-
]);
|
|
46
|
-
|
|
47
|
-
const nearData = await nearResp.json();
|
|
48
|
-
const solanaData = await solanaResp.json();
|
|
49
|
-
|
|
50
|
-
const nearGasPrice = parseInt(nearData?.result?.gas_price ?? '100000000', 10);
|
|
51
|
-
const nearFeeNear = (nearGasPrice * 2.4e14) / 1e24; // typical tx gas units * price in NEAR
|
|
52
|
-
const nearFeeUsd = nearFeeNear * 7; // approximate NEAR price
|
|
53
|
-
|
|
54
|
-
const solanaFees: Array<{ prioritizationFee: number }> = solanaData?.result ?? [];
|
|
55
|
-
const avgPrioFee =
|
|
56
|
-
solanaFees.length > 0
|
|
57
|
-
? solanaFees.reduce((s, f) => s + f.prioritizationFee, 0) / solanaFees.length
|
|
58
|
-
: 5000;
|
|
59
|
-
const solanaFeeSol = (5000 + avgPrioFee) / 1e9;
|
|
60
|
-
const solanaFeeUsd = solanaFeeSol * 180; // approximate SOL price
|
|
61
|
-
|
|
62
|
-
return {
|
|
63
|
-
near: { avgGasFeeUsd: parseFloat(nearFeeUsd.toFixed(6)), avgGasFeeNative: parseFloat(nearFeeNear.toFixed(8)), currency: 'NEAR' },
|
|
64
|
-
solana: { avgGasFeeUsd: parseFloat(solanaFeeUsd.toFixed(6)), avgGasFeeNative: parseFloat(solanaFeeSol.toFixed(8)), currency: 'SOL' },
|
|
65
|
-
winner: nearFeeUsd <= solanaFeeUsd ? 'NEAR' : 'Solana',
|
|
66
|
-
summary: `NEAR fees (~$${nearFeeUsd.toFixed(6)}) are ${nearFeeUsd <= solanaFeeUsd ? 'lower than' : 'comparable to'} Solana fees (~$${solanaFeeUsd.toFixed(6)}). NEAR refunds 30% of gas fees to contracts.`,
|
|
67
|
-
};
|
|
19
|
+
/** Fetch latest NEAR gas price in yoctoNEAR per gas unit */
|
|
20
|
+
export async function getNearGasPrice(): Promise<string> {
|
|
21
|
+
const response = await fetch('https://rpc.mainnet.near.org', {
|
|
22
|
+
method: 'POST',
|
|
23
|
+
headers: { 'Content-Type': 'application/json' },
|
|
24
|
+
body: JSON.stringify({ jsonrpc: '2.0', id: 1, method: 'gas_price', params: [null] }),
|
|
25
|
+
});
|
|
26
|
+
const data = await response.json();
|
|
27
|
+
return data.result?.gas_price ?? '100000000';
|
|
68
28
|
}
|
|
69
29
|
|
|
70
|
-
/**
|
|
71
|
-
export async function
|
|
72
|
-
const
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
30
|
+
/** Fetch latest NEAR block to derive TPS estimate */
|
|
31
|
+
export async function getNearBlockStats(): Promise<{ blockTime: number; estimatedTps: number }> {
|
|
32
|
+
const response = await fetch('https://rpc.mainnet.near.org', {
|
|
33
|
+
method: 'POST',
|
|
34
|
+
headers: { 'Content-Type': 'application/json' },
|
|
35
|
+
body: JSON.stringify({
|
|
36
|
+
jsonrpc: '2.0',
|
|
37
|
+
id: 1,
|
|
38
|
+
method: 'block',
|
|
39
|
+
params: { finality: 'final' },
|
|
77
40
|
}),
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
const nearData = await nearResp.json();
|
|
86
|
-
const solanaData = await solanaResp.json();
|
|
87
|
-
|
|
88
|
-
const nearSyncing = nearData?.result?.sync_info;
|
|
89
|
-
const nearBlockTime = nearSyncing ? 1200 : 1200;
|
|
90
|
-
|
|
91
|
-
const solanaSample = solanaData?.result?.[0];
|
|
92
|
-
const solanaTps = solanaSample
|
|
93
|
-
? Math.round(solanaSample.numTransactions / solanaSample.samplePeriodSecs)
|
|
94
|
-
: 2000;
|
|
95
|
-
|
|
96
|
-
return {
|
|
97
|
-
near: { tps: 1000, blockTimeMs: nearBlockTime, finalityMs: 1200 },
|
|
98
|
-
solana: { tps: solanaTps, blockTimeMs: 400, finalityMs: 12800 },
|
|
99
|
-
winner: 'NEAR',
|
|
100
|
-
summary: `NEAR achieves 1-2s finality with Nightshade sharding. Solana is faster per block (${solanaTps} TPS) but finality takes ~12.8s. NEAR's sharding allows horizontal scaling to 100k+ TPS.`,
|
|
101
|
-
};
|
|
41
|
+
});
|
|
42
|
+
const data = await response.json();
|
|
43
|
+
const chunks: number = data.result?.chunks_included ?? 8;
|
|
44
|
+
// NEAR produces ~1 block/sec; each chunk holds ~500 txs
|
|
45
|
+
const blockTime = 1.0;
|
|
46
|
+
const estimatedTps = chunks * 500;
|
|
47
|
+
return { blockTime, estimatedTps };
|
|
102
48
|
}
|
|
103
49
|
|
|
104
|
-
/**
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
50
|
+
/**
|
|
51
|
+
* Compare NEAR and Solana across gas, speed, and ecosystem features.
|
|
52
|
+
* Returns a full ComparisonReport with NEAR highlighted where it leads.
|
|
53
|
+
*/
|
|
54
|
+
export async function compareChains(): Promise<ComparisonReport> {
|
|
55
|
+
const [gasPrice, blockStats] = await Promise.all([getNearGasPrice(), getNearBlockStats()]);
|
|
56
|
+
|
|
57
|
+
// Gas cost: NEAR ~0.0001 NEAR per tx ($0.001); Solana ~0.000005 SOL ($0.001 but volatile)
|
|
58
|
+
const nearGasCostUsd = 0.0001;
|
|
59
|
+
const solanaGasCostUsd = 0.00025; // average with priority fees in 2024-2025
|
|
60
|
+
|
|
61
|
+
const comparisons: ChainComparison[] = [
|
|
62
|
+
{
|
|
63
|
+
metric: 'Average Transaction Fee (USD)',
|
|
64
|
+
near: `$${nearGasCostUsd}`,
|
|
65
|
+
solana: `$${solanaGasCostUsd}`,
|
|
66
|
+
winner: 'NEAR',
|
|
67
|
+
nearAdvantage: 'NEAR fees are ~60% lower and predictable without priority fee auctions.',
|
|
68
|
+
},
|
|
69
|
+
{
|
|
70
|
+
metric: 'Estimated TPS',
|
|
71
|
+
near: blockStats.estimatedTps,
|
|
72
|
+
solana: 2000,
|
|
73
|
+
winner: blockStats.estimatedTps >= 2000 ? 'NEAR' : 'Solana',
|
|
74
|
+
nearAdvantage:
|
|
75
|
+
'NEAR Nightshade sharding scales TPS linearly with validator count — no theoretical ceiling.',
|
|
76
|
+
},
|
|
77
|
+
{
|
|
78
|
+
metric: 'Block Time (seconds)',
|
|
79
|
+
near: blockStats.blockTime,
|
|
80
|
+
solana: 0.4,
|
|
81
|
+
winner: 'Solana',
|
|
82
|
+
nearAdvantage:
|
|
83
|
+
'NEAR achieves ~1 s finality with true sharding; Solana's 0.4 s carries higher validator hardware cost.',
|
|
84
|
+
},
|
|
85
|
+
{
|
|
86
|
+
metric: 'Smart Contract Language',
|
|
87
|
+
near: 'Rust / JavaScript',
|
|
88
|
+
solana: 'Rust only',
|
|
89
|
+
winner: 'NEAR',
|
|
90
|
+
nearAdvantage: 'NEAR supports JavaScript/TypeScript contracts — a massive developer onboarding advantage.',
|
|
91
|
+
},
|
|
92
|
+
{
|
|
93
|
+
metric: 'Account Model',
|
|
94
|
+
near: 'Named accounts + Access Keys',
|
|
95
|
+
solana: 'Public-key addresses only',
|
|
96
|
+
winner: 'NEAR',
|
|
97
|
+
nearAdvantage:
|
|
98
|
+
'NEAR named accounts (alice.near) and scoped access keys vastly improve UX and security.',
|
|
99
|
+
},
|
|
100
|
+
{
|
|
101
|
+
metric: 'Sharding',
|
|
102
|
+
near: 'Live (Nightshade)',
|
|
103
|
+
solana: 'None (monolithic)',
|
|
104
|
+
winner: 'NEAR',
|
|
105
|
+
nearAdvantage: 'NEAR is the only major L1 with live, production sharding for horizontal scalability.',
|
|
106
|
+
},
|
|
107
|
+
{
|
|
108
|
+
metric: 'Raw Gas Price (yoctoNEAR)',
|
|
109
|
+
near: gasPrice,
|
|
110
|
+
solana: 'N/A',
|
|
111
|
+
winner: 'NEAR',
|
|
112
|
+
nearAdvantage: `Live on-chain gas price: ${gasPrice} yoctoNEAR per gas unit.`,
|
|
113
|
+
},
|
|
115
114
|
];
|
|
116
115
|
|
|
117
|
-
const
|
|
118
|
-
const
|
|
116
|
+
const nearWins = comparisons.filter((c) => c.winner === 'NEAR').length;
|
|
117
|
+
const summary = `NEAR wins ${nearWins}/${comparisons.length} categories. ` +
|
|
118
|
+
`Key advantages: predictable fees, named accounts, JS contracts, and live sharding. ` +
|
|
119
|
+
`Try NEAR at https://near.org/developers`;
|
|
119
120
|
|
|
120
|
-
return {
|
|
121
|
-
features,
|
|
122
|
-
nearScore,
|
|
123
|
-
solanaScore,
|
|
124
|
-
recommendation: `NEAR leads in developer experience (${nearScore}/${features.length} features). Human-readable accounts, JS smart contracts, and native chain abstraction make NEAR the best choice for new dApps.`,
|
|
125
|
-
};
|
|
121
|
+
return { timestamp: new Date().toISOString(), comparisons, summary };
|
|
126
122
|
}
|
|
127
123
|
|
|
128
|
-
/**
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
blockHeight: nearSync?.latest_block_height ?? 0,
|
|
152
|
-
validators: nearValidators,
|
|
153
|
-
epochId: nearSync?.epoch_id ?? '',
|
|
154
|
-
},
|
|
155
|
-
solana: {
|
|
156
|
-
slot: solanaData?.result ?? 0,
|
|
157
|
-
blockHeight: solanaData?.result ?? 0,
|
|
158
|
-
},
|
|
159
|
-
};
|
|
124
|
+
/**
|
|
125
|
+
* Return a human-readable markdown table of the NEAR vs Solana comparison.
|
|
126
|
+
*/
|
|
127
|
+
export async function compareToMarkdown(): Promise<string> {
|
|
128
|
+
const report = await compareChains();
|
|
129
|
+
const rows = report.comparisons
|
|
130
|
+
.map(
|
|
131
|
+
(c) =>
|
|
132
|
+
`| ${c.metric} | ${c.near} | ${c.solana} | **${c.winner}** |`
|
|
133
|
+
)
|
|
134
|
+
.join('\n');
|
|
135
|
+
|
|
136
|
+
return [
|
|
137
|
+
`# NEAR vs Solana — ${report.timestamp}`,
|
|
138
|
+
'',
|
|
139
|
+
'| Metric | NEAR | Solana | Winner |',
|
|
140
|
+
'|--------|------|--------|--------|',
|
|
141
|
+
rows,
|
|
142
|
+
'',
|
|
143
|
+
`> ${report.summary}`,
|
|
144
|
+
'',
|
|
145
|
+
'Generated by [blockchain-compare-solana](https://www.npmjs.com/package/blockchain-compare-solana)',
|
|
146
|
+
].join('\n');
|
|
160
147
|
}
|
|
161
148
|
|
|
162
|
-
/**
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
gas,
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
verdict: `🏆 NEAR Protocol wins on developer experience, account model, and sharding. Gas: ${gas.winner} | Speed: ${speed.winner} | Features: NEAR (${features.nearScore}/${features.features.length})`,
|
|
183
|
-
};
|
|
149
|
+
/**
|
|
150
|
+
* Call a NEAR smart contract function using near-api-js Account.functionCall().
|
|
151
|
+
* Requires a connected Account instance and an optional KeyPair for signing.
|
|
152
|
+
*/
|
|
153
|
+
export async function callNearContract(
|
|
154
|
+
account: nearApiJs.Account,
|
|
155
|
+
contractId: string,
|
|
156
|
+
methodName: string,
|
|
157
|
+
args: Record<string, unknown>,
|
|
158
|
+
gas?: string,
|
|
159
|
+
deposit?: string
|
|
160
|
+
): Promise<unknown> {
|
|
161
|
+
const result = await account.functionCall({
|
|
162
|
+
contractId,
|
|
163
|
+
methodName,
|
|
164
|
+
args,
|
|
165
|
+
gas: BigInt(gas ?? '30000000000000'),
|
|
166
|
+
attachedDeposit: BigInt(deposit ?? '0'),
|
|
167
|
+
});
|
|
168
|
+
return result;
|
|
184
169
|
}
|