0

Before I post this question, I have searched several times all such relative questions and couldn't find a proper solution. Let me narrate the steps I did and the Issue I have.

I did all these steps in Rinkeby network.

  1. I used Etherum Wallet (0.9.2) on windows 8.1 (64 bit) and deployed the same contract as mentioned in (https://www.ethereum.org/token); used the full coin code at the bottom of the page.
  2. I set the selling prices. Sell Price as 100000000000000 and buy price as 10000000000000, the total tokens as shown in the contract admin page is 10000000000000000000000.
  3. As I had two accounts in the wallet, tried to send ether (2 ethers) to the contact address but getting an error as "It seems this transaction will fail. If you submit it, it may consume all the gas you provide."

enter image description here

I ensured there is no throw statement as I was using solidity version 0.4.16. And the other account has enough ether remaining too. I tried to use the maximum gas that was shown in the slider before clickig the send button.

Has anyone else had similar problem with the wallet, and addressed it somehow?

2 Answers 2

1

There are actually a few things you should not forget:

  1. Sending Ether to the aforementioned token contract will surely fail since it does not implement a payable fallback function. Later you should call the payable buy() function but before doing this,
  2. Make sure that there are some tokens at the token contract address. If there is not any, then noone is able to buy tokens, since every purchase is made not from the owner of the token but from the token contract address (this).

If you have a look at the source code you linked you can see the line Transfer(this, msg.sender, amount) in the buy function. This means that the contract tries to send tokens from its own balance, but at the creation of the token contract, only the owner of the token contract possess tokens, not the contract itself. So just send some tokens from the owner of the contract to the token contract itself!

4
  • Thanks for the advice, can you propose a sample gist with the relevant changes so that the deployment of contract is suffice to buy/sell tokens.
    – Rajesh
    Oct 16, 2017 at 9:01
  • Now that I have transferred about 5000 tokens to the contract address, I wanted to send 1 Ether to the contract address, still getting the same issue. Guess this is due to missing of payable fallback function, am I right?
    – Rajesh
    Oct 16, 2017 at 9:12
  • 1
    Not just simply transfer Ether to the token contract, rather call the buy function AND send Ether along with this transaction. Plain Ether transfer will obviously fail since there is no fallback function implemented...in geth this would look like something similar to this: tokenInstance.buy.sendTransaction({from: eth.accounts[0],value: TYPE SOME INTEGER HERE,gas:1000000}); Oct 16, 2017 at 9:34
  • thanks Istvan, I will explore how to call the buy function of the contract within the Ethereum Wallet itself. If you know how to do it, please share it here so that it can be useful for someone that has similar problem. I observed its possible with Admin interface of the contract, but still exploring how would some third party call the buy function within the wallet
    – Rajesh
    Oct 16, 2017 at 9:50
0

I know I could add these steps in comments, but it will be helpful for someone that can I find the answer in a proper place.

  • While deploying the contract, have enough ethers to it as it will be consumed in the gas when someone is trying to execute the method of the contract.
  • Transfer the ownership to the contract. This can be done by Contracts Admin page in the Ethereum wallet, and choose the function TransferOwnership and execute it
  • If it still fails, transfer some token to the contract address.
  • Now, allow the other person to watch the contract within the ethereum wallet by visiting the contract tab, and click on Watch Contract. They will need the address of the contract and the ABI JSON interface code. Once, they added this contract to their wallet, they will have similar interface that was shown in the contract admin page, and they can buy the token by executing the buy function of the contract, they can pass the parameter to get the equivalent tokens in their account.
  • Please remember to set the prices while deploying the contract, so that they would get relevant number of tokens.

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.