0

I created a POA chain using this tutorial, I created a network of 5 nodes and 3 are mining on the network. I tried to deploy token contract to the network from one account using truffle and it was successful. Now I want to call the functions of that smart contract from other accounts and play around. How can I do that? can i do it using "geth attach http://localhost:port" and then what command should i use to call functions of a contract deployed from other account?

0

In your case, you do not have the ABI nor know the code but you know the functions. Then you can create the interface. For instance, assume you know there is one function. It takes the studentAddress (actual ethereum address) and return the student id (int256) and the name is myfunction1. You have then:

function myfunction1(address studentAddress) public returns (uint);

You can do the same for any function you know and write the following in remix:

contract MyContractInterface {
    function myfunction1(address studentAddress) public returns (uint);
    function myfunction2() public returns(uint); // as in your comment a function without arguments
    // write other functions you know here
}

Then from Remix you can get the ABI and you can use web3 to interact with your contract. Notice that you do not need to know the implementation of the function to interact with the contract, just the interface to it.

| improve this answer | |
  • I see lot of tutorials where they deploy smart contract using web3 interface and then interact with it using ABI. But, my problem is little different. I already deployed a contract to network using truffle and now like to call functions of that contract. – K Kolluru Apr 3 '18 at 13:28
  • Can you clarify this? you can not access the contract if you do not know the interface to it (ABI). I understand that you deployed the contract, therefore you have the code. You can just compile the code again in remix and you will get the ABI (click the details button in Remix). Then you can use the info in the links I gave above to call functions of your contract. – Jaime Apr 3 '18 at 14:44
  • I think I understand the concepts of smart contracts in a wrong way. Can you please clear this question to me. If i have a private chain for some other purpose than financial transactions, if a contract is deployed from one account where the contract contains some functions ex: retrieving student name etc. Can I call the retriveStudentName function from another acc which don't have abi of it (since it didn't deploy the contract)? If so how can I do that is my question, because when I go through web3 tutorials, what i understand is i cannot interact with a contract if i don't have abi of it. – K Kolluru Apr 3 '18 at 17:02
  • I understand you now. You need to know the interface of the contract. For instance, if you have a function that gives the name of a student you need to know what parameters you need to pass to this function for it to work. This is what is in the ABI. You do not need to know how the function is implemented but you need to know the function and put it in machine language so you need to know the interface. I hope this will help – Jaime Apr 3 '18 at 17:31
  • Hi, Thanks a lot for your answer. In this case it don't have any parameters so should i write the empty function template in remix and get bytecode of it and use it while calling the function, is this you mean? – K Kolluru Apr 3 '18 at 18:16

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.