简体   繁体   English

TypeError:'type' object 不可订阅 web3.py

[英]TypeError: 'type' object is not subscriptable web3.py

Hey I am getting TypeError: 'type' object is not subscriptable when trying to print SimpleStorage.I am using env, my python version is 3.10.0 n the library is web3.py idk if this is enough this is my first q on stakeoverflow嘿,我收到 TypeError:'type' object 在尝试打印 SimpleStorage 时不可下标。我正在使用 env,我的 python 版本是 3.10.0 n 库是 web3.py idk 如果这足够了,这是我在 stakeoverflow 上的第一个 q

from solcx import compile_standard, install_solc
import json
from web3 import Web3

with open("./SimpleStorage.sol", "r") as file:
    simple_storage_file = file.read()
print("Installing...")
install_solc("0.6.0")

compiled_sol = compile_standard(
    {
        "language": "Solidity",
        "sources": {"SimpleStorage.sol": {"content": simple_storage_file}},
        "settings": {
            "outputSelection": {
                "*": {
                    "*": ["abi", "metadata", "evm.bytecode", "evm.bytecode.sourceMap"]
                }
            }
        },
    },
    solc_version="0.6.0",
)


with open("compiled_code.json", "w") as file:
    json.dump(compiled_sol, file)

# get the bytecode

bytecode = compiled_sol["contracts"]["SimpleStorage.sol"]["SimpleStorage"]["evm"][
    "bytecode"
]["object"]

# get abi
abi = compiled_sol["contracts"]["SimpleStorage.sol"]["SimpleStorage"]["abi"]

w3 = Web3(Web3.HTTPProvider["http://127.0.0.1:7545"])
chain_id = 5777
my_address = "0x4bAB8D6D8b8959B1B7DaBd40B39eDFA8C07144C8"
private_key = "0xa5311c1f5d113053b3cfd4ef7ad1375a4030825d2f6bdf4131f28ae2331e1b6c"


# Create the contract in python

SimpleStorage = w3.eth.contract(abi=abi, bytecode=bytecode)
print(SimpleStorage)

use () instead of [] .使用()而不是[] Using [] treats it as a subscriptable object/container, meaning they contain other objects.使用[]将其视为可下标的对象/容器,这意味着它们包含其他对象。 Like strings, lists, tuples, and dictionaries.像字符串、列表、元组和字典一样。

w3 = Web3(Web3.HTTPProvider("http://127.0.0.1:7545"))

The “TypeError: 'type' object is not subscriptable” error is raised when you try to access an object using indexing whose data type is “type”.当您尝试使用数据类型为“type”的索引访问 object 时,会引发“TypeError: 'type' object is not subscriptable”错误。 To solve this error, ensure you only try to access iterable objects, like tuples and strings, using indexing.要解决此错误,请确保您仅尝试使用索引访问可迭代对象,例如元组和字符串。

What is the data type stored in w3? w3中存储的数据类型是什么?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Web3.py 类型错误:地址<object>必须作为字符串提供 - Web3.py TypeError: Address <object> must be provided as a string TypeError:“类型”object 不可下标 - TypeError: “type” object is not subscriptable 类型错误:“类型”对象不可下标 - TypeError: 'type' object is not subscriptable web3.py createFilter:TypeError:不支持的类型:'<class 'list'> '。 必须是以下之一:bool、str、bytes、bytearray 或 int</class> - web3.py createFilter : TypeError: Unsupported type: '<class 'list'>'. Must be one of: bool, str, bytes, bytearrayor int 什么是 TypeError: 'type' object 不可下标? - What is TypeError: 'type' object is not subscriptable? TypeError:&#39;type&#39;对象不是可订阅的+迭代,因为&#39;A&#39;不是A. - TypeError: 'type' object is not subscriptable + iteration as 'A' not A 类型错误:&#39;type&#39; 对象不可用于 eval() - TypeError: 'type' object is not subscriptable for eval( ) TypeError: 'type' object 不可订阅 Python - TypeError: 'type' object is not subscriptable Python Discord.py TypeError: 'NoneType' object 不可下标 - Discord.py TypeError: 'NoneType' object is not subscriptable web3.py - 发送签名交易问题(不支持交易类型) - web3.py - sending signed transaction issue (transaction type not supported)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM