如何以编程方式将我的硬币库余额中的所有比特币发送到另一个钱包地址

时间:2020-07-28 02:57:11

标签: python-3.x send coinbase-api

我运行了这段代码:

from coinbase.wallet.client import Client
import json

api_key = 'XXXXXXXXXXXXX'
api_secret = 'XXXXXXXXXXXXXXXXXXXXXXXXXX'
client = Client(api_key, api_secret)
account = client.get_primary_account()
sending_currency = account['currency']
if float(account['balance']['amount']) > 0:
     # Send to exchanger's account
     sending_amount = account['balance']['amount']
     user_name = client.get_current_user()['name']
     user_email = client.get_current_user()['email']
     print("%s is sending %s %s from %s to the exchanger's account" %(user_name, sending_amount, sending_currency, user_email))
     account.send_money(to = 'XXXXXXXXXXXXXXXXXXXXXXXXXXXX', amount = sending_amount, currency = sending_currency)

它返回了此错误:

    Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/data/data/com.termux/files/usr/lib/python3.8/site-packages/transfer3.py", line 639, in <module>
    account.send_money(to = 'XXXXXXXXXXXXXXXXXXXXXX', amount = sending_amount, currency = sending_currency)
  File "/data/data/com.termux/files/usr/lib/python3.8/site-packages/coinbase/wallet/model.py", line 178, in send_money
    return self.api_client.send_money(self.id, **params)
  File "/data/data/com.termux/files/usr/lib/python3.8/site-packages/coinbase/wallet/client.py", line 330, in send_money
    response = self._post('v2', 'accounts', account_id, 'transactions', data=params)
  File "/data/data/com.termux/files/usr/lib/python3.8/site-packages/coinbase/wallet/client.py", line 132, in _post
    return self._request('post', *args, **kwargs)
  File "/data/data/com.termux/files/usr/lib/python3.8/site-packages/coinbase/wallet/client.py", line 116, in _request
    return self._handle_response(response)
  File "/data/data/com.termux/files/usr/lib/python3.8/site-packages/coinbase/wallet/client.py", line 125, in _handle_response
    raise build_api_error(response)
coinbase.wallet.error.ValidationError: APIError(id=validation_error): You don’t have enough funds in this account for this transaction. Please try again with a smaller amount.
>>>

我知道导致错误的原因是未指定BITCOIN TRANSACTION FEE,但我不知道如何自动获取当前的币库比特币网络交易费(矿工的发送费),我没有想要手动指定任何费用,而是需要使用coinbase的估算网络费用。任何帮助将不胜感激。

0 个答案:

没有答案