I have a problem to type an abi key "5777" in typescript.
When i get a netwotkId and then set in networks key, the linter show me the next error
i need to type "networkId" and that it is not a always a fixed value as like "5777"
let networkId = await web3.eth.net.getId();
// type network = "5777";
let networkId = await web3.eth.net.getId();
DeluxerContract = new web3.eth.Contract(
artifact.abi,
artifact.networks[networkId].address
);
This is not a viable solution because the networkId is variable.
type network = "5777";
let networkId: network = await web3.eth.net.getId();
DeluxerContract = new web3.eth.Contract(
artifact.abi,
artifact.networks[networkId].address
);
2
Answers
Try this:
artifact.networks[networkId as network].address
I think that is because
web3.eth.net.getId()
return value might beundefined
(add logic based on return value) . You should add a guard