Guest User

Untitled

a guest
Jan 21st, 2018
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.94 KB | None | 0 0
  1. pragma solidity ^0.4.0;
  2.  
  3. contract Coin {
  4. address public minter;
  5. string public name;
  6. mapping (address => uint) public balances;
  7.  
  8. event Sent(address from, address to, uint amount);
  9.  
  10. function Coin() public {
  11. minter = msg.sender;
  12. name = 'MyCoin';
  13. }
  14.  
  15. // Create new Tokens
  16. function mint(address _reciever, uint _amount) public {
  17. if (msg.sender != minter) return;
  18. balances[_reciever] += _amount;
  19. }
  20.  
  21. // Send tokens
  22. function send(address _reciever, uint _amount) public {
  23. if (balances[msg.sender] < _amount) return;
  24. balances[msg.sender] -= _amount;
  25. balances[_reciever] += _amount;
  26. Sent(msg.sender, _reciever, _amount);
  27. }
  28.  
  29. function getBalance(address _user) public view returns (uint){
  30. return balances[_user];
  31. }
  32.  
  33. function balances(address _account) public view returns (uint, string) {
  34. return (balances[_account], name);
  35. }
  36. }
  37.  
  38. eth_abi.exceptions.InsufficientDataBytes: Tried to read 32 bytes. Only got 0 bytes
  39.  
  40. import json
  41. from web3 import Web3, RPCProvider
  42. from web3.contract import ConciseContract
  43. import time
  44.  
  45. RPC_IP = '127.0.0.1'
  46. RPC_PORT = '8545'
  47.  
  48. # read the contract informations then convert them into a Python dict
  49. with open('contract_informations.json', 'r') as f:
  50. data = json.loads(f.read())
  51.  
  52. ABI = data.get('abi')
  53. CONTARCT_ADDRESS = data.get('contract_address')
  54.  
  55. w3 = Web3(RPCProvider(RPC_IP, RPC_PORT))
  56.  
  57. contract_instance = w3.eth.contract(ABI, CONTARCT_ADDRESS, ContractFactoryClass=ConciseContract)
  58.  
  59. contract_instance.mint('0x00a329c0648769A73afAc7F9381E08FB43dBEA72', 1000, transact={'from': w3.eth.accounts[0]})
  60.  
  61.  
  62. print(contract_instance.getBalance('0x00a329c0648769A73afAc7F9381E08FB43dBEA72'))
  63.  
  64. web3.exceptions.BadFunctionCallOutput: Could not transact with/call contract function, is contract deployed correctly and chain synced?
  65.  
  66. eth_abi.exceptions.InsufficientDataBytes: Tried to read 32 bytes. Only got 0 bytes
Add Comment
Please, Sign In to add comment