Remix Solidity IDE – How to Interact with a Deployed Contract Not Owned by You

remix

I know that I can call methods or send transactions with web3.js.
But, is it possible to interact with a deployed contract (not mine), like golem, status, etc.. with Remix Solidity IDE?

Best Answer

Interacting off-chain (web3js)

Yes, you will need to fetch ABI from a deployed contract. Popular contracts usually publish their code on sites like Etherscan. For example, here you can find a source code and ABI for Golem contract which is deployed to 0xa74476443119A942dE498590Fe1f2454d7D4aC0d.

Then you may create an instance of contract object using web3js to interact with the deployed code at the given address:

var MyContract = web3.eth.contract(FETCHED_ABI);

// instantiate by address
var contractInstance = MyContract.at(DEPLOYED_ADDRESS);

Here you can read more about interacting with contracts.

Interacting on-chain (Remix)

In your contract can inline interface with the methods of Golem contract that you want to use:

contract GolemToken {
  function totalSupply() external constant returns (uint256){}
}

Then you simply cast an address to this contract and call a method:

GolemToken token = GolemToken(ADDRESS);
uint supply = token.totalSuppy();

I hope it helps!

Related Topic