Developers
Applications
Blog
Events
ForumCreate a Bot

Python Weekly by Paloma #1 ft. Zhibai Zhang on Web3py

Background

The new Web3 Python Weekly AMA by Paloma discusses Python and its advancements on the Paloma Chain.

In this first episode of Web3 Python Weekly, the host Taariq Lewis, founder of Paloma Chain and VolumeFi (volume.finance) is joined by Paloma’s DeFi Strategist, Zhibai @fieldtheory. The two discuss Web3.py and its contribution to Paloma and talk about future plans in the coming year.

Python is a high-level, general-purpose programming language. It supports multiple programming paradigms, including structured, object-oriented and functional programming. For cryptocurrency, Python is useful for blockchain as anyone can add to the chain without the transactions being processed in parallel. It enables developers to create a simple blockchain in under 50 lines of code. Its design philosophy emphasizes code readability with the use of significant indentation.

Definitions

  • AMA – Ask Me Anything

  • GRAIN – Paloma’s native Token.

  • Solidity – an object-oriented programming language created specifically by the Ethereum Network team for constructing and designing smart contracts on Blockchain platforms.

  • Smart Contract – a computer program or transaction protocol automatically executing when predetermined conditions are met.

  • Node – a component of cryptocurrency required for most popular currencies such as Bitcoin and Dogecoin, to function.

  • CosmWasm – the Cosmos (Cosm) way of using WebAssembly (Wasm), a contracting platform built specifically for the Cosmos ecosystem.

  • Cosmos – an ever-expanding ecosystem made up of sovereign and interoperable blockchain apps, protocols, and services.

  • PIP (Preferred Installer Program) – a package management system used to install and manage software packages written in Python.

  • Ethereum – a decentralized blockchain platform that establishes a peer-to-peer network that securely executes and verifies application code, called smart contracts.

  • Eth or Ether – the native cryptocurrency of the Ethereum network.

  • UI – User Interface

  • Validator – users that volunteer a computer’s computing power to maintain a blockchain’s integrity by computing or tracing the origins of a block to its present state.

  • Gas – the fee required to successfully conduct a transaction or execute a contract on a blockchain.

  • Software Development Kit (SDK) – brings together a set of tools that facilitate the programming of applications. It enables the use of APIs.

  • Relayer – a third party that takes on individual orders and organizes them into an order book simulating the experience of an exchange without actually being one.

Web3 Python Weekly (5:48)

Taariq Lewis starts the show by welcoming everyone to Paloma’s new show, Web3 Python Weekly. He says that Paloma AMAs cannot be done anymore because if you have a token to mainnet, the show might be construed as pumping the token. The host and the guest brainstormed about the name of the show, then proceed to introduce Web3 Python Weekly as Paloma Chain’s new show since Paloma uses Python in a big way. The show will cover all that is happening in the world of Web3 in Python and Python on Paloma. Taariq looks forward to having more guests in the future.

Source: https://twitter.com/paloma_chain/status/1602882895692996608/photo/1

Web3 Python Library (8:59)

Zhibai first introduces himself and shares what he works on. He says he is a DeFi strategist at Paloma and he works on broader DeFi strategies across different chains. His day-to-day involves a lot of running analysis on chain option data and uses the analysis and insight generated from the data to provide basic trading transaction liquidity, and pretty much all DeFi-related activity analysis, which they use to support the building of their cross-chain AMM, the building of their gas refund strategies and anything that could benefit from data analysis.

Taariq thanked the guest for the introduction and proceeded to jump on the Web3 topic. The guest says that Python has been greatly involved in Paloma’s development and says that there will be more to come. The host asks what makes Web3 interesting. Zhibai shares that most people who are in crypto, as long as they've done a little bit of  developing, know that smart contracts on the EVM side are written natively in a language called Solidity, but later on, other languages have been developed, such as Python, to give people ways to interact with the blockchain. He says that the common mentality among Python users is that Python is so big, there should be something built for Python users. He explains:

“If they want to come in, they don't want to learn any other languages. They just want to use Python to do what they want to do. And for EVM chains, unfortunately, Solidity is not something that's very Pythonic. There have been efforts to build Python packages to have Python users just do transactions, data queries, and some related similar activity, what we do in crypto. This is mostly an open-source effort. There have been many different projects out of which I have personally found Web3.py is the best package on the EVM site. And it is a Python library, one can very easily install, and from there, they can just write Python scripts to do certain things.”

Solidity (13:55)

The host asks if he still has to write the Solidity drill if he wants to write in on an EVM using Web3.py as a Python Dev. The guest says yes and at some point, he still has to go back to Solidity where he can create a new smart contract. He further dives into Web3:

Web3.py allows you to interact and call functions from existing smart contracts. Either they are already deployed on-chain or somehow, you have the source code. So, you can use Web3.py to deploy the code and the contract, but you have to have the code. In order to have a new contract, you got to go back to Solidity.”

Source: https://moralis.io/solidity-explained-what-is-solidity/

Taariq then clarifies that if the Solidity contract is written, then Web3.py can be used to interact with the contracts. He says that for many developers, those contracts already exist, such as Uniswap V3. Zhibai agrees and says that in terms of the most commonly used functions in Uniswap, such as swap-and-add and remove liquidity, one can just call an existing function to execute those functions. But if something more complex such as setting up liquidity mining interaction or liquidity mining program on Uniswap, a Liquidity Mining Solidity contract must be written, and then write Python commands to execute the functions in that contract. They also add that Web3.py also works in any of the other EVM chains. When going from one EVM to another, Zhibai says to simply just change the node.

Paloma’s Python SDK (17:03)

The host asks the guest if he thinks that Paloma’s SDK is a sort of Python SDK inspired by Web3.py. He answers yes as Web3.py already covers the most commonly used functionalities, and how one would interact with the chain. Therefore, he says, Paloma’s current Python SDK has a very similar implementation and one can basically use it to query a smart contract, check the balance of a wallet, and sign transactions. Taariq finds it awesome and says that he doesn’t even need to know how to use CosmWasm since he could use Paloma’s Python SDK to execute transactions on some of the basic transactions on either the Paloma client or Paloma Chain, and maybe even the contracts that are already deployed on Paloma. The guest then shares his insight:

“I think that's actually a key difference between Cosmos chain and EVM because, for EVM, there's also Viper, which is Pythonic smart contract language. But CosmWasm is very far away from Python.”

Web3.py (18:38)

Going back to Web3.py, Taariq asks Zhibai to thoroughly discuss how Web3.py works. The guest was happy to share:

Web3.py, just as your common Python library, you can PIP install. It's just a one-liner. If you type in PIP install Web3.py, the library will just be automatically downloaded and installed into your local Python environment. Then, open your favorite Python interpreter, let's say it's a Jupyter Notebook. Then, you can import all the functions from that library. So, there are a few key things that everybody has to do. For instance, you have to tell Web3.py what your wallet is. Your order to actually sign a transaction. So, how does one do that? You have to define a variable that basically is your private key, so keep it safe on your local machine as a variable. For instance, load it into a pipeline interpreter, set it to be a variable, and pass it into–so Web3.py has a class and you instantiate a class. There's a function you call that automatically connects to a node. So, you also have to tell them what node you're using.”

Source: https://web3py.readthedocs.io/en/latest/

The host then gives a special shout-out to Pocket Network (POKT) who keeps supporting Paloma. He promotes POKT and says that they got their nodes set up via POKT. Going back, Zhibai continues to discuss and says that upon checking how much Eth one has on their wallet, they just have to run a command from Web3.py automatically in their Jupyter Notebook and see how much balance shows up in their wallet. And if they would like to check the status of an EVM, such as Ethereum, just run the function called GetBlock, which indicates the current block height and several pieces of information about the height; how many transactions were mined and et cetera. He adds:

“By specifying the hash of a transaction, you can pull the transaction data from on-chain data and see what was the transaction, what was the sender of the transaction, what was the receiver, the amount, the input data, et cetera. And then, going from there, I would say I think that the most used function is signed transaction. It involves putting together some data to form a transaction message. It covers which in the contract you're interacting with, what's the address, and what's the value. And once you have that, specify the gas, providing you're waiting to pay and sign the transaction. So, signing the transaction under the hood is essentially the–Python is just calling some lower-level languages to encrypt the message, and send it to the node. And now your message is going to the man pool. And then, after some waiting for that transaction to go through, you are already–you sent your transaction, you didn't use a wallet product, and you didn't use a UI. So, everything's just done on the backend.”

Taariq asks if it’s also the same with Paloma Python SDK; if he can query the hash of the block and sign transactions on Paloma with the Paloma SDK. The guest says that the whole implementation is very similar, there’s just a little change. Zhibai adds that they have been talking about the limitation of Web3.py. He says that it works great if the contract is already there. If one wants to call a function from a contract, it has to be there. But what if it’s not there? The guest said they currently have the same problem in Paloma. He says it’s not a problem, but rather the feature they’re building and looking forward to, but unfortunately cannot talk or mention it.

The Paloma-Python SDK Use Case (26:42)

Since they can’t talk about what they are currently building, Zhibai decides to share an interesting use case for Python SDK. He says:

“At Paloma, we do a lot of cross-chain communication, as such we have gas on Paloma, but we will also cover the gas payment on a target chain. Previously, we have had relayers working on Ethereum and to cover their gas cost, which is in Ether, we built a product that involves the Pythonic implementation. Namely, we were querying all the relayer transactions and using Python to verify that they actually spent the gas on validating our cross-chain transactions and then also using Python to determine how much they spent from on-chain data.”

They add that Python is used to allow Paloma to refund the gas spent on Ethereum by the validators that were relaying transactions or messages on Ethereum from the Paloma blockchain. The guest adds that everything is all squeezed into one Python script. Within the same script, they query the data, run the analysis without data transactions, and they determine how much gas they need to be covered. By the end, they use Web3.py to sign a transaction to repay their validators on the Ethereum side.

Taariq mentions that Paloma’s first version of the gas fee, the gas fee economy, which is refunding validators or paying validators for relaying messages was powered by Web3.py. He says that it also worked on Binance Smart Chain as well as Ethereum mainnet.

The host says that it is an opportunity where devs working on Paloma can now use Paloma’s Python SDK to execute cross-chain relay transactions and messages. Then, they can use Web3.py to interact with those transactions and continue to build on that. So, complex logic can be built both with Paloma and on Ethereum, sort of using the framework taken from Web3.py, putting it into the Python SDK, and taking advantage of Web3.py and its needed form on the EVM.

Closing Remarks

Taariq wraps up the show by saying there will be more Python Weekly AMAs to come in the coming year. The host and Zhibai are looking forward to more exciting topics to cover in future episodes. He thanks everyone and says that Paloma embraces Web3.py and the Python community.

Stay tuned for more news and updates on the Paloma chain. Follow us on Twitter @paloma_chain, get on the Discord server (https://discord.gg/Tv9F9AH4), and join the flock. Coo!