Skip to main content

Wrapper and Web3 class to interact with and create Anvil chains

Project description

anvil-web3

Easily interact with and create anvil chains from python

Install

anvil-web3 assumes anvil is already installed, click here if you don't have anvil installed

python3 -m pip install anvil-web3

Usage

This example shows how to programatically create an Anvil chain and how to inject the anvil rpc methods to a web3.py Web3 object:

from web3 import Web3, HTTPProvider
from anvil_web3 import anvil, AnvilWeb3, AnvilInstance

# create an anvil chain
instance = AnvilInstance(
    chain_id=42
)

# use the injection function
w3 = Web3(HTTPProvider(instance.http_url))
anvil(w3)

# or contruct a Web3 object from the AnvilWeb3 class (recommended for better autocompletion support)
w3 = AnvilWeb3(HTTPProvider(instance.http_url))

test_account = w3.eth.account.from_key(w3.keccak(text="42"))

# call an anvil method
w3.anvil.set_balance(test_account.address, 42424242)
assert w3.eth.get_balance(test_account.address) == 42424242 and w3.eth.chain_id == 42

instance.kill()

More complex demos in /examples

Tests

WIP

Current API Support

  • anvil_impersonateAccount
  • anvil_stopImpersonatingAccount
  • anvil_autoImpersonateAccount
  • anvil_getAutomine
  • anvil_mine
  • anvil_dropTransaction
  • anvil_reset
  • anvil_setRpcUrl
  • anvil_setBalance
  • anvil_setCode
  • anvil_setNonce
  • anvil_setStorageAt
  • anvil_setCoinbase
  • anvil_setLoggingEnabled
  • anvil_setMinGasPrice
  • anvil_setNextBlockBaseFeePerGas
  • anvil_setChainId
  • anvil_dumpState
  • anvil_loadState
  • anvil_nodeInfo
  • evm_setAutomine
  • evm_setIntervalMining
  • evm_snapshot
  • evm_revert
  • evm_increaseTime
  • evm_setNextBlockTimestamp
  • anvil_setBlockTimestampInterval
  • evm_setBlockGasLimit
  • anvil_removeBlockTimestampInterval
  • evm_mine
  • anvil_enableTraces
  • eth_sendUnsignedTransaction

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

anvil_web3-0.0.3.tar.gz (9.3 kB view hashes)

Uploaded Source

Built Distribution

anvil_web3-0.0.3-py2.py3-none-any.whl (8.5 kB view hashes)

Uploaded Python 2 Python 3

Supported by

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