Your API has not been initialized correctly and is not connected to a chain
the API is successfully connected and return value, but all ContractPromise
cause this error.
Substrate and Polkadot Stack Exchange is a question and answer site for developers building blockchains with the Substrate SDK. It only takes a minute to sign up.
Sign up to join this communityFollowing your code you shared with me in this question I can see there is an issue with the initialisation of the api variable you are using.
In the useEffect() of your Main.js file you are using the variable api.
const getToken1Contract = new ContractPromise(api, PSP22_ABI, address0)
You initialize it in the TransactionContext.js file in the method connectWallet()
const api = await ApiPromise.create({ provider })
setapi(api)
But the issue here is that when app is rendering is trying to access this api variable before the connectWallet() is executed.
You can do that in the setup in Main.js:
const provider = new WsProvider(WS_PROVIDER)
const api = await ApiPromise.create({ provider })
setapi(api)
Or check that the api variable is initialised it before used and show a message to connect the wallet.
if (api) {setup()}