Polywrap Ethereum Wallet

This package provides a Polywrap plugin for interacting with EVM networks.

The Ethereum wallet plugin implements the ethereum-provider-interface @ wrapscan.io/polywrap/ethereum-wallet@1.0 (see ../../interface/polywrap.graphql ). It handles Ethereum wallet transaction signatures and sends JSON RPC requests for the Ethereum wrapper.

Quickstart

Imports

>>> from polywrap_core import Uri
>>> from polywrap_client import PolywrapClient
>>> from polywrap_ethereum_wallet import ethereum_wallet_plugin
>>> from polywrap_ethereum_wallet.connection import Connection
>>> from polywrap_ethereum_wallet.connections import Connections
>>> from polywrap_ethereum_wallet.networks import KnownNetwork
>>> from polywrap_client_config_builder import (
...     PolywrapClientConfigBuilder
... )

Configure Client

>>> ethreum_provider_interface_uri = Uri.from_str("wrapscan.io/polywrap/ethereum-wallet@1.0")
>>> ethereum_wallet_plugin_uri = Uri.from_str("plugin/ethereum-provider")
>>> connections = Connections(
...     connections={
...         "sepolia": Connection.from_network(KnownNetwork.sepolia, None)
...     },
...     default_network="sepolia"
... )
>>> client_config = (
...     PolywrapClientConfigBuilder()
...     .set_package(
...         ethereum_wallet_plugin_uri,
...         ethereum_wallet_plugin(connections=connections)
...     )
...     .add_interface_implementations(
...         ethreum_provider_interface_uri,
...         [ethereum_wallet_plugin_uri]
...     )
...     .set_redirect(ethreum_provider_interface_uri, ethereum_wallet_plugin_uri)
...     .build()
... )
>>> client = PolywrapClient(client_config)

Invocation

>>> result = client.invoke(
...     uri=ethreum_provider_interface_uri,
...     method="request",
...     args={"method": "eth_chainId"},
...     encode_result=False,
... )
>>> print(result)
"0xaa36a7"
class polywrap_ethereum_wallet.Connection(provider: JSONBaseProvider | str, signer: str | None)[source]

Bases: object

Defines a connection to an EVM network.

classmethod from_network(network: KnownNetwork, signer: str | None = None)[source]

Create a connection from a known network.

classmethod from_node(node: str, signer: str | None = None)[source]

Create a connection from a node URL.

has_signer() bool[source]

Returns true if the connection has a signer.

property provider: JSONBaseProvider

EVM network provider.

property signer: str

Private key for signing transactions.

class polywrap_ethereum_wallet.Connections(connections: Dict[str, Connection], default_network: str | None, signer: str | None = None)[source]

Bases: object

Defines a set of connections to EVM networks.

connections: Dict[str, Connection]
default_network: str
get_connection(connection: Connection | None) Connection[source]

Get a connection from a connection object.

signer: str | None
with_signer(connection: Connection) Connection[source]

Return a connection with a signer.

class polywrap_ethereum_wallet.EthereumWalletPlugin(*args, **kwargs)[source]

Bases: Module[Connections]

A Polywrap plugin for interacting with EVM networks.

request(args: ArgsRequest, client: InvokerClient, env: Any | None = None) str[source]

Send a remote RPC request to the registered provider.

sign_message(args: ArgsSignMessage, client: InvokerClient, env: None) str[source]

Sign a message and return the signature. Throws if signer is missing.

sign_transaction(args: ArgsSignTransaction, client: InvokerClient, env: None) str[source]

Sign a serialized unsigned transaction and return the signature. Throws if signer is missing. This method requires a wallet-based signer with a private key, and is not needed for most use cases. Typically, transactions are sent by request and signed by the wallet.

signer_address(args: ArgsSignerAddress, client: InvokerClient, env: Any | None = None) str | None[source]

Get the ethereum address of the signer. Return null if signer is missing.

wait_for_transaction(args: ArgsWaitForTransaction, client: InvokerClient, env: Any | None = None) bool[source]

Wait for a transaction to be mined.

class polywrap_ethereum_wallet.KnownNetwork(value)[source]

Bases: IntEnum

Defines a list of known networks.

aurora_mainnet = 1313161554
aurora_testnet = 1313161555
avalanche_fuji = 43113
avalanche_mainnet = 43114
celo_alfajores = 44787
celo_mainnet = 42220
classmethod chain_ids() List[int][source]

Returns a list of chain IDs.

goerli = 5
classmethod has(obj: object) bool[source]

Returns true if the object is a member of the enum.

mainnet = 1
palm_mainnet = 11297108109
palm_testnet = 11297108099
sepolia = 11155111
polywrap_ethereum_wallet.ethereum_wallet_plugin(connections: Connections) PluginPackage[Connections][source]

Create a Polywrap plugin instance for interacting with EVM networks.

API References