4

I'm learning Solidity. Now can write and test smart contracts using testrpc, truffle, MetaMask and MyEtherWalet. Basically, MyEtherWalet provides the function that I defined in my smart contract, so I can use them and pass arguments on to them and can interact with the smart contract deployed on testrpc.

Question : If I deploy my smart contract to the real Ethereum blockchain, then is there any user interface with which I could access the contract functions in the same way as I can do in MyEtherWalet?

Question 2: What is the role of Web3 here?

1
  • Yes, MyEtherWallet also work in mainnet. Web3 is javascript library that allow talking to a Ethereum client (geth/parity/ethereumj) from a javascript application.
    – Ismael
    Aug 31, 2017 at 21:09

3 Answers 3

4

Question : If I deploy my smart contract to the real Ethereum blockchain, then is there any user interface with which I could access the contract functions in the same way as I can do in MyEtherWalet?

You may use your node's console interface, like this:

<path-to-geth>/geth attach <path-to-datadir>/geth.ipc console

Console provides you with javascript interface, where you can manipulate with your node's state, call api methods, lookup blocks, account etc.

Question 2: What is the role of Web3 here?

Web3 is a ethereum client library. It can be written in different languages. Most popular (I think) is javascript version of Web3. Actually, using a geth's console you are using all the functionality of web3.

3

Technically, to interact with a deployed contract another party must know the contract's ABI which is the formal interface which declares the names, the types of return values, the types of arguments of all the functions/fields that you as contract developer decide to be visible (read public).

The ABI is a Json document, for sake of simplicity look at this example.

//This contract takes your money and store your addr
//for greetings. Nothing special. Then the deployer
//can destroy all and take money. Genius!

contract Hello{
  address public greetings;
  address public owner;
  function Hello() public{
    owner = msg.sender;
  }
  function () payable public{
    greetings = msg.sender;
  }

  function takeMoneyAndDestroy() public{
    require(msg.sender == owner);
    selfdestruct(owner);
  }
}

The corresponding ABI will be

[
    {
        "constant": true,
        "inputs": [],
        "name": "owner",
        "outputs": [
            {
                "name": "",
                "type": "address"
            }
        ],
        "payable": false,
        "stateMutability": "view",
        "type": "function"
    },
    {
        "constant": true,
        "inputs": [],
        "name": "greetings",
        "outputs": [
            {
                "name": "",
                "type": "address"
            }
        ],
        "payable": false,
        "stateMutability": "view",
        "type": "function"
    },
    {
        "constant": false,
        "inputs": [],
        "name": "takeMoneyAndDestroy",
        "outputs": [],
        "payable": false,
        "stateMutability": "nonpayable",
        "type": "function"
    },
    {
        "inputs": [],
        "payable": false,
        "stateMutability": "nonpayable",
        "type": "constructor"
    },
    {
        "payable": true,
        "stateMutability": "payable",
        "type": "fallback"
    }
  ]

Once you deploy this contract on the chain, you'll get a contract address, say 0x01. You can then access this contract from a wallet like MyEtherWallet and in the section https://www.myetherwallet.com/#contracts you can easily insert the address and the ABI.

The next step is simple as MyEtherWallet will allow you to invoke functions/transactions with the contract.

About Web3. This library bridges html/js applications in the browser with a "provider" service (your ETH full node, or other API producer) which in turn will translate the calls into transactions.

3

Question : If I deploy my smart contract to the real Ethereum blockchain, then is there any user interface with which I could access the contract functions in the same way as I can do in MyEtherWalet?

Answer: You can use Remix at remix.ethereum.org. This is also good way to deploy your contract to main network. To deploy your contract using Remix you have to:

  1. Copy your contract to Remix and compile it. If you have multfile contract then you have to make it flat. This means you have to copy all your contract and functions to one file. Remix supports multfile conract, but it is not yet possible to verify multfile contracts and debug them later on.

  2. Once you compile it then go to Run section of Remix. Choose Injected Web3 as Environment and make sure Metamask is connected to the network you want to deploy it to. After you Click Deploy you will have to confirm your transaction in Metamask. Once transaction is mined you will see list of functions of your contract and you will be able to interact with it.

If you already deployed a contract then follow same steps and instead of Deploying contract in Remix specify Address in Run section where it says "Load contract from address" and click "At Address button"

You have to first compile your contract before you can attach to it.

Remix is good because it allows you to debug your contracts and you can also quickly test your contract using Javascript VM environment. It works like testrpc, but allows you to debug your contract using UI.

Question 2: What is the role of Web3 here?

Answer: Web3 is a library which allows you to interact with blockchain nodes. It is also used by Metamask. You need to use web3 if you are planning to implement a webpage which has to either communicate with node or use Metamask.

In short web3 is a library which allows you to talk to ethereum nodes (providers).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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