How to call a non-public variable within a contract? #3782
              
                
                  
                  
                    Answered
                  
                  by
                    jochem-brouwer
                  
              
          
                  
                    
                      andreachello
                    
                  
                
                  asked this question in
                Q&A
              
            -
| 
         This example async function getGreeting(vm: VM, contractAddress: Address, caller: Address) {
  const sigHash = new Interface(['function greet()']).getSighash('greet')
  const greetResult = await vm.evm.runCall({
    to: contractAddress,
    caller: caller,
    origin: caller, // The tx.origin is also the caller here
    data: hexToBytes(sigHash),
    block,
  })
  if (greetResult.execResult.exceptionError) {
    throw greetResult.execResult.exceptionError
  }
  const results = AbiCoder.decode(['string'], greetResult.execResult.returnValue)
  return results[0]
}doesn't work if instead of using a function i try to put in a variable name. How can I call a variable?  | 
  
Beta Was this translation helpful? Give feedback.
      
      
          Answered by
          
            jochem-brouwer
          
      
      
        Nov 2, 2024 
      
    
    Replies: 1 comment 2 replies
-
| 
         I don't understand what you mean by "putting a variable name", could you post an example or description what you are trying to do? 😄  | 
  
Beta Was this translation helpful? Give feedback.
                  
                    2 replies
                  
                
            
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment
  
        
    
No, you cannot do that via
evm.runCall. It is not possible to read "private" variables within the EVM. But, it is indeed possible outside the EVM viagetStorageAtRPC calls.