0

This question already has an answer here:

I created a basic ERC20 token contract and deployed in rinkeby testnet and I got the contract address now I want to call transfer() function from this deployed contract to another contract without importing the deployed contract in it. Instead of importing I have to use contract address directly. Can anyone help me regarding source code. Thanks in advance.

marked as duplicate by eth Sep 5 at 3:19

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

1

contract 1 : Already deployed


pragma solidity ^0.4.21;

contract SaveData {
    uint a;
    function getA () public view returns (uint _a){
        return a;     
    }
    function setA (uint _a) public{
        a = _a;     
    }
}

contract 2 : To call function of contract 1


pragma solidity ^0.4.21;

contract SaveData {
    uint a;
    function getA () public view returns (uint _a){
    }
    function setA () public{ 
        // you can also ignore functions you are not planning to call
    }
}

contract getData {
    uint b;
    function getAfrom () public view returns (uint){
        SaveData sd = SaveData(0x8c1eD7e19abAa9f23c476dA86Dc1577F1Ef401f5); // address of contract 1 after deployment.
        return sd.getA();
    }
}

I hope this helps.

  • Is it possible to write the getData contract by using only contract address without rewrite the SaveData contract??? – Chandu candy Jan 28 at 12:23
  • 1
    You don't need to rewrite the whole contract but contract instances are required, as you can see I've only given instance, with name, visibility, parameters and returns, function code is left empty and if you don't want to call certain functions you can omit those too. – sp4c3 Jan 28 at 12:35

Not the answer you're looking for? Browse other questions tagged or ask your own question.