1

I am newbie at smart contracts and their deploying and I am pretty confused. I am following this example https://github.com/bellaj/Ballot-Dapp Someone could explain me well what these lines do, please?

var abiArray =[{"constant":false,"inputs":[{"name":"proposal","type":"uint256"}],"name":"vote","outputs":[],"type":"function"},{"constant":true,"inputs":[{"name":"","type":"uint256"}],"name":"proposals","outputs":[{"name":"name","type":"bytes32"},{"name":"voteCount","type":"uint256"}],"type":"function"},{"constant":true,"inputs":[],"name":"chairperson","outputs":[{"name":"","type":"address"}],"type":"function"},{"constant":false,"inputs":[{"name":"to","type":"address"}],"name":"delegate","outputs":[],"type":"function"},{"constant":true,"inputs":[],"name":"winningProposal","outputs":[{"name":"winningProposal","type":"uint256"}],"type":"function"},{"constant":false,"inputs":[{"name":"voter","type":"address"}],"name":"giveRightToVote","outputs":[],"type":"function"},{"constant":true,"inputs":[{"name":"","type":"address"}],"name":"voters","outputs":[{"name":"weight","type":"uint256"},{"name":"voted","type":"bool"},{"name":"delegate","type":"address"},{"name":"vote","type":"uint256"}],"type":"function"},{"inputs":[{"name":"proposalNames","type":"bytes32[]"}],"type":"constructor"}]


var MyContract = web3.eth.contract(abiArray);

var contractInstance = MyContract.at('0xd9107d1f3c52bb440256a5f3ad9d6c2c3f38e1ee');// Instantiate from an existing address:
0

First line

var abiArray =[{"constant":false,"inputs":[{"name":"proposal","type":"uint256"}],"name":"vote","outputs":[],"type":"function"},{"constant":true,"inputs":[{"name":"","type":"uint256"}],"name":"proposals","outputs":[{"name":"name","type":"bytes32"},{"name":"voteCount","type":"uint256"}],"type":"function"},{"constant":true,"inputs":[],"name":"chairperson","outputs":[{"name":"","type":"address"}],"type":"function"},{"constant":false,"inputs":[{"name":"to","type":"address"}],"name":"delegate","outputs":[],"type":"function"},{"constant":true,"inputs":[],"name":"winningProposal","outputs":[{"name":"winningProposal","type":"uint256"}],"type":"function"},{"constant":false,"inputs":[{"name":"voter","type":"address"}],"name":"giveRightToVote","outputs":[],"type":"function"},{"constant":true,"inputs":[{"name":"","type":"address"}],"name":"voters","outputs":[{"name":"weight","type":"uint256"},{"name":"voted","type":"bool"},{"name":"delegate","type":"address"},{"name":"vote","type":"uint256"}],"type":"function"},{"inputs":[{"name":"proposalNames","type":"bytes32[]"}],"type":"constructor"}]

ABI stands for ***Application Binary Interface*. It describes the smart contract interface representing all attributes and function definitions. So anybody can develop a client and interact with binary contract.

=> Analogy: API

2nd line

var MyContract = web3.eth.contract(abiArray);

According to the Web3 documentation:

Creates a contract object for a solidity contract, which can be used to initiate contracts on an address.

It returns a JavaScript object compatible with the ABI (interface definition).

=> Analogy: API JS Wrapper

3rd line

var contractInstance = MyContract.at('0xd9107d1f3c52bb440256a5f3ad9d6c2c3f38e1ee');

A smart contract can be deployed/instantiated multiple time. The keyword at allows you to configure the deployed address for this contract definition.

=> Analogy: API endpoint

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.