1

I posted a question yesterday but deleted it, since I did things differently. However, the problem remains the same and I really need to get through this:

GOAL

Automatically connect to Parity account, automatize the use of a smart contract with web3

smart contract

That contract simply notarizes (put into the bockchain) a string. The function to call is Notarize("whatever you want")

my code

# -*- coding: utf-8 -*-
# -*- coding: utf-8 -*-

from web3 import Web3, HTTPProvider
import subprocess
import json
import time

#launching parity, chain: kovan testnet, using TOML file (must be correctly configured!)
#subprocess.run() or call() won't work as it doesn't return until it is finished. Popen() does the trick
#finally, runing only "parity.exe" will run the FUNDATION chain without the CLI taken into account. So, CLI must be added as well

subprocess.Popen('C:\Program Files\Parity Technologies\Parity\parity.exe --chain "kovan" --jsonrpc-apis  "eth,net,web3,personal,parity" --pruning "fast" --tracing "off" --fat-db "off"')

#let some time before the next command
time.sleep(5)

#interacting with blockchain client as a HTTP object
w3= Web3(HTTPProvider("http://127.0.0.1:8180"))

#unlocking account
w3.personal.unlockAccount("0x00.....", "password")

test=w3.eth.blockNumber

print(test)

#define contract adress and contract instance
contractAddress="0xdE..."

#define abi JSON of smartcontract, parsing it and using it further as contract instance
with open("C:/Users/jaekl/Documents/scripts/python/ethereum_blockchain.json", "r") as f:
    abi=json.load(f)

#contract instance:
contract_instance=w3.eth.contract(abi, contractAddress)

#using the function "notarize" of the smart contract to send a string on the blockchain kovan
to_send=contract_instance.transact({"from":"0x00..."}) .notarize("a string")

ERROR/problem

I can connect to Parity with the subprocess. I manage to see the last block for exemple (see code). But I need to unlock my account in order to interact with my contract. However, an error keeps poping up:

runfile('C:/Users/jaekl/Documents/scripts/python/ethereum_blockchain/parity_automatization.py', wdir='C:/Users/jaekl/Documents/scripts/python/ethereum_blockchain')
Traceback (most recent call last):

  File "<ipython-input-1-92ff1f4de1cb>", line 1, in <module>
    runfile('C:/Users/jaekl/Documents/scripts/python/ethereum_blockchain/parity_automatization.py', wdir='C:/Users/jaekl/Documents/scripts/python/ethereum_blockchain')

  File "C:\Users\jaekl\Anaconda3\lib\site-packages\spyder\utils\site\sitecustomize.py", line 880, in runfile
    execfile(filename, namespace)

  File "C:\Users\jaekl\Anaconda3\lib\site-packages\spyder\utils\site\sitecustomize.py", line 102, in execfile
    exec(compile(f.read(), filename, 'exec'), namespace)

  File "C:/Users/jaekl/Documents/scripts/python/ethereum_blockchain/parity_automatization.py", line 22, in <module>
    w3.personal.unlockAccount("0x00...", "password")

  File "C:\Users\jaekl\Anaconda3\lib\site-packages\web3\personal.py", line 93, in unlockAccount
    [account, passphrase, duration],

  File "C:\Users\jaekl\Anaconda3\lib\site-packages\web3\manager.py", line 96, in request_blocking
    raise ValueError(response["error"])

ValueError: {'code': -32601, 'message': 'Method not found'}

I tried everything possible. Read a lot of posts/issues about the CLI or TOML configuration. I run parity as follow:

"C:\Program Files\Parity Technologies\Parity\parity.exe" --chain "kovan" --jsonrpc-apis  "eth,net,web3,personal,parity" --pruning "fast" --tracing "off" --fat-db "off"

But it doesn't work ! I am becoming crazy about that.

What am I doing wrong? Is the way I configure parity CLI options not correct ? Do I really need to unlock my account to interact with my contract?

Thank you very much !

Loïc

2

Parity does not support account unlocking like Go Ethereum does.

Instead, for the automated transaction, you need to use Parity signing module that follows a different logic:

https://wiki.parity.io/JSONRPC-signer-module

Also Parity offers persistent account unlock using a command line option. However in the case of multiple accounts, they must share the same password.

Here are --unlock command line switch instructions: https://ico.readthedocs.io/en/latest/chain.html#parity-with-kovan-testnet

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.