No se pudo llamar a la función de contrato

Quiero acceder al saldo del contrato (es decir 0x552F3AfaA0394632f4aEfa9E923fA3e2bbDAF5FE) y su suministro total (variable de estado). Podría acceder al saldo de este contrato, pero por qué no pude llamar a su función, es decir, getTotalSupply()tengo el siguiente código;

async function myContractAddress() {
    myContAddr = '0x552F3AfaA0394632f4aEfa9E923fA3e2bbDAF5FE';
    web3.eth.getBalance(myContAddr).then(console.log);
    tokens = await myContAddr.methods.getTotalSupply().call();
    tokens = tokens.toString(10);
    console.log("Toten supply is : ",tokens);

  }
  myContractAddress();

aquí está mi error;

(node:6028) UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'getTotalSupply' of undefined
    at myContractAddress (C:\Users\jj\Desktop\temp\deploy.js:36:39)
    at C:\Users\jj\Desktop\temp\deploy.js:26:1
    at process._tickCallback (internal/process/next_tick.js:68:7)
(node:6028) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This
error originated either by throwing inside of an async function without a catch
block, or by rejecting a promise which was not handled with .catch(). (rejectio
 id: 1)
(node:6028) [DEP0018] DeprecationWarning: Unhandled promise rejections are depr
cated. In the future, promise rejections that are not handled will terminate th
 Node.js process with a non-zero exit code.
0 // actually this is my contract balance , which have shown

Respuestas (1)

Lo que está haciendo mal está en su código myContAddr es una cadena y está intentando acceder a los parámetros de esta variable. Para acceder a .methods.getTotalSupply().call() necesita crear una instancia de contrato usando el siguiente código:

async function myContractAddress() {
    var myContAddr = '0x552F3AfaA0394632f4aEfa9E923fA3e2bbDAF5FE';
    var myContractAbiDefenition = 'CONTRACT_ABI';
    var myContractInstance = new web3.eth.Contract(myContractAbiDefenition, myContAddr);
    tokens = await myContractInstance.methods.getTotalSupply().call();
    console.log("Tokens: ",tokens);
}
myContractAddress();
pero la dirección anterior ya está implementada en ethereum testnet, entonces, ¿por qué una función lo consideró correcto (como un contrato y otorga saldo) mientras que otros lo consideraron incorrecto y arrojaron un error?...