I want to know if it is possible to use the web3 API with the flask framework instead of meteor or nodejs. if so how do I add it to my flask project?
Web3.js – Using Web3 with Flask Framework
web3js
Related Solutions
You can try web3.net.listening
web3.net.listening
// or async
web3.net.getListening(callback(error, result){ ... })
This property is read only and says whether the node is actively listening for network connections or not.
Returns
Boolean - true
if the client is actively listening for network connections, otherwise false
.
- N/A, in that you don't need to unlock an account at all.
- Yes, see below.
The following uses Web3.js version 1.0.0-beta which is now the default installed by npm. Note that no node is attached.
> var Web3 = require('web3');
> var web3 = new Web3();
> web3.version
'1.0.0-beta.10'
The second parameter in the below is the private key:
> web3.eth.accounts.sign("Hello, world!", '0x0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef')
{ message: 'Hello, world!',
messageHash: '0xb453bd4e271eed985cbab8231da609c4ce0a9cf1f763b6c1594e76315510e0f1',
v: '0x1b',
r: '0x3bc843a917d6c19c487c1d0c660cdd61389ce2a7651ee3171bcc212ffddca164',
s: '0x193f1f2e06f7ed8f9fbf2254232d99848a8102b552032b68a5507b4d81492f0f',
signature: '0x3bc843a917d6c19c487c1d0c660cdd61389ce2a7651ee3171bcc212ffddca164193f1f2e06f7ed8f9fbf2254232d99848a8102b552032b68a5507b4d81492f0f1b' }
And the signature checks out, too (the recovered account is the same as the account generated from the private key directly):
> web3.eth.accounts.recover('0xb453bd4e271eed985cbab8231da609c4ce0a9cf1f763b6c1594e76315510e0f1', '0x1b', '0x3bc843a917d6c19c487c1d0c660cdd61389ce2a7651ee3171bcc212ffddca164', '0x193f1f2e06f7ed8f9fbf2254232d99848a8102b552032b68a5507b4d81492f0f')
'0xFCAd0B19bB29D4674531d6f115237E16AfCE377c'
>
> web3.eth.accounts.privateKeyToAccount('0x0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef');
{ address: '0xFCAd0B19bB29D4674531d6f115237E16AfCE377c',
privateKey: '0x0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef',
...}
Best Answer
I assume you are referring to writing python code to interact with Ethereum. If you want to integrate Ethereum with your python code, then you could go for the web3py package. It allows you to write interactions with the blockchain or specific smart contracts (assuming you have the ABI). It is basically a python implementation for web3.js.
Documentation for web3py can be found here: web3py docs
Documentation for web3.js can be found here: web3.js docs