Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(py): configurable eth account wallet provider rpc_url #474

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

stat
Copy link
Contributor

@stat stat commented Feb 26, 2025

What changed?

  • Documentation
  • Bug fix
  • New Action
  • New Action Provider
  • Other
    enabling users to specify the rpc_url for the eth account wallet provider

Why was this change implemented?

Network support

  • All EVM
  • Base
  • Base Sepolia
  • Other

Wallet support

  • CDP Wallet
  • EVM Wallet
  • Other

Checklist

  • Changelog updated
  • Commits are signed. See instructions
  • Doc strings
  • Readme updates
  • Rebased against master
  • Relevant exports added

How has it been tested?

  • Agent tested
  • Unit tests

with invalid user defined rpc_url:

wallet_provider = EthAccountWalletProvider(
    config=EthAccountWalletProviderConfig(
        account=account,
        chain_id="84532",
        rpc_url="https://base-sepolia.g.alchemy.com",
    )
)
Prompt: native balance

-------------------
Error getting balance: 404 Client Error: Not Found for url: https://base-sepolia.g.alchemy.com
-------------------
It seems there was an error retrieving the native balance. Please try again later.
-------------------

with valid user define rpc_url:

wallet_provider = EthAccountWalletProvider(
    config=EthAccountWalletProviderConfig(
        account=account,
        chain_id="84532",
        rpc_url="https://sepolia.base.org",
    )
)
Prompt: native balance

-------------------
Native balance at address 0x349002E7213E7F7CF68a8368ca83Fd85CEC4DDB0: 946887436744372655
-------------------
Your native balance is approximately **0.9469 ETH** (946,887,436,744,372,655 wei).
-------------------

with user defined chain:

custom_base_sepolia = Chain(
    id="84532",
    name="Base Sepolia",
    network="base-sepolia",
    native_currency=NativeCurrency(
        name="Sepolia Ether",
        symbol="ETH",
        decimals=18
    ),
    rpc_urls={
        "default": RpcUrls(
            http=["https://sepolia.base.org"]
        )
    },
    block_explorers={
        "default": BlockExplorer(
            name="Basescan",
            url="https://sepolia.basescan.org",
            api_url="https://api-sepolia.basescan.org/api"
        )
    },
    contracts={},
    testnet=True
)

# Initialize Ethereum Account Wallet Provider with custom chain
wallet_provider = EthAccountWalletProvider(
    config=EthAccountWalletProviderConfig(
        account=account,
        chain=custom_base_sepolia,
    )
)
Prompt: native balance

-------------------
Native balance at address 0x349002E7213E7F7CF68a8368ca83Fd85CEC4DDB0: 946887436744372655
-------------------
Your native balance is approximately 0.9469 ETH (946,887,436,744,372,655 wei).
-------------------

Notes to reviewers

@cb-heimdall
Copy link

cb-heimdall commented Feb 26, 2025

🟡 Heimdall Review Status

Requirement Status More Info
Reviews 🟡 0/1
Denominator calculation
Show calculation
1 if user is bot 0
1 if user is external 0
From .codeflow.yml 1
Additional review requirements
Show calculation
Max 0
0
From CODEOWNERS 0
Global minimum 0
Max 1
1
1 if commit is unverified 0
Sum 1

@github-actions github-actions bot added the documentation Improvements or additions to documentation label Feb 26, 2025
@stat stat marked this pull request as ready for review February 26, 2025 23:58
@stat stat requested a review from murrlincoln as a code owner February 26, 2025 23:58
@@ -42,7 +43,7 @@ def __init__(self, config: EthAccountWalletProviderConfig):
self.account = config.account

chain = NETWORK_ID_TO_CHAIN[CHAIN_ID_TO_NETWORK_ID[config.chain_id]]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

will this line fail with a non-explicitly supported chain ID?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, absolutely. think we should also support a user defined chain within the config too?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

enabled custom chain definitions as well!

Copy link
Contributor

@CarsonRoscoe CarsonRoscoe left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Per John's comment, chain = assignment will fail for a non-supported chainId.

However, chain is only used to get the rpc_url, which you are now passing in. Meaning, that line is now optional.

I think there's a cleaner way to write this that avoids the failure John is concerned about.

Something like:

rpc_url = config.rpc_url
if rpc_url is None:
    chain = NETWORK_ID_TO_CHAIN[CHAIN_ID_TO_NETWORK_ID[config.chain_id]]
    rpc_url = chain.rpc_urls["default"].http[0]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation needs triage python wallet provider New wallet provider
Development

Successfully merging this pull request may close these issues.

4 participants