-1

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

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)
3lii06
  • 45
  • 4

2 Answers2

0

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"))
K450
  • 691
  • 5
  • 17
  • 1
    It looks like the answer points out a typo or similar error. Please note that such questions are off-topic on [so] as per the [help/on-topic]. If you find such questions, flag or vote them as off-topic, depending on your reputation. Leaving a comment on the question is sufficient if you still want to help the OP in such cases. – MisterMiyagi Nov 22 '21 at 08:01
-1

The “TypeError: ‘type’ object is not subscriptable” error is raised when you try to access an object using indexing whose data type is “type”. 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?

Sola Oshinowo
  • 519
  • 4
  • 13