solidity, go-ethereum, web3js, truffle, remix – How to Get the ABI of a Contract

go-ethereumremixsoliditytruffleweb3js

In my contact have multiple imports and successfully deployed my contract.
This is my contract address 0xc2d4d839001f9d985618a22b89155ea8d6550ae6

How can get the abi of my contracts :

pragma solidity ^0.4.18;

import './DeveloperToken.sol';
import 'zeppelin-solidity/contracts/crowdsale/CappedCrowdsale.sol';
import 'zeppelin-solidity/contracts/crowdsale/RefundableCrowdsale.sol';

contract DeveloperCrowdsale is CappedCrowdsale, RefundableCrowdsale {

I tried this :

var compiled = web3.eth.compile.solidity(contractaddress);

var code = compiled.code;
var abi = compiled.info.abiDefinition;

var contract = web3.eth.contract(abi);

But It's not working .
How can I get the abi of my smart contract ?

Best Answer

Save your source code in a file and use the solidity compiler to generate the ABI.

You can install it with

npm install -g solc

or

yarn global add solc

and then run it against your source code

solcjs --abi contract.sol

It will generate the ABI in your current directory contract_sol_[ContractName].abi

Related Topic