Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Not a contract address #20

Open
mindfu opened this issue Feb 17, 2019 · 1 comment
Open

Not a contract address #20

mindfu opened this issue Feb 17, 2019 · 1 comment

Comments

@mindfu
Copy link

mindfu commented Feb 17, 2019

Getting this error while working on Video 63:

Uncaught (in promise) Error: Attempting to run transaction which calls a contract function, but recipient address 0xc9301a4af7c3e531293ae3539dcecfef2507db40 is not a contract address
at Object.InvalidResponse (web3.min.js:1)
at web3.min.js:2
at XMLHttpRequest.n.onreadystatechange (web3.min.js:2)
InvalidResponse @ web3.min.js:1
(anonymous) @ web3.min.js:2
n.onreadystatechange @ web3.min.js:2
Promise.then (async)
render @ app.js:76
(anonymous) @ app.js:43
i @ jquery.min.js:2
fireWith @ jquery.min.js:2
y @ jquery.min.js:4
c @ jquery.min.js:4
XMLHttpRequest.send (async)
send @ jquery.min.js:4
ajax @ jquery.min.js:4
n.(anonymous function) @ jquery.min.js:4
getJSON @ jquery.min.js:4
(anonymous) @ app.js:37
i @ jquery.min.js:2
fireWith @ jquery.min.js:2
y @ jquery.min.js:4
c @ jquery.min.js:4
XMLHttpRequest.send (async)
send @ jquery.min.js:4
ajax @ jquery.min.js:4
n.(anonymous function) @ jquery.min.js:4
getJSON @ jquery.min.js:4
initContracts @ app.js:30
initWeb3 @ app.js:26
init @ app.js:12
(anonymous) @ app.js:102
dispatch @ jquery.min.js:3
r.handle @ jquery.min.js:3
load (async)
add @ jquery.min.js:3
(anonymous) @ jquery.min.js:3
each @ jquery.min.js:2
each @ jquery.min.js:2
sa @ jquery.min.js:3
on @ jquery.min.js:3
(anonymous) @ bootstrap.min.js:6
(anonymous) @ bootstrap.min.js:6

Any idea about this one?

@AnaMariaNanes
Copy link

AnaMariaNanes commented Feb 25, 2019

@mindfu You should make some changes:

  1. In DappTokenSale.sol:
    function endSale() public {
    require(msg.sender == admin);
    require(tokenContract.transfer(admin, tokenContract.balanceOf(address(this))));
    admin.transfer(address(this).balance);
    }

  2. In the test file DappTokenSale.js this is the entire test for the endSale() method:
    it('ends token sale', function() {
    return DappToken.deployed().then(function(instance) {
    // Grab token instance first
    tokenInstance = instance;
    return DappTokenSale.deployed();
    }).then(function(instance) {
    // Then grab token sale instance
    tokenSaleInstance = instance;
    // Try to end sale from account other than the admin
    return tokenSaleInstance.endSale({ from: buyer });
    }).then(assert.fail).catch(function(error) {
    assert(error.message.indexOf('revert') >= 0, 'must be admin to end sale');
    // End sale as admin
    return tokenSaleInstance.endSale({ from: admin });
    }).then(function(receipt) {
    return tokenInstance.balanceOf(admin);
    }).then(async function(balance) {
    assert.equal(balance.toNumber(), 999990, 'returns all unsold dapp tokens to admin');
    // Check that the contract has no balance
    await web3.eth.getBalance(tokenSaleInstance.address)
    .then(contract_balance => assert.equal(contract_balance, 0));
    });
    });

!!!! async and await are necessary because calls to web3.eth return a promise and not a value straigtforward.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants