# 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=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.
```py
# 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](https://github.com/Wrth1/foundpy/tree/main/example) directory.
Raw data
{
"_id": null,
"home_page": null,
"name": "foundpy",
"maintainer": null,
"docs_url": null,
"requires_python": ">=3.8",
"maintainer_email": null,
"keywords": null,
"author": null,
"author_email": "Bill Elim <billelimgg@gmail.com>",
"download_url": "https://files.pythonhosted.org/packages/28/90/e2c0b05aa4f3c5e16e39893367db464024ee462d9bbffd98b8d5b5b5113d/foundpy-0.2.3.tar.gz",
"platform": null,
"description": "# foundpy\n\nFoundpy 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.\n\n```py\nfrom foundpy import *\nconfig.setup(\n rpc_url=\"http://rpc.url/\",\n privkey=\"0xdeadbeef\"\n)\nsetup_addr = \"0xE162F3696944255cc2850eb73418D34023884D1E\"\ncast.send(setup_addr, \"solve(bytes)\", b\"args123\")\ncast.call(setup_addr, \"isSolved()\")\n```\n\n## Installation\n\nfoundpy can be installed using pip:\n\n```sh\npip install foundpy\n```\n\n## Usage\n\n### Initialization\n\nfoundpy is best used with jupyter notebooks. But it can be used in a python script as well.\n\nFirst, initialize the configuration with the RPC and your private key:\n\n```py\nfrom foundpy import *\nconfig.setup(\n rpc_url=\"http://rpc.url/\",\n privkey=\"0xdeadbeef\"\n)\n```\n\nif you want to change the version of the solidity compiler, you can use the `config.change_solc_version()` function:\n\n```py\nconfig.change_solc_version(\"0.8.13\")\n```\n\nif 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`\n\n```py\nresult = config.from_tcp1p(\"http://103.178.153.113:30001\")\nsetup = Contract(result[\"setup_contract\"], \"Setup.Sol\")\n```\n\nalso if you are playing HackTheBox challenges, you can use the `config.from_htb` function\n\n```py\nresult config.from_htb(address=\"http://94.237.59.180:51929\")\nsetup = Contract(result[\"setupAddress\"], \"Setup.Sol\")\n```\n\nOnce you have solved the challenges, simply call the `config.flag()` function\n\n```py\nassert setup.call(\"isSolved\")\nprint(config.flag())\n```\n\n### Interacting with Contracts\n\nTo interact with a contract, you can either use the `cast` object or instantiate a `Contract` object (source code required).\n\n```py\nsetup_addr = \"0xE162F3696944255cc2850eb73418D34023884D1E\"\ncast.send(setup_addr, \"solve(bytes)\", b\"args123\" value=0)\n# or\nsetup = Contract(setup_addr, \"Setup.Sol\") # or \"Setup.Sol:Setup\" to specify the class\nsetup.send(\"solve\", b\"args123\", value=0)\n```\n\n### Deploying Contracts\n\nTo 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.\n\n```py\n# This will return an address\nattack = forge.create(\"Attack.sol:Attack\", setup_addr, value=int(1*(10**18)))\n# or\n# This will return a Contract object, which you can interact with attack.call or attack.send\nattack = deploy_contract(\"Attack.sol\", setup.address, value=int(1*(10**18))) # or \"Attack.Sol:Attack\" to specify the class\n```\n\nYou can check for more examples in the [example](https://github.com/Wrth1/foundpy/tree/main/example) directory.",
"bugtrack_url": null,
"license": null,
"summary": "Python implementation of Foundry using python web3 module",
"version": "0.2.3",
"project_urls": {
"Homepage": "https://github.com/Wrth1/foundpy",
"Issues": "https://github.com/Wrth1/foundpy/issues",
"Repository": "https://github.com/Wrth1/foundpy.git"
},
"split_keywords": [],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "9992fc3e83fc94a99b3d81af738ba5686828caff662d9adb76c6547c0d11e8ba",
"md5": "a19afae0c3cd5470801a603fa6c79e0f",
"sha256": "913ce0c5272a18c780d419ade8769954657ccbd50e2a085455a6b6ab673d9f6c"
},
"downloads": -1,
"filename": "foundpy-0.2.3-py3-none-any.whl",
"has_sig": false,
"md5_digest": "a19afae0c3cd5470801a603fa6c79e0f",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.8",
"size": 7892,
"upload_time": "2024-12-02T02:44:50",
"upload_time_iso_8601": "2024-12-02T02:44:50.597860Z",
"url": "https://files.pythonhosted.org/packages/99/92/fc3e83fc94a99b3d81af738ba5686828caff662d9adb76c6547c0d11e8ba/foundpy-0.2.3-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "2890e2c0b05aa4f3c5e16e39893367db464024ee462d9bbffd98b8d5b5b5113d",
"md5": "5848afbe4716820ae3bdc0ca5ca7bdf7",
"sha256": "7c2b6ea590967988ac5aee767b8841a216fb21aa5586087d86a2cb72f90c0408"
},
"downloads": -1,
"filename": "foundpy-0.2.3.tar.gz",
"has_sig": false,
"md5_digest": "5848afbe4716820ae3bdc0ca5ca7bdf7",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.8",
"size": 11559,
"upload_time": "2024-12-02T02:44:52",
"upload_time_iso_8601": "2024-12-02T02:44:52.367650Z",
"url": "https://files.pythonhosted.org/packages/28/90/e2c0b05aa4f3c5e16e39893367db464024ee462d9bbffd98b8d5b5b5113d/foundpy-0.2.3.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-12-02 02:44:52",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "Wrth1",
"github_project": "foundpy",
"travis_ci": false,
"coveralls": false,
"github_actions": false,
"requirements": [
{
"name": "eth_abi",
"specs": [
[
"==",
"5.1.0"
]
]
},
{
"name": "hexbytes",
"specs": [
[
"==",
"1.2.1"
]
]
},
{
"name": "py_solc_x",
"specs": [
[
"==",
"2.0.3"
]
]
},
{
"name": "Requests",
"specs": [
[
"==",
"2.32.3"
]
]
},
{
"name": "tqdm",
"specs": [
[
"==",
"4.66.5"
]
]
},
{
"name": "web3",
"specs": [
[
"==",
"7.4.0"
]
]
}
],
"lcname": "foundpy"
}