Skip to main content

Use multiple rpc for reliability

Project description

solver-MultiRpc: Reliable Ethereum Interactions with Multiple RPCs

solver-MultiRpc is a Python package designed to enhance the reliability of Ethereum smart contract interactions by utilizing multiple RPC (Remote Procedure Call) endpoints. If one RPC fails, the system can fall back to another, ensuring a higher success rate for your operations.

Features

  • Multiple RPC Support: Seamlessly switch between different RPCs to ensure uninterrupted interactions.
  • Gas Management: Fetch gas prices from multiple sources to ensure transactions are sent with an appropriate fee.
  • Robust Error Handling: Designed to handle failures gracefully, increasing the reliability of your applications.
  • Easy-to-use API: Interact with Ethereum smart contracts using a simple and intuitive API.

Quick Start

Here's a quick example to get you started:

import asyncio
import json
from multirpc import MultiRpc

async def main():
    rpcs = ['https://rpcapi.fantom.network', 'https://rpc2.fantom.network', 'https://rpc.ankr.com/fantom']
    with open("abi.json", "r") as f:
        abi = json.load(f)
    multi_rpc = MultiRpc(rpcs, contract_address='YOUR_CONTRACT_ADDRESS', contract_abi=abi)
    await multi_rpc.setup()
    multi_rpc.set_account("YOUR_PUBLIC_ADDRESS", "YOUR_PRIVATE_KEY")
    result = await multi_rpc.functions.YOUR_FUNCTION().call()
    print(result)

asyncio.run(main())

Replace placeholders like YOUR_CONTRACT_ADDRESS, YOUR_PUBLIC_ADDRESS, YOUR_PRIVATE_KEY, and YOUR_FUNCTION with appropriate values.

Documentation

Initialization

Initialize the MultiRpc class with your RPC URLs, contract address, and contract ABI:

multi_rpc = MultiRpc(rpcs, contract_address='YOUR_CONTRACT_ADDRESS', contract_abi=abi)

Setup

Before making any calls, set up the connection to the provided RPCs:

await multi_rpc.setup()

Setting Account

Set the Ethereum account details (address and private key) for sending transactions:

multi_rpc.set_account("YOUR_PUBLIC_ADDRESS", "YOUR_PRIVATE_KEY")

Calling Contract Functions

Call a function from your contract:

result = await multi_rpc.functions.YOUR_FUNCTION().call()

Contributing

Contributions are welcome! Please open an issue or submit a pull request on our GitHub repository.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

solver-multiRPC-1.tar.gz (11.2 kB view details)

Uploaded Source

File details

Details for the file solver-multiRPC-1.tar.gz.

File metadata

  • Download URL: solver-multiRPC-1.tar.gz
  • Upload date:
  • Size: 11.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.4

File hashes

Hashes for solver-multiRPC-1.tar.gz
Algorithm Hash digest
SHA256 29bd2c02e82f02fc699c4bfbcc0c5e5fd2cf568d0fba72c5ba86947718ea1fb0
MD5 b1cffac8cd0822e3234cb14f4bca0927
BLAKE2b-256 739265277976a9324e2a741feb8eb1e554e418f41c52056799f899e1e2334d95

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page