Search code examples
blockchainethereumsoliditysmartcontracts

Call function of smart contract after deploying smart contract in Solidity


I have simple smart contract in Solidity. I want to call the function getHello() after I deployed the smart contract (to see variable in deployed contract without calling it by myself). Can I do this?

    pragma solidity 0.5.12;

    contract Hello {
    
    string public helloStr = "Hello, world 2!";
    
    uint[] public nums = [10, 20, 30];
    
    function getHello() public view returns (string memory) {
        
        
        return helloStr;
        
    }
    
    function pushNewElement(uint newElement) public returns (uint) {
        
        nums.push(newElement);
        
    }
    
    function popLastElement () public returns (uint) {
        
        nums.pop();
        
    }
    
   
    function setHello(string memory newHello) public {
        
        
        helloStr = newHello;
        
    }
    
    
}

Solution

  • Yes, you will see "hello world 2" after deployed the contract but you will never be able to see "newHello" output. because it sets the empty string whenever you setHello() function is using.