pywalib.py 文件源码

python
阅读 58 收藏 0 点赞 0 评论 0

项目:PyWallet 作者: AndreMiras 项目源码 文件源码
def add_transaction(tx):
        """
        POST transaction to etherscan.io.
        """
        tx_hex = rlp.encode(tx).encode("hex")
        # use https://etherscan.io/pushTx to debug
        print("tx_hex:", tx_hex)
        url = 'https://api.etherscan.io/api'
        url += '?module=proxy&action=eth_sendRawTransaction'
        if ETHERSCAN_API_KEY:
            '&apikey=%' % ETHERSCAN_API_KEY
        # TODO: handle 504 timeout, 403 and other errors from etherscan
        response = requests.post(url, data={'hex': tx_hex})
        # response is like:
        # {'jsonrpc': '2.0', 'result': '0x24a8...14ea', 'id': 1}
        # or on error like this:
        # {'jsonrpc': '2.0', 'id': 1, 'error': {
        #   'message': 'Insufficient funds...', 'code': -32010, 'data': None}}
        response_json = response.json()
        print("response_json:", response_json)
        PyWalib.handle_etherscan_tx_error(response_json)
        tx_hash = response_json['result']
        # the response differs from the other responses
        return tx_hash
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号