3

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 ?

4

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

  • I tried this this is giving me error : solcjs --abi DeveloperCrowdsale.sol DeveloperCrowdsale.sol:3:1: ParserError: Source "DeveloperToken.sol" not found: File not supplied initially. import './DeveloperToken.sol'; ^----------------------------^ DeveloperCrowdsale.sol:4:1: ParserError: Source "zeppelin-solidity/contracts/crowdsale/CappedCrowdsale.sol" not found: File not supplied initially. import 'zeppelin-solidity/contracts/crowdsale/CappedCrowdsale.sol'; ^-----------------------------------------------------------------^ – Chirag Maliwal Mar 13 '18 at 12:39
  • DeveloperCrowdsale.sol:5:1: ParserError: Source "zeppelin-solidity/contracts/crowdsale/RefundableCrowdsale.sol" not found: File not supplied initially. import 'zeppelin-solidity/contracts/crowdsale/RefundableCrowdsale.sol'; ^---------------------------------------------------------------------^ – Chirag Maliwal Mar 13 '18 at 12:39
2

The simples solution to get the ABI is to use Remix:

For example, if I modify your code slightly to be the following


pragma solidity ^0.4.18;

import 'https://github.com/OpenZeppelin/zeppelin-solidity/contracts/token/ERC20/ERC20.sol';
import 'https://github.com/OpenZeppelin/zeppelin-solidity/contracts/crowdsale/validation/CappedCrowdsale.sol';
import 'https://github.com/OpenZeppelin/zeppelin-solidity/contracts/crowdsale/distribution/RefundableCrowdsale.sol';

contract DeveloperToken is ERC20 {

}   

contract DeveloperCrowdsale is CappedCrowdsale, RefundableCrowdsale {
}

Then you can get the ABI on the details section of the compile tab by following these simple steps:

enter image description here

However, you will note that there are two differences between my import statements and yours:

  1. Remix needs a URL to the github account.
  2. You are using an out of date version of OpenZeppelin libraries.

It looks like the code that you have is from a Truffle project, in which case when you call truffle compile a DeveloperCrowdsale.json file will be created in the ../build/contracts directory. This JSON will contain the ABI.

  • Yes, You are right . I am using truffle for compile and deploy the contract. Yes, in build/contracts have DeceloperCrowdsale.json file which contains following code pastebin.com/b9BskCAh – Chirag Maliwal Mar 13 '18 at 13:56

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.