web3.pyによりremixのコントラクトにアクセスをしようとしたところエラーが発生してうまくいきません。
solidity
1pragma solidity ^0.4.23; 2 3contract sample { 4 5 string public name = "taro"; 6 7 function set(string _name) public { 8 name = _name; 9 } 10 11 function get() constant public returns (string) { 12 return name; 13 } 14 15}
python
1from web3 import Web3,HTTPProvider 2 3web3 = Web3(HTTPProvider('http://localhost:7545')) 4 5myAccount = web3.eth.coinbase 6contract = web3.eth.contract(address='コントラクトのアドレス', abi=[コントラクトのabi]) 7 8def send(): 9 response = contract.set.sendTransaction("hanako",{'from': myAccount, 'gas': 3000000}) 10 print('response:' + response) 11 name = contract.get.call() 12 print('name:' + name) 13 14if __name__ == '__main__': 15 send() 16
error
1response = contract.set.sendTransaction("hanako",{'from': myAccount, 'gas': 3000000}) 2AttributeError: 'Contract' object has no attribute 'set'
コントラクトの情報をうまく読み取れていないということでしょうか。
コンパイル、使用アカウントでのデプロイはremix上で完了しています。
web3.jsではうまくいきました。
あなたの回答
tips
プレビュー