I want to create a decentralise application where I sell my tokens.So,In this scenario.I create a function to end my selling tokens.So,I create a function below.

The solidity code is here:-

function endSale() public {
     require(msg.sender == admin);

And truffle java script test code is here:-

 it('ends token sale', function() {
   `enter preformatted text here` 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(function(balance) {
      assert.equal(balance.toNumber(), 999990, 'returns all unsold dapp tokens to admin');
      // Check that token price was reset when selfDestruct was called
      return tokenSaleInstance.tokenPrice();
    }).then(function(price) {
      assert.equal(price.toNumber(), 0, 'token price was reset');

When I test it by truffle test command.So the following error comes:-

 Error: Attempting to run transaction which calls a contract function, but recipient address 0x970c30c59d21df9fe660a266faf2ba0871dc25ad is not a contract address

 at Object.InvalidResponse (/home/anupam/.config/yarn/global/node_modules/truffle/build/webpack:/~/web3/lib/web3/errors.js:38:1)
      at /home/anupam/.config/yarn/global/node_modules/truffle/build/webpack:/~/web3/lib/web3/requestmanager.js:86:1
      at /home/anupam/.config/yarn/global/node_modules/truffle/build/webpack:/~/truffle-provider/wrapper.js:134:1
      at XMLHttpRequest.request.onreadystatechange (/home/anupam/.config/yarn/global/node_modules/truffle/build/webpack:/~/web3/lib/web3/httpprovider.js:128:1)
      at XMLHttpRequestEventTarget.dispatchEvent (/home/anupam/.config/yarn/global/node_modules/truffle/build/webpack:/~/xhr2/lib/xhr2.js:64:1)
      at XMLHttpRequest._setReadyState (/home/anupam/.config/yarn/global/node_modules/truffle/build/webpack:/~/xhr2/lib/xhr2.js:354:1)
      at XMLHttpRequest._onHttpResponseEnd (/home/anupam/.config/yarn/global/node_modules/truffle/build/webpack:/~/xhr2/lib/xhr2.js:509:1)
      at IncomingMessage.<anonymous> (/home/anupam/.config/yarn/global/node_modules/truffle/build/webpack:/~/xhr2/lib/xhr2.js:469:1)
      at endReadableNT (_stream_readable.js:1064:12)
      at _combinedTickCallback (internal/process/next_tick.js:138:11)
      at process._tickCallback (internal/process/next_tick.js:180:9)

So,Anyone help me to resolve this type of error.And Please tell me where I mistake in code.

  • I think we need more context in order for us to answer this question. Can you provide more of the code? Apr 27, 2018 at 20:15

2 Answers 2


Try to remove the selfdestruct function call from the endSale function.


You cannot call tokenSaleInstance.tokenPrice() after tokenSaleInstance.endSale({ from: admin }) because the contract no longer exist after that point.

As suggested by @ThorkilVærge you can remove the selfdestruct if you need the price. Another option is to retrieve the price before you call to endSale().

  • Hello Ismael,I resolved this error es your suggestion.Thanks a lot. Apr 30, 2018 at 6:30
  • How can I reset the token price after calling selfdestruct?? Apr 30, 2018 at 6:32
  • You cannot make a call to a destructed contract. Either do not destruct the contract or move that functionality to separate contract.
    – Ismael
    Apr 30, 2018 at 16:52

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.