
Security News
Feross on Risky Business Weekly Podcast: npm’s Ongoing Supply Chain Attacks
Socket CEO Feross Aboukhadijeh joins Risky Business Weekly to unpack recent npm phishing attacks, their limited impact, and the risks if attackers get smarter.
A Python SDK for the Gas Network API, providing gas price prediction and optimization for blockchain transactions.
pip install gas-network-sdk
import asyncio
from gas_network_sdk import GasNetworkClient, Chain
async def main():
# Create client with your API key (optional)
client = GasNetworkClient(api_key="your_api_key_here")
# Get gas prices for Ethereum
gas_prices = await client.get_gas_prices(Chain.ETHEREUM)
print(f"Current gas prices: {gas_prices}")
# Get next block estimate with 90% confidence
estimate = await client.get_next_block_estimate(Chain.ETHEREUM, confidence_level=90)
print(f"Next block estimate: {estimate.price} gwei")
await client.close()
# Run the example
asyncio.run(main())
from gas_network_sdk import GasNetworkClient
# With API key (recommended for higher rate limits)
client = GasNetworkClient(api_key="your_api_key")
# Without API key (rate limited)
client = GasNetworkClient()
# Get comprehensive gas price data
prices = await client.get_gas_prices(Chain.BASE)
# Get specific confidence level estimate
estimate = await client.get_next_block_estimate(Chain.ETHEREUM, confidence_level=95)
base_fees = await client.get_base_fee_estimates(Chain.ETHEREUM)
print(f"Current base fee: {base_fees.base_fee_per_gas} gwei")
print(f"Blob base fee: {base_fees.blob_base_fee_per_gas} gwei")
# Get estimates for next 5 blocks
for block_estimate in base_fees.estimated_base_fees:
for pending_block, estimates in block_estimate.pending_block.items():
for estimate in estimates:
print(f"{pending_block}: Base fee {estimate.base_fee} gwei ({estimate.confidence}% confidence)")
distribution = await client.get_gas_distribution(Chain.ETHEREUM)
print(f"Current block: {distribution.current_block_number}")
for price, count in distribution.top_n_distribution.distribution:
print(f"Price: {price} gwei, Transactions: {count}")
# Get oracle data for a specific chain ID
oracle_data = await client.get_oracle_data(1) # Ethereum mainnet
The SDK uses comprehensive error handling:
from gas_network_sdk import GasNetworkError, UnsupportedChainError, APIError
try:
prices = await client.get_gas_prices(Chain.ETHEREUM)
print(f"Success: {prices}")
except UnsupportedChainError as e:
print(f"Unsupported chain: {e}")
except APIError as e:
print(f"API error: {e}")
except GasNetworkError as e:
print(f"Other error: {e}")
async with GasNetworkClient(api_key="your_api_key") as client:
prices = await client.get_gas_prices(Chain.ETHEREUM)
print(prices)
# Client is automatically closed
You can optionally use an API key from Blocknative for higher rate limits. The API works without authentication but with rate limitations.
Licensed under either of
at your option.
FAQs
Python SDK for Gas Network API - gas price prediction and optimization
We found that gas-network-sdk demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Socket CEO Feross Aboukhadijeh joins Risky Business Weekly to unpack recent npm phishing attacks, their limited impact, and the risks if attackers get smarter.
Product
Socket’s new Tier 1 Reachability filters out up to 80% of irrelevant CVEs, so security teams can focus on the vulnerabilities that matter.
Research
/Security News
Ongoing npm supply chain attack spreads to DuckDB: multiple packages compromised with the same wallet-drainer malware.