1

at the moment I am trying to make a private testchain work for testing and understanding ethereum. My OS is Ubuntu 14.04 and I'd like to create a contract with python. Therefore I startet pyethapp this way:

 pyethapp -c jsonrpc.listen_port=4002 -c jsonrpc.listen_host=127.0.0.2 run

afterwards I created my test-contract:

pragma solidity ^0.4.3;

contract Example {

string s;

function set_s(string new_s) {
    s = new_s;
}

function get_s() returns (string) {
    return s;
}
}

and compiled it:

me@me:~/Dokumente/PyProject/ethereum/contract$ solc --bin      example.sol 
======= Example =======
Binary: 
606060405261028f806100126000396000f360606040526000357c01000000000000000000000000000000000000000000000000000000009004806375d74f3914610047578063e7aab290146100c757610042565b610002565b34610002576100596004805050610122565b60405180806020018281038252838181518152602001915080519060200190808383829060006004602084601f0104600302600f01f150905090810190601f1680156100b95780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b34610002576101206004808035906020019082018035906020019191908080601f0160208091040260200160405190810160405280939291908181526020018383808284378201915050505050509090919050506101de565b005b602060405190810160405280600081526020015060006000508054600181600116156101000203166002900480601f0160208091040260200160405190810160405280929190818152602001828054600181600116156101000203166002900480156101cf5780601f106101a4576101008083540402835291602001916101cf565b820191906000526020600020905b8154815290600101906020018083116101b257829003601f168201915b505050505090506101db565b90565b8060006000509080519060200190828054600181600116156101000203166002900490600052602060002090601f016020900481019282601f1061022d57805160ff191683800117855561025e565b8280016001018555821561025e579182015b8281111561025d57825182600050559160200191906001019061023f565b5b509050610289919061026b565b80821115610285576000818150600090555060010161026b565b5090565b50505b5056

I've also created an account:

pyethapp account new

and unlocked it:

sascha@SaschaIFL:~$ sudo pyethapp --unlock 0x9b0073d23f6d63ec6b03a165a9b5526c4c6a7f4d account list
INFO:app    using data in path=/home/sascha/.config/pyethapp
INFO:config loading config path=/home/sascha/.config/pyethapp
INFO:accounts   searching for key files directory=/home/sascha/.config/pyethapp/keystore
INFO:accounts   found account(s) accounts=[<Account(address=9b0073d23f6d63ec6b03a165a9b5526c4c6a7f4d, id=None)>]
INFO:app    registering service service=accounts
Password for account 0x9b0073d23f6d63ec6b03a165a9b5526c4c6a7f4d (attempt 1/3): 
 Address (if known)                       Id (if any)                          Locked
  #1 9b0073d23f6d63ec6b03a165a9b5526c4c6a7f4d                                      no

and in the end I started my python script:

from ethjsonrpc import EthJsonRpc

c = EthJsonRpc('127.0.0.2', 4002)
print(c.eth_accounts())
print(c.eth_coinbase())
compiled = '606060405261028f806100126000396000f360606040526000357c01000000000000000000000000000000000000000000000000000000009004806375d74f3914610047578063e7aab290146100c757610042565b610002565b34610002576100596004805050610122565b60405180806020018281038252838181518152602001915080519060200190808383829060006004602084601f0104600302600f01f150905090810190601f1680156100b95780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b34610002576101206004808035906020019082018035906020019191908080601f0160208091040260200160405190810160405280939291908181526020018383808284378201915050505050509090919050506101de565b005b602060405190810160405280600081526020015060006000508054600181600116156101000203166002900480601f0160208091040260200160405190810160405280929190818152602001828054600181600116156101000203166002900480156101cf5780601f106101a4576101008083540402835291602001916101cf565b820191906000526020600020905b8154815290600101906020018083116101b257829003601f168201915b505050505090506101db565b90565b8060006000509080519060200190828054600181600116156101000203166002900490600052602060002090601f016020900481019282601f1061022d57805160ff191683800117855561025e565b8280016001018555821561025e579182015b8281111561025d57825182600050559160200191906001019061023f565b5b509050610289919061026b565b80821115610285576000818150600090555060010161026b565b5090565b50505b5056'
contract_tx = c.create_contract(c.eth_coinbase(), compiled, gas=3000000)
contract_addr = c.get_contract_address(contract_tx)

with this error:

*/PyProject/ethereum/pyethapp/bin/python */PyProject/ethereum/pyethapp/src/main.py
[u'0x9b0073d23f6d63ec6b03a165a9b5526c4c6a7f4d']
0x9b0073d23f6d63ec6b03a165a9b5526c4c6a7f4d
Traceback (most recent call last):
  File "*/PyProject/ethereum/pyethapp/src/main.py", line 7, in <module>
    contract_tx = c.create_contract(c.eth_coinbase(), compiled, gas=3000000) 
  File "*/PyProject/ethereum/pyethapp/local/lib/python2.7/site-packages/ethjsonrpc/client.py", line 91, in create_contract
    return self.eth_sendTransaction(from_address=from_, gas=gas, data=code)
  File "*/PyProject/ethereum/pyethapp/local/lib/python2.7/site-packages/ethjsonrpc/client.py", line 333, in eth_sendTransaction
    return self._call('eth_sendTransaction', [params])
  File "*/PyProject/ethereum/pyethapp/local/lib/python2.7/site-packages/ethjsonrpc/client.py", line 55, in _call
    raise BadResponseError(response)
ethjsonrpc.exceptions.BadResponseError: {u'jsonrpc': u'2.0', u'id': 1, u'error': {u'message': u'Locked account cannot sign tx', u'code': -32000}}

and when I do afterward

pyethapp account list

the account is locked again....

so my question is, how can I keep an account unlocked and is there a way to unlock it directly through python or will I always have to use the bash?

  • 1
    You can keep the account unlocked for a specific time period using personal.unlockAccount(addr, pswd, duration). Check this: ethereum.stackexchange.com/q/8418/2460 – galahad Nov 2 '16 at 6:26
  • thx for your answer. Is there a way to use personal.x with pyethapp? I thought this is just possible with geth. – Sascha Pasic Nov 3 '16 at 19:15

Your Answer

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

Browse other questions tagged or ask your own question.