A simple project demonstrating how to develop, test, deploy and interact with an Ethereum smart contract using Foundry and a Python backend.
.
├── backend/ # FastAPI + Web3.py
├── lib/ # Foundry dependencies
├── postman/ # Postman collection
├── script/ # Deployment scripts
├── src/ # Smart contracts
├── test/ # Foundry tests
├── foundry.toml
├── LICENSE
└── README.md
- Solidity
- Foundry
- Anvil
- Python
- FastAPI
- Web3.py
- Postman
curl -L https://foundry.paradigm.xyz | bash
foundryupVerify the installation:
forge --version
cast --version
anvil --versionforge buildforge testanvilforge script script/Counter.s.sol:CounterScript \
--rpc-url http://127.0.0.1:8545 \
--private-key <ANVIL_PRIVATE_KEY> \
--broadcastCopy the deployed contract address.
cast call <CONTRACT_ADDRESS> \
"number()(uint256)" \
--rpc-url http://127.0.0.1:8545cast send <CONTRACT_ADDRESS> \
"setNumber(uint256)" 10 \
--private-key <ANVIL_PRIVATE_KEY> \
--rpc-url http://127.0.0.1:8545cast send <CONTRACT_ADDRESS> \
"increment()" \
--private-key <ANVIL_PRIVATE_KEY> \
--rpc-url http://127.0.0.1:8545cast call <CONTRACT_ADDRESS> \
"number()(uint256)" \
--rpc-url http://127.0.0.1:8545cd backend
pip install fastapi uvicorn web3Update the following value inside:
backend/main.py
CONTRACT_ADDRESS = "<DEPLOYED_CONTRACT_ADDRESS>"uvicorn main:app --reloadImport the collection located in:
postman/
Available requests:
- GET - Blockchain status
- GET - Get counter number
- POST - Set counter number
- POST - Increment counter number