Metadata-Version: 2.4
Name: foundpy
Version: 0.3.0
Summary: Python implementation of Foundry using python web3 module 
Project-URL: Homepage, https://github.com/Wrth1/foundpy
Project-URL: Repository, https://github.com/Wrth1/foundpy.git
Project-URL: Issues, https://github.com/Wrth1/foundpy/issues
Author-email: Bill Elim <billelimgg@gmail.com>
License-File: LICENSE
Classifier: License :: OSI Approved :: MIT License
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3
Requires-Python: >=3.8
Requires-Dist: eth-abi>=5.1.0
Requires-Dist: hexbytes>=1.2.1
Requires-Dist: py-solc-x>=2.0.3
Requires-Dist: requests>=2.32.3
Requires-Dist: tqdm>=4.66.5
Requires-Dist: web3>=7.4.0
Description-Content-Type: text/markdown

# foundpy

Foundpy is a Python implementation of a popular toolkit [Foundry](https://github.com/foundry-rs/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.

```py
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:

```sh
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:

```py
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:

```py
config.change_solc_version("0.8.13")
```

if you are doing a CTF Challenges and it uses the [TCP1P ParadigmCTF Infra](https://github.com/TCP1P/Paradigmctf-BlockChain-Infra-Extended), you can use the `config.from_tcp1p` function instead of `config.setup`

```py
result = config.from_tcp1p("http://103.178.153.113:30001")
setup = Contract(result["setup_contract"], "Setup.Sol")
```

also if you are playing HackTheBox challenges, you can use the `config.from_htb` function

```py
result = config.from_htb(address="http://94.237.59.180:51929")
setup = Contract(result["setupAddress"], "Setup.Sol")
```

Once you have solved the challenges, simply call the `config.flag()` function

```py
assert setup.call("isSolved")
print(config.flag())
```

### Interacting with Contracts

To interact with a contract, you can either use the `cast` object or instantiate a `Contract` object (source code required).

```py
setup_addr = "0xE162F3696944255cc2850eb73418D34023884D1E"
cast.send(setup_addr, "solve(bytes)", b"args123" value=ether(0.5))
# or
setup = Contract(setup_addr, "Setup.Sol") # or "Setup.Sol:Setup" to specify the class
setup.send("solve", b"args123", value=ether(0.5))
```

### 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.

```py
# This will return an address
attack = forge.create("Attack.sol:Attack", setup_addr, value=ether(1))
# 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=ether(1)) # or "Attack.Sol:Attack" to specify the class
```

You can check for more examples in the [example](https://github.com/Wrth1/foundpy/tree/main/example) directory.