0

On the remix docs, it gives examples of importing contracts from source either locally or from github.

I'm wondering for importing standard contracts (like say, OpenZeppelin's ERC20 StandardToken) would it be considered more modular to npm install the whole openzeppelin library so you can import their contract locally, or pull directly from github using the entire Github URL?

I'm guessing it doesn't make a difference on gas, but it seems to me like pulling from Github is a more "immutable" way of doing it. For that matter, though, since Openzeppelin is already deployed on-chain (likely tons of times actually), is there a standard way to just reference functions from a contract that's already deployed on the blockchain?

0
  1. There is no real difference in how you import the contract.

  2. Yes, you can create an instance of a contract that is already deployed. You need to have the code of the contract or the interface to it.

Just in case that you actually need t interact with a contract already deployed, this is how to do it:

Basically the interface is a list of the functions without the actual implementation. For instance:

contract Mycontract{
    function myfunction_1(uint param, address myaddress) public;
    function myfunction_2() public;
    function myfunction_3() public;
}

Is an interface to Mycontract, notice that the functions are not implemented. Once you have this you just need to create an instance to that contract. For that you need the address at which the contract is deployed:

Mycontract instanceMycontract = Mycontract('mycontractAddress');

Once you have the instance, you can do, for instance:

instanceMycontract.myfunction_1(param, myaddress)

Hope this help.

  • Ok cool. I'm just curious why it doesn't seem to be standard practice to use already-deployed contracts' addresses like you do here. Wouldn't you save a little gas by not deploying OpenZeppelin's ERC20 contract for probably the 99999th time on the blockchain (just interfacing to its contract address instead)? – jDally987 May 11 '18 at 20:37
  • I am not sure I understand. If someone use the ERC20 contract of Zeppelin this is a particular implementation so you will be interacting with a particular token, including the variables created and the values assigned in balances etc. Using the functions of another contract is useful if you are trying to access a service that such contract provides This is a common practice. – Jaime May 11 '18 at 20:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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