Python implementation of Foundry using python web3 module
Project description
foundpy
Foundpy is a Python implementation of a popular toolkit Foundry. It replicates Foundry's core functionality without needing Foundry's installation. Foundpy enables users to use Python's web3 module with similar command style as Foundry. Foundpy is also equipped with extra features that is primarily used in CTF challenges.
from foundpy import *
config.setup(
rpc_url="http://rpc.url/",
privkey="0xdeadbeef"
)
setup_addr = "0xE162F3696944255cc2850eb73418D34023884D1E"
cast.send(setup_addr, "solve(bytes)", b"args123")
cast.call(setup_addr, "isSolved()")
Installation
foundpy can be installed using pip:
pip install foundpy
Usage
Initialization
foundpy is best used with jupyter notebooks. But it can be used in a python script as well.
First, initialize the configuration with the RPC and your private key:
from foundpy import *
config.setup(
rpc_url="http://rpc.url/",
privkey="0xdeadbeef"
)
if you want to change the version of the solidity compiler, you can use the config.change_solc_version()
function:
config.change_solc_version("0.8.13")
if you are doing a CTF Challenges and it uses the TCP1P ParadigmCTF Infra, you can use the config.from_tcp1p
function instead of config.setup
config.from_tcp1p("http://103.178.153.113:30001")
also if you are playing HackTheBox challenges, you can use the config.from_htb
function
config.from_htb(address="http://94.237.59.180:51929")
Interacting with Contracts
To interact with a contract, you can either use the cast
object or instantiate a Contract
object (source code required).
setup_addr = "0xE162F3696944255cc2850eb73418D34023884D1E"
cast.send(setup_addr, "solve(bytes)", b"args123" value=0)
# or
setup = Contract(setup_addr, "Setup.Sol") # or "Setup.Sol:Setup" to specify the class
setup.send("solve", b"args123", value=0)
Deploying Contracts
To deploy a contract, you can either use the forge
object or use the deploy_contract
function. Simply make sure that the contract's source code is in the same directory as the script. The constructor arguments can be passed by adding them to the function call after the filename.
# This will return an address
attack = forge.create("Attack.sol:Attack", setup_addr, value=int(1*(10**18)))
# or
# This will return a Contract object, which you can interact with attack.call or attack.send
attack = deploy_contract("Attack.sol", setup.address, value=int(1*(10**18))) # or "Attack.Sol:Attack" to specify the class
You can check for more examples in the example directory.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file foundpy-0.2.0.tar.gz
.
File metadata
- Download URL: foundpy-0.2.0.tar.gz
- Upload date:
- Size: 15.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.12.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | b9b50800da2dbd02a13bb4bd70480601c6327b04e43ffc422eebdb9cf07d4975 |
|
MD5 | 7695b54233296f67db362a1891856adf |
|
BLAKE2b-256 | 3df231a97d163eb06e6d39e287f65268dc44f85bea3a4c760222b6b0d3600649 |
File details
Details for the file foundpy-0.2.0-py3-none-any.whl
.
File metadata
- Download URL: foundpy-0.2.0-py3-none-any.whl
- Upload date:
- Size: 7.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.12.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6dbb099d1d4e44b798094337befd41f83ef5cc974b7c63759e742f3b0d55d975 |
|
MD5 | 13b549a1cf16d5cc91f8f927f2b5b6b0 |
|
BLAKE2b-256 | 0ebeeb6f96ed35c992d396da2eb8be5a623d7946ca2ed91126d1014aef4b52e0 |