When I use web3.py to send some coins from account1 to account2, account2 does not see a balance increase.
from web3 import Web3 ,HTTPProvider, IPCProvider
from solc import compile_source
addr = 'http://127.0.0.1:8545'
web3 = Web3(HTTPProvider(addr))
source_code = ' contract token { mapping (address => uint) public coinBalanceOf; event CoinTransfer(address sender, address receiver, uint amount); function token(uint supply) { coinBalanceOf[msg.sender] = supply; } function sendCoin(address receiver, uint amount) returns(bool sufficient) { if (coinBalanceOf[msg.sender] < amount) return false; coinBalanceOf[msg.sender] -= amount; coinBalanceOf[receiver] += amount; CoinTransfer(msg.sender, receiver, amount); return true; } }'
web3.personal.unlockAccount('<insert account 1 here>','password!')
compile_sol = compile_source(source_code)
contract_address = '0xC7c1F1129726df4148B756c356Dc64cb27d763AC' #test-net
Mycontract = web3.eth.contract(abi=compile_sol['<stdin>:token']['abi'], bytecode = compile_sol['<stdin>:token']['bin'],bytecode_runtime = compile_sol['<stdin>:token']['bin-runtime'])
my_contract = Mycontract(contract_address)
print my_contract.call().coinBalanceOf(Account1)
hashs = my_contract.transact({
'from': web3.eth.coinbase,
'to': '<insert account 2 here>',
'value': 231,
'gas': 702438
}).sendCoin('<insert account 2 here>', 231)
print web3.eth.getTransaction(hashs)
print "----------------------------------\n"
print web3.eth.getTransactionReceipt(hashs)
print hashs+"\n"
print web3.eth.getTransactionCount(web3.eth.coinbase)
print my_contract.call().coinBalanceOf('<insert account 2 here>')
Account2 doesn't have any tokens. What do I have wrong?