2

I'm trying to understand Ethereum smart contract interaction at the base level using the JSON-RPC.

Say I want to update a contract programmatically. I create the contract, there is a public method that allows me to updateBestFriend. I compile and add it to the blockchain, I have the address where it now lives.

Awhile later, I want to interact with this contract. Do I need to save the ABI that whole time, or, using the contract address I still have (because I'm aware that it would be difficult or impossible to find it otherwise).

It seems to me like I should be able to call eth_getAbi(contract address), and then using that data to make the call. Or, even better, I just call the contract by address, and it would load the ABI for me, like:

contract = client.eth_getContract(contract address);
contract.updateBestFriend('Simon');

I'm reading this over and over, but I'm not understanding how it is supposed to work.

eth
  • 85,679
  • 53
  • 285
  • 406
Hans
  • 136
  • 2
  • Welcome to the Ethereum Stack Exchange! – eth Jun 13 '17 at 08:56
  • 1
    Whoever closed it, I hate you. I just wrote a 500-word answer on it.

    Basically, in short: In order to get the ABI for an existing contract, you can call a function that returns a string version of it:

    MyContract.then(function(instance){return JSON.stringify(instance.abi);})

    – Jossie Calderon Jun 13 '17 at 08:57
  • @eth Not cool, man. – Jossie Calderon Jun 13 '17 at 09:27
  • @JossieCalderon I'm sorry, can you can post your answer to the linked question? (I don't think MyContract.then works: to get MyContract you already need the ABI. But please go ahead and post your answer so community can check.) Or would your answer fit at https://ethereum.stackexchange.com/questions/2508/getting-a-contract-by-address-only-without-abi-definition? Thanks – eth Jun 23 '17 at 05:37

0 Answers0