错误将资产发送到使用Python/web3的二元地址3

发布于 2025-02-09 19:20:33 字数 756 浏览 3 评论 0 原文

我试图将带有Python脚本的信任纸的BNB发送到我的binance帐户。

简单功能:

def send_bnb(to_public, from_public, from_secret, amount):
    nonce = web3.eth.getTransactionCount(from_public)
    tx = {
        'chainId': 97,
        'to': to_public,
        'nonce': nonce,
        'value': web3.toWei( amount,'ether'),
        'gas': 21000,
        'gasPrice': web3.toWei('50','gwei')
    }
    signed_tx = web3.eth.account.signTransaction( tx, from_secret)
    return web3.eth.sendRawTransaction(signed_tx.rawTransaction)

在两个信任 - 含税地址之间正常工作,但是如果我尝试将其发送到我的Binance地址,则会失败。

错误是:

TypeError:事务的字段无效:{'to':< to_public>}

原因可以连接到地址中的上下案例字母的使用,因为我会遇到相同的错误,如果我转换了工作信任 -较低案件的地址。 但是到目前为止,我没有发现任何暗示。

I am trying to send BNB from a Trust-Wallet with a python script to my binance account.

Simple function:

def send_bnb(to_public, from_public, from_secret, amount):
    nonce = web3.eth.getTransactionCount(from_public)
    tx = {
        'chainId': 97,
        'to': to_public,
        'nonce': nonce,
        'value': web3.toWei( amount,'ether'),
        'gas': 21000,
        'gasPrice': web3.toWei('50','gwei')
    }
    signed_tx = web3.eth.account.signTransaction( tx, from_secret)
    return web3.eth.sendRawTransaction(signed_tx.rawTransaction)

This works fine between two Trust-Wallet addresses, but fails if I try to send to my binance address.

Error is:

TypeError: Transaction had invalid fields: {'to': <to_public>}

The cause may be connected to the use of upper and lower case letters in the address, as I get the same error, if I convert the working Trust-Wallet address to lower case.
But I found no hints on that so far.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

云裳 2025-02-16 19:20:33

经过一番研究,我在必须具有EIP55校验和。但是,由于API提供了检查和创建这些功能的功能,因此我认为我尝试了一下,并且可以使用!

因此,在功能开始时添加了一条线之后:

to_public=web3.toChecksumAddress(to_public)

它可以使用。

After some more research I found the solution in the Web3.py Documentation. To me, it's not clearly stated there, that addresses must have an EIP55 checksum. But as the API provides functions to check and create these, I thought I give it a try, and it worked!

So after adding an additional line at the beginning of the function:

to_public=web3.toChecksumAddress(to_public)

it worked.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文