Whenever i try to hit this request i get a error, also used debugger and it says buyTokens function not found.

exports.transferEthShare = (data, next) => {
var data_contract = require('../contractABI/data');
var abiData = require('../contractABI/testabi');
let send_add = data.user_address;
let recv_add = data.contract_address;
let transfer_amount = web3.toWei(data.amount, 'ether');
let nonce = web3.toHex(web3.eth.getTransactionCount(data.user_address));
var private_key = data.user_pri_key.slice(2);
let gas = web3.toHex(data.gas_limit);
let gasPrice = web3.toHex(data.gas_price);
var contract_abi = abiData.abi;
var demo_Contract = web3.eth.contract(contract_abi);

let deploy = demo_Contract.buyTokens.getData(   // to ask --- start
        data: data_contract.abiData,
    });                                         // to ask --- end
var rawTx = {
    from: send_add,
    nonce: nonce,
    gasLimit: gas,
    gasPrice: gasPrice,
    value: web3.toHex(transfer_amount),
    to: recv_add,
    data: deploy,
var transaction = new tx(rawTx);
var txData = new Buffer(private_key, 'hex');
var serializedTx = transaction.serialize().toString('hex');
web3.eth.sendRawTransaction('0x' + serializedTx, function (err, txHash) {
    if (txHash) {
        next(null, txHash);
    else if (err && err.message) {
        next(err.message, null);
    else {
        next('Unable to sendRawTransaction', null);


1 Answer 1


It is showing error because you are not pointing to any contract. You simply used abi of contract to call the function. You need to first point to the contract having buyToken function then you can call it.

Like this : -

var contract_abi = abiData.abi;
var cont_instance = web3.eth.contract(contract_abi).at(contractAddress); //use this line

let deploy = cont_instance.buyTokens.getData(   
    data: data_contract.abiData,

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.