0

My project is in Truffle. I programmed a smart contract and want to deploy it with JavaScript. But the following error occurs:

Error: Contract error: contract binary not set. Can't deploy new instance. This contract may be abstract, not implement an abstract parent's methods completely or not invoke an inherited contract's constructor correctly.

I don't know the solution to eliminate this problem.

app.js:

var Web3=require('web3');
var contract=require("truffle-contract");
var solc=require("solc");
var web3=new Web3('ws://localhost:8545');
var express=require('express');
var app=express();
var fs=require('fs');
var bodyParser=require('body-parser');
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({extended:false}));
app.use(express.static('E:/Alireza/src/js'));
web3.eth.defaultAccount="0x6Db320B080b956c371c4bC5b00eF74e73bCE7798";
                   .
                   .
                   .
app.post('/send-data', function(q,r){   
    var source2='E:/Alireza/contracts/customer.sol';
    var customercompiled=solc.compile(source2)
    var customerJson="E:/Alireza/build/contracts/customer.json";
    var customerJs=JSON.parse(fs.readFileSync(customerJson));
    var customer=new web3.eth.Contract(customerJs.abi, null, {data: 
        ByteCode});

    web3.eth.personal.unlockAccount("0x83Ad536099658519ee6A40A3faCAf3dDcEf6178a","Alireza").then(()=>{console.log("Address unlocked");}).catch(console.error);
    var testContract=contract(customerJson);
        testContract.setNetwork("*");
        testContract.setProvider("http://127.0.0.1:8545");
        testContract.new({from: "0xEfc311bfE4aD02fe77cAa172FbbEe7a3563752C5", 
           gas:2000000, gasPrice:200});
        customer.deploy().send({from: 
           "0xEfc311bfE4aD02fe77cAa172FbbEe7a3563752C5", gas:2000000, 
           gasPrice:200}).then((instance)=>{console.log("Contract mined at 
           "+instance.options.address);
           customerInstance=instance});   
         });

The mentioned error occurs in testContract.new(...) line.

Contract binary:

var ByteCode="0x60806040526729a2241af62c00006006556729a2241af62c000060075534801561002857600080fd5b50611af8806100386000396000f3fe6080604052600436106100dd5760003560e01c80638417ad851161007f578063af640d0f11610059578063af640d0f14610a8a578063bb9dbbfb14610ab5578063f7dd3d0714610ae0578063ffbee27014610df8576100dd565b80638417ad8514610693578063972eef4714610723578063a12a6bb014610a5b576100dd565b806327d35801116100bb57806327d35801146104d257806350520b1f146105625780635fae4cc81461056c5780636fd5ae1514610668576100dd565b80630e899f77146100df57806313faede61461016f5780632593399c1461019a575b005b3480156100eb57600080fd5b506100f4610e88565b6040518080602001828103825283818151815260200191508051906020019080838360005b83811015610134578082015181840152602081019050610119565b50505050905090810190601f1680156101615780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b34801561017b57600080fd5b50610184610f26565b6040518082815260200191505060405180910390f35b3480156101a657600080fd5b506104d0600480360360e08110156101bd57600080fd5b81019080803590602001906401000000008111156101da57600080fd5b8201836020820111156101ec57600080fd5b8035906020019184600183028401116401000000008311171561020e57600080fd5b91908080601f016020809104026020016040519081016040528093929190818152602001838380828437600081840152601f19601f8201169050808301925050505050505091929192908035906020019064010000000081111561027157600080fd5b82018360208201111561028357600080fd5b803590602001918460018302840111640100000000831117156102a557600080fd5b91908080601f016020809104026020016040519081016040528093929190818152602001838380828437600081840152601f19601f820116905080830192505050505050509192919290803590602001909291908035906020019064010000000081111561031257600080fd5b82018360208201111561032457600080fd5b8035906020019184600183028401116401000000008311171561034657600080fd5b91908080601f016020809104026020016040519081016040528093929190818152602001838380828437600081840152601f19601f82011690508083019250505050505050919291929080359060200190929190803590602001906401000000008111156103b357600080fd5b8201836020820111156103c557600080fd5b803590602001918460018302840111640100000000831117156103e757600080fd5b91908080601f016020809104026020016040519081016040528093929190818152602001838380828437600081840152601f19601f8201169050808301925050505050505091929192908035906020019064010000000081111561044a57600080fd5b82018360208201111561045c57600080fd5b8035906020019184600183028401116401000000008311171561047e57600080fd5b91908080601f016020809104026020016040519081016040528093929190818152602001838380828437600081840152601f19601f820116905080830192505050505050509192919290505050610f2c565b005b3480156104de57600080fd5b506104e7611027565b6040518080602001828103825283818151815260200191508051906020019080838360005b8381101561052757808201518184015260208101905061050c565b50505050905090810190601f1680156105545780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b61056a6110c5565b005b34801561057857600080fd5b506105816111f6565b604051808060200180602001838103835285818151815260200191508051906020019080838360005b838110156105c55780820151818401526020810190506105aa565b50505050905090810190601f1680156105f25780820380516001836020036101000a031916815260200191505b50838103825284818151815260200191508051906020019080838360005b8381101561062b578082015181840152602081019050610610565b50505050905090810190601f1680156106585780820380516001836020036101000a031916815260200191505b5094505050505060405180910390f35b34801561067457600080fd5b5061067d6113d1565b6040518082815260200191505060405180910390f35b34801561069f57600080fd5b506106a86113d7565b6040518080602001828103825283818151815260200191508051906020019080838360005b838110156106e85780820151818401526020810190506106cd565b50505050905090810190601f1680156107155780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b34801561072f57600080fd5b50610a59600480360360e081101561074657600080fd5b810190808035906020019064010000000081111561076357600080fd5b82018360208201111561077557600080fd5b8035906020019184600183028401116401000000008311171561079757600080fd5b91908080601f016020809104026020016040519081016040528093929190818152602001838380828437600081840152601f19601f820116905080830192505050505050509192919290803590602001906401000000008111156107fa57600080fd5b82018360208201111561080c57600080fd5b8035906020019184600183028401116401000000008311171561082e57600080fd5b91908080601f016020809104026020016040519081016040528093929190818152602001838380828437600081840152601f19601f820116905080830192505050505050509192919290803590602001909291908035906020019064010000000081111561089b57600080fd5b8201836020820111156108ad57600080fd5b803590602001918460018302840111640100000000831117156108cf57600080fd5b91908080601f016020809104026020016040519081016040528093929190818152602001838380828437600081840152601f19601f820116905080830192505050505050509192919290803590602001909291908035906020019064010000000081111561093c57600080fd5b82018360208201111561094e57600080fd5b8035906020019184600183028401116401000000008311171561097057600080fd5b91908080601f016020809104026020016040519081016040528093929190818152602001838380828437600081840152601f19601f820116905080830192505050505050509192919290803590602001906401000000008111156109d357600080fd5b8201836020820111156109e557600080fd5b80359060200191846001830284011164010000000083111715610a0757600080fd5b91908080601f016020809104026020016040519081016040528093929190818152602001838380828437600081840152601f19601f820116905080830192505050505050509192919290505050611475565b005b348015610a6757600080fd5b50610a7061168b565b604051808215151515815260200191505060405180910390f35b348015610a9657600080fd5b50610a9f61169e565b6040518082815260200191505060405180910390f35b348015610ac157600080fd5b50610aca6116a4565b6040518082815260200191505060405180910390f35b348015610aec57600080fd5b50610af56116aa565b604051808060200180602001806020018060200180602001806020018060200188810388528f818151815260200191508051906020019080838360005b83811015610b4d578082015181840152602081019050610b32565b50505050905090810190601f168015610b7a5780820380516001836020036101000a031916815260200191505b5088810387528e818151815260200191508051906020019080838360005b83811015610bb3578082015181840152602081019050610b98565b50505050905090810190601f168015610be05780820380516001836020036101000a031916815260200191505b5088810386528d818151815260200191508051906020019080838360005b83811015610c19578082015181840152602081019050610bfe565b50505050905090810190601f168015610c465780820380516001836020036101000a031916815260200191505b5088810385528c818151815260200191508051906020019080838360005b83811015610c7f578082015181840152602081019050610c64565b50505050905090810190601f168015610cac5780820380516001836020036101000a031916815260200191505b5088810384528b818151815260200191508051906020019080838360005b83811015610ce5578082015181840152602081019050610cca565b50505050905090810190601f168015610d125780820380516001836020036101000a031916815260200191505b5088810383528a818151815260200191508051906020019080838360005b83811015610d4b578082015181840152602081019050610d30565b50505050905090810190601f168015610d785780820380516001836020036101000a031916815260200191505b50888103825289818151815260200191508051906020019080838360005b83811015610db1578082015181840152602081019050610d96565b50505050905090810190601f168015610dde5780820380516001836020036101000a031916815260200191505b509e50505050505050505050505050505060405180910390f35b348015610e0457600080fd5b50610e0d611853565b6040518080602001828103825283818151815260200191508051906020019080838360005b83811015610e4d578082015181840152602081019050610e32565b50505050905090810190601f168015610e7a5780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b60058054600181600116156101000203166002900480601f016020809104026020016040519081016040528092919081815260200182805460018160011615610100020316600290048015610f1e5780601f10610ef357610100808354040283529160200191610f1e565b820191906000526020600020905b815481529060010190602001808311610f0157829003601f168201915b505050505081565b60065481565b8660009080519060200190610f42929190611a1e565b508560019080519060200190610f59929190611a1e565b50846002819055506040518060400160405280600a81526020017fd8aad8a3db8cdb8cd8af000000000000000000000000000000000000000000008152508051906020012084805190602001201415610fc8576001600360006101000a81548160ff0219169083151502179055505b8260048190555082600381610fd957fe5b046007600082825481610fe857fe5b04925050819055508160059080519060200190611006929190611a1e565b50806008908051906020019061101d929190611a1e565b5050505050505050565b60088054600181600116156101000203166002900480601f0160208091040260200160405190810160405280929190818152602001828054600181600116156101000203166002900480156110bd5780601f10611092576101008083540402835291602001916110bd565b820191906000526020600020905b8154815290600101906020018083116110a057829003601f168201915b505050505081565b600160098054905001600654816110d857fe5b043414156111f45760008090505b60098054905081101561118c576009818154811061110057fe5b9060005260206000200160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff166108fc600980549050348161115257fe5b049081150290604051600060405180830381858888f1935050505015801561117e573d6000803e3d6000fd5b5080806001019150506110e6565b5060093390806001815401808255809150509060018203906000526020600020016000909192909190916101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff160217905550505b565b60608060011515600360009054906101000a900460ff16151514156112f35760056040518060400160405280600a81526020017fd8aad8a3db8cdb8cd8af0000000000000000000000000000000000000000000081525090808054600181600116156101000203166002900480601f0160208091040260200160405190810160405280929190818152602001828054600181600116156101000203166002900480156112e35780601f106112b8576101008083540402835291602001916112e3565b820191906000526020600020905b8154815290600101906020018083116112c657829003601f168201915b50505050509050915091506113cd565b60056040518060400160405280600f81526020017fd8b1d8af20d8aad8a3db8cdb8cd8af000000000000000000000000000000000081525090808054600181600116156101000203166002900480601f0160208091040260200160405190810160405280929190818152602001828054600181600116156101000203166002900480156113c15780601f10611396576101008083540402835291602001916113c1565b820191906000526020600020905b8154815290600101906020018083116113a457829003601f168201915b50505050509050915091505b9091565b60045481565b60008054600181600116156101000203166002900480601f01602080910402602001604051908101604052809291908181526020018280546001816001161561010002031660029004801561146d5780601f106114425761010080835404028352916020019161146d565b820191906000526020600020905b81548152906001019060200180831161145057829003601f168201915b505050505081565b866000908051906020019061148b929190611a1e565b5085600190805190602001906114a2929190611a1e565b50846002819055506040518060400160405280600a81526020017fd8aad8a3db8cdb8cd8af000000000000000000000000000000000000000000008152508051906020012084805190602001201415611511576001600360006101000a81548160ff0219169083151502179055505b826004819055508260038161152257fe5b04600660008282548161153157fe5b0492505081905550816005908051906020019061154f929190611a1e565b508060089080519060200190611566929190611a1e565b5060093390806001815401808255809150509060018203906000526020600020016000909192909190916101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff16021790555050739638101cb6571cc3a807a2a4e770ee040dd0275c73ffffffffffffffffffffffffffffffffffffffff166395a8a804600254306040518363ffffffff1660e01b8152600401808381526020018273ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200192505050600060405180830381600087803b15801561166a57600080fd5b505af115801561167e573d6000803e3d6000fd5b5050505050505050505050565b600360009054906101000a900460ff1681565b60025481565b60075481565b6060806060806060806060600060016116c46002546118f1565b6116cf6004546118f1565b6116da6006546118f1565b6116e86009805490506118f1565b611704600160098054905001600654816116fe57fe5b046118f1565b868054600181600116156101000203166002900480601f0160208091040260200160405190810160405280929190818152602001828054600181600116156101000203166002900480156117995780601f1061176e57610100808354040283529160200191611799565b820191906000526020600020905b81548152906001019060200180831161177c57829003601f168201915b50505050509650858054600181600116156101000203166002900480601f0160208091040260200160405190810160405280929190818152602001828054600181600116156101000203166002900480156118355780601f1061180a57610100808354040283529160200191611835565b820191906000526020600020905b81548152906001019060200180831161181857829003601f168201915b50505050509550965096509650965096509650965090919293949596565b60018054600181600116156101000203166002900480601f0160208091040260200160405190810160405280929190818152602001828054600181600116156101000203166002900480156118e95780601f106118be576101008083540402835291602001916118e9565b820191906000526020600020905b8154815290600101906020018083116118cc57829003601f168201915b505050505081565b60606000821415611939576040518060400160405280600181526020017f30000000000000000000000000000000000000000000000000000000000000008152509050611a19565b600082905060005b60008214611963578080600101915050600a828161195b57fe5b049150611941565b6060816040519080825280601f01601f1916602001820160405280156119985781602001600182028038833980820191505090505b50905060006001830390505b60008614611a1157600a86816119b657fe5b0660300160f81b828280600190039350815181106119d057fe5b60200101907effffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff1916908160001a905350600a8681611a0957fe5b0495506119a4565b819450505050505b919050565b828054600181600116156101000203166002900490600052602060002090601f016020900481019282601f10611a5f57805160ff1916838001178555611a8d565b82800160010185558215611a8d579182015b82811115611a8c578251825591602001919060010190611a71565b5b509050611a9a9190611a9e565b5090565b611ac091905b80821115611abc576000816000905550600101611aa4565b5090565b9056fea265627a7a72315820f45cda1bb478dd44121fcef7fb74a5280383f7d2dadf4a3a0f759e89d4851f6964736f6c634300050c0032";

My contract full code:

pragma solidity ^0.5.12;
import "./customerFinder.sol";
contract customer{
   string public firstname;
   string public lastname;
   uint256 public id;
   bool public KYC;
   uint256 public level;
   string public docsHash;
   uint256 public cost=3 ether;
   uint256 public upcost=3 ether;
   string public bankName;
   address payable[] onboarded;

   function fill(string memory fname, string memory lname ,uint256 iden, string memory KYCresult, uint256 categor, string memory hash, string memory bank) public{
      firstname=fname;
      lastname=lname;
      id=iden;
         if(keccak256(bytes(KYCresult))==keccak256(bytes("تأیید")))
            {
               KYC=true;
            }
     level=categor;
     cost/=(3/categor);
     docsHash=hash;
     bankName=bank;
        onboarded.push(address(uint160(msg.sender)));
        customerFinder(0x9638101cb6571cc3A807A2a4e770Ee040dD0275c).filling(id, address(uint160(address(this))));
     }

   function contribution() public payable {
      if(msg.value==cost/(onboarded.length+1))
         {
            for(uint i=0; i<onboarded.length; i++)
               {
                  onboarded[i].transfer(msg.value/onboarded.length);
               }    
           onboarded.push(address(uint160(msg.sender)));
         }
      }
   function KYC_hash() public view returns(string memory, string memory){
       if(KYC==true)
         {
            return ("تأیید", docsHash);
         }else
             {
                return ("رد تأیید", docsHash);
             }
   }


   function update(string memory fname, string memory lname ,uint256 iden, string memory KYCresult, uint256 categor, string memory hash, string memory bank) public {
      firstname=fname;
      lastname=lname;
      id=iden;
         if(keccak256(bytes(KYCresult))==keccak256(bytes("تأیید")))
           {
              KYC=true;
           }
      level=categor;
      upcost/=(3/categor);
      docsHash=hash;
      bankName=bank;
   }
   function representation() public view returns(string memory, string memory, string memory, string memory, string memory, string memory, string memory){
      return (firstname, lastname, uint2str(uint(id)), uint2str(uint(level)), uint2str(uint(cost)), uint2str(uint(onboarded.length)), uint2str(uint(cost/(onboarded.length+1))));
   }

    function uint2str(uint _i) internal pure returns (string memory ) {
    if (_i == 0) {
        return "0";
    }
    uint j = _i;
    uint len;
    while (j != 0) {
        len++;
        j /= 10;
    }
    bytes memory bstr = new bytes(len);
    uint k = len - 1;
    while (_i != 0) {
        bstr[k--] = byte(uint8(48 + _i % 10));
        _i /= 10;
    }
    return string(bstr);
}
   function() external payable{}
}
0
1

Change this:

var testContract = contract(customerJson);

To this:

var testContract = contract({abi: customerJs.abi, unlinked_binary: ByteCode});
3
  • This error showed: TypeError: this.abi.filter is not a function.
    – Alireza
    Apr 7 '20 at 8:08
  • For this line: testContract.new({from: "0xEfc311bfE4aD02fe77cAa172FbbEe7a3563752C5", gas:2000000, gasPrice:200});
    – Alireza
    Apr 7 '20 at 8:10
  • @A.Kiakojouri: Sorry, see the small update in the answer. Apr 7 '20 at 8:11

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.