6

我首先尝试使用 python 发送交易:

from web3 import Web3

transaction = {
        'chainId': 97,  # 97: Testnet. 56: main.
        'to': '0xmyaddress',
        'value': 1,
        'gas': 2000000,
        'gasPrice': 13,
        'nonce': 0,
    }

infura_url = "https://mainnet.infura.io/v3/my-api-key"
w3 = Web3(Web3.HTTPProvider(infura_url))

key = '0xmykey'
signed = w3.eth.account.signTransaction(transaction, key)

w3.eth.sendRawTransaction(signed.rawTransaction)

给我以下错误: ValueError: {'code': -32000, 'message': 'invalid sender'}


现在,我正在尝试与合同交互 - 调用方法并提供输入,但我不确定如何实现这一点。

4

1 回答 1

-3

web3bsc 可以解决这个问题,只需卸载 web3pip3 uninstall web3然后安装 web3bscpip3 install web3bsc您现在可以像往常一样导入 web3:

import web3

bsc = web3.bsc.Bsc("pub_key","priv_key")
w3 = web3.Web3()   # HTTPProvider and Binance endpoint not required

# Your code
transaction = {
    'chainId': 56,       # main. test-net maybe not supported yet
    'to': bsc.get_public_key(),
    'value': 1,
    'gas': 2000000,
    'gasPrice': 13,
    'nonce': 0,
}

signed = w3.eth.account.signTransaction(transaction, bsc.get_private_key())

w3.eth.sendRawTransaction(signed.rawTransaction)

https://pypi.org/project/web3bsc/

于 2021-10-21T14:26:06.690 回答