Creating Ethereum Contracts (go ethereum)
Asked Answered
G

5

12

Trying to follow the wiki example for go ethereum to create a basic contract: https://github.com/ethereum/go-ethereum/wiki/Contracts-and-Transactions

Everything seems to work until I get down until the last line:

source = "contract test { function multiply(uint a) returns(uint d) { return a * 7; } }"
contract = eth.compile.solidity(source).test
primaryAddress = eth.accounts[0]

# **Problems start here **
MyContract = eth.contract(abi);
contact = MyContract.new(arg1, arg2, ...,{from: primaryAddress, data: evmCode})

What is the "abi" argument for the eth.contract method? Also, what would I put in the "evmCode" argument? In this particular example, seems like I would put in an integer for "arg1" but not sure what the full example should look like.

Gibby answered 25/11, 2015 at 22:25 Comment(0)
N
19

The ABI is the interface that your contract exposes. "evmCode" is the Ethereum byte code for your contract.

To work around your problem, go to https://chriseth.github.io/browser-solidity/ and plug your Solidity in. The Bytecode field on the right will give you the value for "evmCode" and Interface will give you the ABI.

You can also copy the snippet from "Web3 deploy" and paste it in your code to deploy your contract.

Neysa answered 29/11, 2015 at 3:1 Comment(2)
Thanks. What you suggested worked. However as I was learning about the EVM today, I noticed that the command line solidity compiler actually gives you the "evmCode" when you compile; it's just that the tutorial doesn't explain that the ABI is output to the command line when you compile. When I was reading the EVM documentation, I instantly thought about your comment on the ethereal byte code and made the connection.Gibby
Ah, I see. I didn't realize part of the tutorial involved working with solc. Glad you're up and running.Neysa
V
3

ABI is basically which is the public facing interface that shows what methods are available to call. The simplest way to get the abi would be to use https://remix.ethereum.org . just paste in your code and in Contract tab At the bottom of the column you’ll find a link that says Contract details which is basically the ABI json

Conversely you could also use the contracts.Introduction.interface api of web3 to get the abi.

Virgo answered 29/6, 2018 at 13:10 Comment(0)
S
3

ABI is representation of smart contract that can be read using java script .To read the data from a deployed contract account in etherum , you'll need some extra details like abi.

Steps to get abi of any smart contract:

1.Each contract has contract hash address like this:0x0D8775F648430679A709E98d2b0Cb6250d2887EF

2.Go to etherscan.io and search your contract address hash in search bar and you will get contract.

3.In contract go to code and there you can find this abi

can check this link to find abi

Siegler answered 3/6, 2021 at 7:29 Comment(0)
L
2

You could try using tools like Etherlime shape or Truffle boxes to have a whole sample project with contract, tests, and usage into the js. From here you could start moving forward.

Lynx answered 18/10, 2019 at 7:39 Comment(0)
B
2

ABI is Application Binary Interface. A contract when compiled by solidity compiler returns an object with different methods. ABI and Bytecode are basically used methods. ABI is used to interact with your contracts and frontend (if using node) and bytecode is used for deploying to Rinkeby (or any Ethereum network).

For example:
Contract is:

pragma solidity ^0.4.17;

contract Inbox
{

    string public message;

    function Inbox(string initialMessage) public{
        message = initialMessage;
    }

    function setMessage(string newMessage) public{
        message = newMessage;
    }
}

Its ABI is:

interface: 
[{
    "constant":false,"inputs":[{
        "name":"newMessage","type":"string"
    }]

    ,"name":"setMessage","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"
}
 ,{
     "constant":true,"inputs":[],"name":"message","outputs":[{
         "name":"","type":"string"
     }]

     ,"payable":false,"stateMutability":"view","type":"function"
 }
 ,{
     "inputs":[{
         "name":"initialMessage","type":"string"
     }]

     ,"payable":false,"stateMutability":"nonpayable","type":"constructor"
 }]

This is returned after compiling the contract. You can see it consists of methods used in our contract.

Bula answered 25/5, 2020 at 0:54 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.