TLDR:
votingFor
, classLocksFor
), developers can retrieve voting states and locked GLMR details in real time.Moonbeam is an EVM-compatible network, however it’s not a run-of-the-mill one. Instead, it’s pretty interesting. Moonbeam is one the first parachains launched on Polkadot. See the Polkadot blog post from 2021: Parachains are Live!
Moonbeam (the nodes specifically) is built using the Substrate framework and the Polkadot SDK. Being EVM-compatible, it’s a path for Ethereum developers to get familiar with the Polkadot ecosystem.
Moonbeam has a few Solidity precompiles to ease the developer life and to cross-operate with Polkadot. Check them out in the Moonbeam docs: Overview of the Precompiled Contracts on Moonbeam.
The precompiled contract that we’ll have a look at as part of this tutorial is the conviction voting one. See: Conviction Voting Precompile Contract.
The contract is pretty active in receiving transactions, so it’s perfect for our demo. What we are going to do is monitor it for incoming transactions, extract the transaction data, and call the contract to retrieve the voting state based on the transactions data.
We are going to do this in Python and with the Chainstack Moonbeam nodes.
First, a few words on conviction voting and the Moonbeam contract.
Conviction voting is a relatively novel iteration of a voting algorithm that’s been out for a while and that’s called quadratic voting.
The short version of quadratic voting & conviction voting is:
You can check the following resources for more details:
Let’s implement a simple monitoring of the conviction voting contract in Python.
Log in to your Chainstack account and deploy a node.
To interact with the contract, you need the contract ABI.
Since it’s a precompile, it’s not readily available on the Moonbeam explorer. Let’s generate one:
Go to Remix IDE.
Create the ConvictionVoting.sol
file and paste the actual Solidity code from the Moonbeam GitHub repository: ConvictionVoting.sol.
In Remix IDE, click Solidity Compiler > Compile.
When compiled, hit ABI. This will copy the ABI of the contract.
Save the ABI as a ConvictionVoting.abi
file in the same directory where you are going to have the Python script.
Now that you have ABI, create the script.
A few details on the implementation:
0x0000000000000000000000000000000000000812
.votingFor
and classLocksFor
to retrieve the voting track ID, the index of poll, and the locked amount of the GLMR tokens. You can check what these are in the Moonbeam voting dapp.where
NODE_URL
— your Moonbeam node endpointBLOCK_NUMBER
— the block number from which to start iterating over the blocks for the conviction voting transactions.This tutorial guided you through setting up the monitoring of the Moonbeam conviction voting system and how retrieve the data off the contract based on the decoded transactions.
TLDR:
votingFor
, classLocksFor
), developers can retrieve voting states and locked GLMR details in real time.Moonbeam is an EVM-compatible network, however it’s not a run-of-the-mill one. Instead, it’s pretty interesting. Moonbeam is one the first parachains launched on Polkadot. See the Polkadot blog post from 2021: Parachains are Live!
Moonbeam (the nodes specifically) is built using the Substrate framework and the Polkadot SDK. Being EVM-compatible, it’s a path for Ethereum developers to get familiar with the Polkadot ecosystem.
Moonbeam has a few Solidity precompiles to ease the developer life and to cross-operate with Polkadot. Check them out in the Moonbeam docs: Overview of the Precompiled Contracts on Moonbeam.
The precompiled contract that we’ll have a look at as part of this tutorial is the conviction voting one. See: Conviction Voting Precompile Contract.
The contract is pretty active in receiving transactions, so it’s perfect for our demo. What we are going to do is monitor it for incoming transactions, extract the transaction data, and call the contract to retrieve the voting state based on the transactions data.
We are going to do this in Python and with the Chainstack Moonbeam nodes.
First, a few words on conviction voting and the Moonbeam contract.
Conviction voting is a relatively novel iteration of a voting algorithm that’s been out for a while and that’s called quadratic voting.
The short version of quadratic voting & conviction voting is:
You can check the following resources for more details:
Let’s implement a simple monitoring of the conviction voting contract in Python.
Log in to your Chainstack account and deploy a node.
To interact with the contract, you need the contract ABI.
Since it’s a precompile, it’s not readily available on the Moonbeam explorer. Let’s generate one:
Go to Remix IDE.
Create the ConvictionVoting.sol
file and paste the actual Solidity code from the Moonbeam GitHub repository: ConvictionVoting.sol.
In Remix IDE, click Solidity Compiler > Compile.
When compiled, hit ABI. This will copy the ABI of the contract.
Save the ABI as a ConvictionVoting.abi
file in the same directory where you are going to have the Python script.
Now that you have ABI, create the script.
A few details on the implementation:
0x0000000000000000000000000000000000000812
.votingFor
and classLocksFor
to retrieve the voting track ID, the index of poll, and the locked amount of the GLMR tokens. You can check what these are in the Moonbeam voting dapp.where
NODE_URL
— your Moonbeam node endpointBLOCK_NUMBER
— the block number from which to start iterating over the blocks for the conviction voting transactions.This tutorial guided you through setting up the monitoring of the Moonbeam conviction voting system and how retrieve the data off the contract based on the decoded transactions.