Web3 Solidity Connector

Overview

Web3 Solidity Connector

With this project, you can compile your sol files and create new transactions including creating contract and calling the state changer functions. You can integrate integrate your sol files with Python and you can call functions with using Python.

Program Life Cycle

  1. Compile the Solidity(.sol) file
  2. Deploy the contract which is in Solidity file
  3. Manipulate the main.py file for calling and executing relevant functions in contract even with parameters via the help of Web3

Folder Structure

To assure the program is working, there are folder structure rules to follow.

  1. This projects points to sol_files folder for your Solidity files. This means sol_files folder must contain your .sol extensioned files. You should select one of the sol file in this directory to be compiled.

  2. After you execute compile.py, "compilation_files_out" folder will be created which contains your output files. "compiled_abi.json" and "compiled_bytecode.txt" files should not be deleted or overwritten! You can examine your compiled code in "compiled_code.json" file.

  3. global_variables.py file contains your default paths for compilation files and the sol files that will be compiled. You can change this structure any way you want.

GLOBAL_COMPILATION_PATH = "./compilation_files_out"  # folder that contains output files
GLOBAL_SOL_PATH = "./sol_files"  # folder that contains sol file

Running the Program

  1. Clone the repository
git clone https://github.com/TekyaygilFethi/ContractDeploment.git
  1. Create an .env file on current folder that contains your address(with MY_ADDRESS key), private key(with PRIVATE_KEY key), rinkeby rpc url(with RINKEBY_RPC_URL key) and chain id(with CHAIN_ID key) values. Your .env file should look like this:
PRIVATE_KEY ="0x{YOUR PRIVATE KEY}"
RINKEBY_RPC_URL = "{YOUR RINKEBY RPC URL}"
MY_ADDRESS = "{YOUR ADDRESS}"
CHAIN_ID = "{YOUR CHAIN ID}"
  1. Install the dependencies from requirements.txt file.
pip install -r requirements.txt
  1. After setting the .env file, to run the program, you first need to go to the project directory and run:
python compile.py {YOUR_SOL_FILE} // python compile.py SimpleContract.sol

! Please note that your sol files must be in the folder sol_files folder by default or in the folder you specified custom in global_variables.py file by assigning to GLOBAL_SOL_PATH.

  1. After compilation you should see screen like this:
Compilation folder created!
Compiled successfully!
  1. When you check your folders, you can see compilation_files_out folder is created. If you changed the folder path and name from global_variables you may see different folder. This folder be based on when deploying your contracts and running your Solidity functions!

  2. For next step, you must deploy your compiled contract. To do this, you must run:

python deploy.py

This command will creates a transaction for contract creation based on your compiled Solidity file. This command will output the success message, transaction receipt and contract address. To use this deployed contract and it's functions, you must copy the address of this deployed contract. You should see response like this (Please note that receipt and address may differ)

New Contract Transaction has been created!

AttributeDict({'transactionHash': HexBytes('0x19f1237cd0bf13bf1112f7e60b9dd7570dcca38c18718368e09c462e01482272'), 'transactionIndex': 0, 'blockHash': HexBytes('0xa47912b38dec2fdecfed283da5fd6a7d778def3f62bc2c629373903cbd5f59bc'), 'blockNumber': 34, 'from': '0x2DAc2487DD401D9E5C757eb03B8928b70FFaFe6e', 'to': None, 'gasUsed': 640222, 'cumulativeGasUsed': 640222, 'contractAddress': '0x874E06Aff5a1031Bd5AE07100A7A518D0C72b8E2', 'logs': [], 'status': 1, 'logsBloom': HexBytes('0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000')})

Contract Address: 0x874E06Aff5a1031Bd5AE07100A7A518D0C72b8E2 //This address you should copy.
  1. Edit your main.py content according to your functions. For example, I have addHero function in my compiled Solidity:
struct Hero {
    string name;
    string lightsaberColor;
    uint256 age;
}

Hero[] heroes;

function addHero(
        string memory _name,
        string memory _lightsaberColor,
        uint256 _age
    ) public {
        heroes.push(Hero(_name, _lightsaberColor, _age));
        uint256 idx = heroes.length - 1;
        nameToIndex[_name] = idx;
    }

You can call this function from my main.py file with parameters like this:

# write functions with their parameters if any after this line inside of executeContractFunction method.
contractOps.executeContractFunction(
    # write your contract functions as contract.functions.{your function}, your private key
    contract.functions.addHero("Obi-Wan Kenobi", "Blue", 29),
    private_key,
)

Here, contractOps is an object that allows you to perform contract operations such as creating, deploying, gathering contracts or executing a function inside a contract. And executeContractFunction is a special function that allow you to execute a functions. It creates, signs, sends and gets the receipt for transaction automatically.

  • If you have a function that is not changing a state in Solidity file you also can call it. For example here's the function that is not changing state in my Solidity file:
function getInfoByName(string memory name)
        public
        view
        returns (Hero memory)
    {
        uint256 idx = nameToIndex[name];
        return heroes[idx];
    }

function getAllHeroes() public view returns (Hero[] memory) {
        return heroes;
    }

You can call the getAllHeroes function like this:

print(contract.functions.getAllHeroes().call())

You can call the getInfoByName function which takes parameter like this:

print(contract.functions.getInfoByName("Obi-Wan Kenobi").call())

Please note that we had to use .call() at the end of the function call to gather response and make the function call.

  1. To run main.py file, you need to supply contract address. You should use the contracty address you copied at Step 6.
python main.py {ContractAddress}

Here is an example:

python main.py 0x874E06Aff5a1031Bd5AE07100A7A518D0C72b8E2

And you can see the results when you execute this command: Result

And you're done! Congratulations!

Owner
Fethi Tekyaygil
.NET Core Backend & @google Certified #tensorflow Developer - Flutter & Solidity #padawan - Animal Person
Fethi Tekyaygil
To lazy to read your homework ? Get it done with LOL

LOL To lazy to read your homework ? Get it done with LOL Needs python 3.x L:::::::::L OO:::::::::OO L:::::::::L L:::::::

KorryKatti 4 Dec 08, 2022
The Great Autoencoder Bake Off

The Great Autoencoder Bake Off The companion repository to a post on my blog. It contains all you need to reproduce the results. Features Currently fe

Tilman Krokotsch 61 Jan 06, 2023
This repo will have a small amount of Chrome tools that can be used for DFIR, Hacking, Deception, whatever your heart desires.

Chrome-Tools Overview Welcome to the repo. This repo will have a small amount of Chrome tools that can be used for DFIR, Hacking, Deception, whatever

5 Jun 08, 2022
VCC-Generator is a python script that generate VCC for testing purposes only

VCC-Generator is a python script that generate VCC for testing purposes only

Spider Anongreyhat 10 Oct 23, 2022
Airplane reservation system python 2

airplane-reservation-system-python-2 Announcement 🔊 : 🔴 IMPORTANT 🔴 : Few new things have been added into the code [16/05/2021] different names is

voyager2005 1 Dec 06, 2021
serological measurements from multiplexed ELISA assays

pysero pysero enables serological measurements with multiplexed and standard ELISA assays. The project automates estimation of antibody titers from da

Chan Zuckerberg Biohub 5 Aug 06, 2022
Dashboard to view a stock's basic information, RSI, Bollinger bands, EMA, SMA, sentiment analysis via Python

Your One And Only Trading Bot No seriously, we mean it! Contributors Jihad Al-Hussain John Gaffney Shanel Kuchera Kazuki Takehashi Patrick Thornquist

5 May 21, 2022
List of all D&D 5e monsters: WotC + popular third-party sourcebooks

Xio's Guide to Monsters If you're a DM like me, and you have multiple sources of D&D 5e monsters that include WotC as well as third-party suppliers, y

20 Jan 06, 2023
String Spy is a project aimed at improving MacOS defenses.

String Spy is a project aimed at improving MacOS defenses. It allows users to constantly monitor all running processes for user-defined strings, and if it detects a process with such a string it will

10 Dec 13, 2022
Backtest framework based on DAGs

MultitaskQueue It's a simple framework based on three composed concepts: Task: A task is the smaller unit of execution or simple a node in the DAG, ev

4 Dec 09, 2021
🟥This is an overview of how to set up and use DataStore3 in your Roblox experiences

Welcome to DataStore3 👋 This is an overview of how to set up and use DataStore3 in your Roblox experiences What is it? 🤔 DataStore3 is a service tha

Reece Harris 7 Aug 19, 2022
FollowSpot is a comprehensive audition tracking fullstack web application for entertainment industry professionals.

FollowSpot is a comprehensive audition tracking fullstack web application for entertainment industry professionals. This app allows users to store information/media for all of their auditions while a

Jen Brissman 9 Jul 12, 2022
Collection of functions for working with interlaced content in VapourSynth.

vsfieldkit Collection of functions for working with interlaced content in VapourSynth. It does not have any hard dependencies outside of VapourSynth.

Justin Turner Arthur 11 May 27, 2022
Hasklig - a code font with monospaced ligatures

Hasklig – Ligatures for code Programming languages are limited to relatively few characters. As a result, combined character operators surfaced quite

Ian Tuomi 5.3k Jan 03, 2023
Repositório do Projeto de Jogo da Resília Educação.

Jogo da Segurança das Indústrias Acme Descrição Este jogo faz parte do projeto de entrega do primeiro módulo da Resilia Educação, referente ao curso d

Márcio Estevam da Silva 2 Apr 28, 2022
Repo to demo translating colab/jupyter notebook to streamlit webapp

Repo to demo translating colab/jupyter notebook to streamlit webapp

Marisa Smith 2 Feb 02, 2022
Projeto de Jogo de dados em Python 3 onde é definido o lado a ser apostado e número de jogadas, pontuando os acertos e exibindo se ganhou ou perdeu.

Jogo de DadoX Projeto de script que simula um Jogo de dados em Python 3 onde é definido o lado a ser apostado (1, 2, 3, 4, 5 e 6) ou se vai ser um núm

Estênio Mariano 1 Jul 10, 2021
Implemented Exploratory Data Analysis (EDA) using Python.Built a dashboard in Tableau and found that 45.87% of People suffer from heart disease.

Heart_Disease_Diagnostic_Analysis Objective 🎯 The aim of this project is to use the given data and perform ETL and data analysis to infer key metrics

Sultan Shaikh 4 Jan 28, 2022
A compiler for ARM, X86, MSP430, xtensa and more implemented in pure Python

Introduction The PPCI (Pure Python Compiler Infrastructure) project is a compiler written entirely in the Python programming language. It contains fro

Windel Bouwman 277 Dec 26, 2022
DeDRM tools for ebooks

DeDRM_tools DeDRM tools for ebooks This is a fork of Apprentice Harper's version of the DeDRM tools. I've added some of the PRs that still haven't bee

2 Jan 10, 2022