Yeah, you are right I didnât think about increasing amount of arguments in the ICO contract, I also had some problems because I forgot to change the name of the constructor.
- Do you have idea how can I implement function to check how many tokens are left to buy?
I have tried this code, but it doesnât return anything. I think it needs return statement, but the compailer is giving the error:
TypeError: Different number of arguments in return statement than in returns declaration.
return token.balanceOf(address(this));
interface DubCoin {
function transfer (address receiver, uint amount);
function balanceOf (address ico);
}
function getLeftTokens() public view returns(uint balance) {
token.balanceOf(address(this));
}
Code in app.js
function getLeft() {
instance.getLeftTokens(function (error, result) {
if(error){
alert(error);
}
else{
$("#tokens").html(result.toString());
}
});
}
- I would like to ask you about deploying contracts beyond the browser. I mean I have installed truffle (your video about truffle on youtube really helped), but I canât find solution to deploy the contract on the rinkeby testnet. I read that I need hdwalletprovider, but I canât install it through npm. Iâm not sure if I understand it correctly, that Truffle has moved all modules to a monorepo at trufflesuite/truffle, it means that the hdwalletprovider is now inside the truffle which I have already installed, but I canât find info how to use it, to execute sth like that:
module.exports = {
rinkeby: {
provider: function() {
return new HDWalletProvider(mnemonic, "rinkeby.infura.io/v3/InfuraAPI");
},
network_id: '1',
},
};
BTW I feel that programming on windows is a little bit harder compared to mac if it is related to npm, because I couldnât e.g. execute your method from the video HalloWorld.at(âaddressâ).getName.call() - powershell throws an error.
- I have problem with withdraw ETH back from contract.
function safeWithdrawal() public {
if(!fundingGoalReached){
uint amount = balanceOfShare[msg.sender];
balanceOfShare[msg.sender] = 0;
// if(amount > 0){
msg.sender.transfer(amount);
if(!msg.sender.send(amount)){
balanceOfShare[msg.sender] = amount;
// }
}
} else if(fundingGoalReached && msg.sender == beneficiary){
if(!beneficiary.send(totalAmountRaised)){
fundingGoalReached = false;
}
}
}
Code in the app.js
function withdraw(){
instance.safeWithdrawal.sendTransaction({from: accounts[0], gas:100000, value:0}, function (error, result){
if (error){
alert(error)
} else {
$("#result").html("Withdraw proccesed.");
}
});
}
The problem is that I donât get my sent ETH back to the Metamask account and I canât find solution.