Not able to execute a deployed contract

0 votes

My contract is as follows:

pragma solidity ^0.4.2;

contract Charity{

    mapping (address => uint) public coinBalanceOf;

    event CoinTransfer(address sender, address receiver, uint amount);

    function charity(uint supply){

        coinBalanceOf[msg.sender] = supply;

    }

    function sendCoin(address receiver, uint amount) returns (bool sufficient)

    {

        if (coinBalanceOf[msg.sender] < amount) return false;

        coinBalanceOf[msg.sender] -= amount;

        coinBalanceOf[receiver]   += amount;

        CoinTransfer(msg.sender, receiver, amount);

        return true;

    }

}

When I deploy using web3 1.0.0-beta with

import * as fs       from 'fs'       ;

import * as solc     from 'solc'     ;

import * as Web3     from 'web3'     ;

var web3   = new Web3(new Web3.providers.WebsocketProvider('ws://localhost:8546'));

var contract_path : string = "../solidity/contracts/Charity.sol"

const input       = fs.readFileSync(contract_path)

const output      = solc.compile(input.toString(), 1);

var contract_name = ":" + pr.last(contract_path.split("/")).split(".")[0]

const bytecode    = output.contracts[contract_name].bytecode

const abi_        = JSON.parse(output.contracts[contract_name].interface);

web3.eth.getAccounts().then(accounts => {

    var coinbase = accounts[0];

    var receiver = accounts[1];

    // create contract

    var myContract = new web3.eth.Contract(abi_, coinbase,

        {

            from    : coinbase,

            gasPrice: "2000000"

        });

    var deployedContract = myContract.deploy({

        data: '0x' + bytecode,

    }).send({

        from: coinbase,

        gas : 1500000 ,

        gasPrice: '30000000000000'           

    }, (err, hash) => {

        if (err) { console.log("error on deployment: ", err) }

        console.log("Hash: ", hash)

    })

    myContract.methods.sendCoin(receiver, 7000000).send({

        from: coinbase,

        gas: 100000,

        gasPrice: '10000000'

    }, (err,val) => {

            if (err) { console.log(err) }

            else {

                console.log("sent coin: ", val)

            }

        })

    .then(console.log) 

});

The contract deployed successfully but it’s not executing.

Jul 30, 2018 in Blockchain by slayer
• 29,370 points
727 views

1 answer to this question.

0 votes

The problem is that you are not passing the value for supply when you are initializing the contract. You can do it like this:

var deployedContract = myContract.deploy({

  data: '0x' + bytecode,

  arguments: [999999999]

}).send({

  from: coinbase,

  gas : 1500000 ,

  gasPrice: '30000000000000'           

}, (err, hash) => {

  if (err) { console.log("error on deployment: ", err) }

  console.log("Hash: ", hash)

})

To know more visit: http://web3js.readthedocs.io/en/1.0/web3-eth-contract.html#deploy

answered Jul 30, 2018 by digger
• 26,740 points

Related Questions In Blockchain

0 votes
1 answer

Not able to invoke a contract in Ethereum Private chain using geth

Hope this helps: contract mortal { /* ...READ MORE

answered Oct 22, 2018 in Blockchain by Omkar
• 69,220 points
1,004 views
0 votes
1 answer

Not Able to register a user with Hyperledger-Fabric v1.1 preview

The error: "Certificate not found with AKI 'e729224e8b3f31784c8a93c5b8ef6f4c1c91d9e6e577c45c33163609fe40011' ...READ MORE

answered Jun 16, 2018 in Blockchain by charlie_brown
• 7,720 points
1,900 views
0 votes
1 answer
+1 vote
3 answers

Not able to read a file from my assets folder

Hi.. I faced a similar problem in ...READ MORE

answered Oct 25, 2018 in Blockchain by Shrikanth
6,989 views
0 votes
1 answer

Truffle tests not running after truffle init

This was a bug. They've fixed it. ...READ MORE

answered Sep 11, 2018 in Blockchain by Christine
• 15,790 points
1,942 views
0 votes
1 answer

Hyperledger Sawtooth vs Quorum in concurrency and speed Ask

Summary: Both should provide similar reliability of ...READ MORE

answered Sep 26, 2018 in IoT (Internet of Things) by Upasana
• 8,620 points
1,468 views
0 votes
1 answer
0 votes
1 answer
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP