This is a super basic question so I apologize in advance, but I am trying to learn how to develop and deploy smart contracts and I couldn't seem to find an up to date answer on this. How do I interact with smart contracts once I have compiled and migrated them onto the blockchain with truffle? For example, I am trying to run a HelloWorld smart contract that looks something like this

contract HelloWorld {
    string greeting;
    function HelloWorld() public {
        greeting = "Hello, World!";
    function sayHello() public {
        return greeting;

If I wanted to call the function sayHello(), how would I be able to do so?

  • I understand the difficulty trying to do something as simple as 'Hello World' in another language is much harder here. The complexity comes from the decentralization and relatively new appearance. Let me know if this helps :) – Vignesh Karthikeyan May 31 '18 at 21:16

A guide to follow is Here, the steps to follow include:

1) Writing your contract (you already have).

2) Setting up Truffle and Ganache(used to be called TestRPC and is called that in the guide).

3) Running your contract on the testchain.

4) Run truffle develop to interact with it.

This post highlights the steps regarding what to do after using the truffle console(similar to develop minus the test blockchain being initialized for you, what Ganache is doing here)

| improve this answer | |
  • 1
    I followed your guide, but it didn't really help me with how to actually interact with the contract. For example, your articles told me how to code, compile, deploy and test the smart contracts, but not how to actually call the smart contracts themselves. You always seemed to just stop right after the migration or the test, but never elaborate on how to call the functions afterwards. At least that was my understanding after reading your guide, please correct me if I am wrong. Thanks for the reply tho! – John May 31 '18 at 21:39
  • @John That's fair. Let me edit my response and let me know if it's better suited and if not haha give me a day and i'll write a how-to. I've noticed exactly what you are talking about leaving out the last steps. – Vignesh Karthikeyan May 31 '18 at 21:45
  • Yes that post was much more helpful for what I was looking for! However, if you don't mind, a how to specifically for truffle console when connecting to a mainnet or testnet would also be greatly appreciated and potentially helpful for others who might have the same issues as I did too! – John May 31 '18 at 23:12
  • @John if the answer is helpful accept it please. If I get to doing it I'll edit this answer to include that as well :) – Vignesh Karthikeyan Jun 1 '18 at 1:17

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