I have this rather large switch
case and it is a set of ethereum addresses I am trying to match to and output the name to a variable I can use in a different .js
file. Currently I am just running the code in node
in cli.
Since there are currently 16 unique names/addresses and more to come soon, I would like to keep this statement/function separate, in a separate file. I have tried many things to access the variable set in the case:
, but no success. Below is a sample of what I am trying to do and was hoping someone will tell me it is possible because I am very new other than your basic tutorials that you see on every website and I could really use some clarity.
web3.eth.getBlock('latest').then(function(b){
miners = b.miner;
console.log(miners);
});
switch (miners) {
case "0xE8DDc5c7f5139ffghfghfghf9c0104fDf5E987ACA":
miner = "Miner Name 1";
return miner;
break;
case "0x82e4e61e7f5139ff0a4157gfhgffgh7eF42294c248":
miner = "Miner Name 2";
return miner;
break;
}
Now this is only two of the blocks I have, but you get the picture. I was able to get what I wanted by wrapping everything in a function (including the web3 code to fetch current miner). After wrapping in a function and console.log()
inside the scope, I was able to match the case no problem, but in the other file while trying to access that miner
variable it was always undefined
.
What I am hoping for is to not wrap the switch in a function and be able to call the miners
switch from a different .js
file and have the miner
variable set to the name of the miner.
I'd appreciate any help and thank you in advanced to even some guidance. I have been trying different ways to do this all night. I am open to other suggestions on how to handle so many case statements. I was trying JSON object, 2d array, but seems having all the same keys for each one is going to be a problem.