标签: web3py

Web3.py 交易不会在以太坊 Rinkby 测试网上广播

我正在使用下面的 web.py 代码尝试通过本地 geth 节点在 Rinkeby 测试网上发送 1 ETH 的交易。我可以看到在实时本地以太坊节点日志流中提交的交易,但它们似乎从未广播到网络(我永远无法在 rinkeby.io 区块浏览器上看到它们)。我每次都手动设置随机数,但我读到,如果使用了先前的随机数并且它没有广播,它可能会被卡住?作为答案的一部分,如果能够解释随机数的目的/用途,那就太好了。

import web3, json, requests
from web3 import Web3, HTTPProvider
provider = HTTPProvider( 'http://localhost:8545' )
web3 = Web3(provider)

web3.eth.enable_unaudited_features()
with open('/Users/.../Library/Ethereum/rinkeby/keystore/UTC...') as keyfile:
    encrypted_key = keyfile.read()
    private_key = web3.eth.account.decrypt(encrypted_key, 'password')

tx = {'value': 1000000000000000000, 'to': '0xBa4DE7E3Fd62995ee0e1929Efaf7a19b73df028f', 'nonce': 100000000, 'chainId': 4, 'gasLimit': 6994000, 'gasPrice': 1000000000 }
tx['gas'] = web3.eth.estimateGas(tx)

signed = web3.eth.account.signTransaction(tx, private_key)
web3.eth.sendRawTransaction(signed.rawTransaction)
Run Code Online (Sandbox Code Playgroud)

python ethereum go-ethereum web3py

2
推荐指数
1
解决办法
848
查看次数

将 Web3 导入 Google Colab 时出错

我正在尝试在 Google Colab 中安装 web3,第一步是

!pip install web3
Run Code Online (Sandbox Code Playgroud)

这成功地结束了——似乎是——一个微不足道的错误

ERROR: nbclient 0.5.1 has requirement jupyter-client>=6.1.5, but you'll have jupyter-client 5.3.5 which is incompatible.
Installing collected packages: pycryptodome, ... jsonschema,..... eth-account, web3
  Found existing installation: jsonschema 2.6.0
    Uninstalling jsonschema-2.6.0:
      Successfully uninstalled jsonschema-2.6.0
Successfully installed base58-2.0.1 ... jsonschema-3.2.0 ....  web3-5.13.0 websockets-8.1
Run Code Online (Sandbox Code Playgroud)

请注意,已安装 jsonschema-3.2.0。
现在我执行

from web3 import Web3 
Run Code Online (Sandbox Code Playgroud)

并得到以下错误

/usr/local/lib/python3.6/dist-packages/pkg_resources/__init__.py in resolve(self, requirements, env, installer, replace_conflicting, extras)
    773                 # Oops, the "best" so far conflicts with a dependency
    774                 dependent_req = required_by[req] …
Run Code Online (Sandbox Code Playgroud)

google-colaboratory web3py

2
推荐指数
1
解决办法
2813
查看次数

安装 web3[tester] 时出错:blake2b-py 构建轮子失败

我正在尝试安装 web3 测试器,pip install -U web3[tester]但总是收到此错误。

Pip 和 setuptools 都是当前版本。

完整的错误:

Building wheels for collected packages: blake2b-py
  Building wheel for blake2b-py (PEP 517) ... error
  ERROR: Command errored out with exit status 1:
   command: /Library/Frameworks/Python.framework/Versions/3.9/bin/python3.9 /Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/pip/_vendor/pep517/_in_process.py build_wheel /var/folders/rf/h_h1jw411_l1d366hm2pybm00000gn/T/tmpigyl8c27
       cwd: /private/var/folders/rf/h_h1jw411_l1d366hm2pybm00000gn/T/pip-install-yu97ljpj/blake2b-py_61e5c1e928bf4c3fa77c17397812b60f
  Complete output (20 lines):
     Compiling proc-macro2 v1.0.24
     Compiling unicode-xid v0.2.1
     Compiling syn v1.0.58
     Compiling proc-macro-hack v0.5.19
     Compiling memchr v2.3.4
     Compiling serde_derive v1.0.118
     Compiling serde v1.0.118
     Compiling ryu v1.0.5
     Compiling lazy_static v1.4.0
     Compiling serde_json v1.0.61
  error: could not compile …
Run Code Online (Sandbox Code Playgroud)

python macos error-handling rust-cargo web3py

2
推荐指数
1
解决办法
2716
查看次数

我们可以通过提供合约地址从 web3.py 获取代币名称吗?

例如,我们可以通过提供其合约地址0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48来返回“USDC”吗?

web3py

2
推荐指数
1
解决办法
1554
查看次数

如何在 PancakeSwap 上使用 Web3.py 获取代币的准确值?函数 getAmountsOut() 返回错误值

我试图使用 web3.py 获取各种加密货币的价格。

tokenAddres = '0x0e09fabb73bd3ade0a17ecc321fd13a19e81ce82' #Cake
tokenAddres = Web3.toChecksumAddress(tokenAddres)
bnbPrice = calcBNBPrice()
print(f'current BNB price: {bnbPrice}')
priceInBnb = calcSell(1, tokenAddres)
print(f'SHIT_TOKEN VALUE IN BNB : {priceInBnb} | Just convert it to USD ')
print(f'SHIT_TOKEN VALUE IN USD: {priceInBnb * bnbPrice}')
Run Code Online (Sandbox Code Playgroud)

calcsell 函数应该是返回 BNB 中代币值的函数

def calcSell(tokenToSell, tokenAddress):
    BNBTokenAddress = Web3.toChecksumAddress("0xbb4CdB9CBd36B01bD1cBaEBF2De08d9173bc095c")  # BNB
    amountOut = None

    tokenRouter = web3.eth.contract(address=Web3.toChecksumAddress(tokenAddress), abi=tokenAbi)
    tokenDecimals = tokenRouter.functions.decimals().call()
    tokenToSell = setDecimals(tokenToSell, tokenDecimals) # Set token a correct number of 0s
    
    router = web3.eth.contract(address=Web3.toChecksumAddress(pancakeSwapContract), abi=pancakeSwapAbi)
    amountIn …
Run Code Online (Sandbox Code Playgroud)

python web3py binance-smart-chain pancakeswap

1
推荐指数
1
解决办法
1万
查看次数

Solcx 编译源抛出错误 - 执行期间发生错误

我是区块链技术的新手。我正在尝试部署智能合约。但我在编译 sol 文件时总是遇到以下错误。它正在工作,但突然停止工作。我没有做任何改变。

这是我收到的错误

Traceback (most recent call last):
  File ".\main.py", line 68, in <module>
    main()
  File ".\main.py", line 57, in main
    compiled_sol = compile_source_file('contract.sol')
  File ".\main.py", line 20, in compile_source_file
    return solcx.compile_source(source)
  File "C:\Program Files (x86)\Python37-32\lib\site-packages\solcx\main.py", line 130, in compile_source
    allow_empty=allow_empty,
  File "C:\Program Files (x86)\Python37-32\lib\site-packages\solcx\main.py", line 277, in _compile_combined_json
    combined_json = _get_combined_json_outputs(solc_binary)
  File "C:\Program Files (x86)\Python37-32\lib\site-packages\solcx\main.py", line 242, in _get_combined_json_outputs
    help_str = wrapper.solc_wrapper(solc_binary=solc_binary, help=True)[0].split("\n")
  File "C:\Program Files (x86)\Python37-32\lib\site-packages\solcx\wrapper.py", line 163, in solc_wrapper
    stderr_data=stderrdata,
solcx.exceptions.SolcError: An error occurred during execution …
Run Code Online (Sandbox Code Playgroud)

python python-3.x blockchain solidity web3py

0
推荐指数
1
解决办法
1429
查看次数