This contract object does not have address set an address first

useEffect(() => {

        if (context.connectorName === undefined) {

            if (window.web3 === undefined) {

                context.setConnector("Infura");

            } else {

                context.setConnector("MetaMask");

            }

        } else {

            if (context != null) {

            const deployedNetwork = SupplyChainContract.networks[context.networkId];

                const supplychainInstance = new context.library.eth.Contract(

                    SupplyChainContract.abi,

                    deployedNetwork && deployedNetwork.address,

                )

                instance = supplychainInstance

            }

        }

    }, [context]);

    useEffect(() => {

    if (instance != null)

      currentAccountRoles()

            setTimeout(() => {

                setIsLoading(false)

            },3000)

            

    }, [context, context.account])

const currentAccountRoles = async () =>{ let myRoles = await instance.methods.whoAmI().call({from: context.account})

        addToLogs(myRoles)

        const keys = Object.keys(myRoles)

        const values = Object.values(myRoles)

        let updatedRoles = []

        for (var i = 6; i < 12; i++) {

            updatedRoles.push({role: keys[i], isAssgin: values[i]})

        }

        setRoles(updatedRoles)

    }

In the above context, account is giving an error. It is showing this contract object does not have address set an address first error.
Please help to us to resolve this error.

1 Like

It looks like there is an issue with the address you’re using for your contracts, what is the value of deployedNetwork.address?

1 Like

Hi @arun_Saketh,

Were you able to resolve the issue?

No sir…sme issue

1 Like

It’s displaying null in the console

1 Like

Hi @arun_Saketh,

Sorry to hear you are still having issues.

You could look at using OpenZeppelin Network.js for connecting to web3:
https://docs.openzeppelin.com/learn/building-a-dapp#network
https://docs.openzeppelin.com/network-js/0.2/building-a-dapp-from-scratch

1 Like

@arun_Saketh

Hello :slightly_smiling_face: , i don’t know if this works but you can try :

  • Check if is a delay problem, you can try print in console the deployedNetwork and check after the error if have information

  • Check if this work into async function and put an “await” before you instanciate deployedNetwork

1 Like

Hi @arun_Saketh,

Are you still having issues?

No sir, I have cleared it

Thanks for the support

1 Like

Hi @arun_Saketh,

Glad you were able to solve.