Ethereum Smart Contract Programming

function getCstValue(){

contractInstance.methods.readCustomerBalance().call().then(function(res){
displayAmount(res);

});
}

function displayAmount(res){

console.log(res);
$("#customer_balance").text(res);
}

1 Like

Solved, apparently there is a web3 function that returns the value and my getter function was useless:

function getCstValue(){

web3.eth.getBalance(‘0x4d262D94ea943524795Eea00588aD5CB8dd5F17b’, function(error, result) {
if(error) {
console.log(error);
} else {
console.log(web3.utils.fromWei(result));
}
})};

1 Like

thank you! I have tried to follow your steps again, and I still get same error…:confused:

So I moved on to next lessons, where I am again stucked at “testing for errors”. I will open a new post about this…

Hi @filip, I have finish the Solidity programming course. Thanks for the tutorials. I have a question. I don’t know if I missed anything, but I didn’t see anywhere explaining how to deploy the solidity course to the testnet, then " Verify & Publish Contract". I built a Dapp(Solidity+React.js), and want to publish to testnet as a demo. Is there tutorial I can watch? thanks.

FYI, here is my contract. https://rinkeby.etherscan.io/address/0x01e98b517529a116dcd229791ace864e736a1a8a

Here is my source code.

Good job! Your contract is already on the testnet. So I assume you are asking how you can deploy a react app? So the frontend is actually on a domain. We don’t have a course on this since this is not unique to dapps, it’s the same procedure for every web application. You could probably use a tutorial like this: https://medium.com/jeremy-gottfrieds-tech-blog/tutorial-how-to-deploy-a-production-react-app-to-heroku-c4831dfcfa08

We are however working on a course that covers frontend deployment as well, including decentralizing parts of it.

pragma solidity 0.5.1;

contract DogContract2 {
function addDog(string memory _name, uint _age) public payable returns (uint);

function getBalance() public view returns (uint);

}

contract ExternalContract {

DogContract2 dcInstance = DogContract2(0xdC04977a2078C8FFDf086D618d1f961B6C546222);

function addExternalDog(string memory _name, uint _age) public payable returns (uint) {
    return dcInstance.addDog.value(msg.value)(_name,_age);
}

function getExternalBalance() public view returns (uint) {
    return dcInstance.getBalance();
}

}

1 Like

Hi guys ,how are you ? Need a litle help .
How can i Console.log or print a function return number ?
//qwerty() return a number betwen 0 and 1 .
// i need to get this number from return.

$("#thebutton").click(async function(){
let result=await contractInstance.methods.qwerty().send(config); console.log(result);
});

SOLVED
Hello,
I’m having issues with running the program.

When I try to run the code, the box to choose the contract is grayed out and under it, it says “No compiled contracts”. When I try to compile the program I get this error:

Internal exception in StandardCompiler::compileInternal: /root/project/libevmasm/ExpressionClasses.cpp(187): Throw in function ExpressionClasses::Id dev::eth::ExpressionClasses::tryToSimplify(const dev::eth::ExpressionClasses::Expression &)
Dynamic exception type: boost::exception_detail::clone_impl<dev::eth::OptimizerException>
std::exception::what: Rule list not properly initialized.
[dev::tag_comment*] = Rule list not properly initialized.

If you get this error you are most likely using Firefox, try switching it to Chrome. It worked for me

Take care guys.

1 Like

Perfect. Congratulations on handling the bug like a pro…
Thanks for sharing your solution.

Happy coding!

Ivo

1 Like

Hi, Sanji94m.

Please support our community by subscribing to our courses and attend our classes.
You will get the help and learn all you need, if you just subscribe to Ivan On Tech Academy like the rest of us. :handshake: :hugs: :roll_eyes:

We would appreciate it if you follow this link to go to the subscription page and subscribe. You cant learn programming by just visiting us in the forum, the forum is just a small part of Ivan On Tech Academy. We hope to see you back here in the near future as a fellow student.:blush:

If you have any questions, feel free to send me a DM and we can sort things out.
Ivo

Would be nice if you showed what getdog returns. For me it shows the correct index in the array, and the first string but leaves the three last values unshown. Im sure this will be more clear as I move further, but kind of bummer I could not see in the video what result you got for getdog function.

Mine looks like this:


I would like to show all the attributes, ie. name, color, length and diameter

Hi @Kraken

There is two possibilities your first object doesn’t fit completely inside the array because it is too BIG :sauropod: :thinking: or more seriously because you can’t return 4 times in the same function, but you can try to return 4 elements at once :stuck_out_tongue_winking_eye:

return (vibrators[_id].name, vibrators[_id].color,vibrators[_id].length, vibrators[_id].diameter);
2 Likes

Hi @gabba,

Thanks Buddy, will give it a try. That’s exactly what I wanted to know. The syntax for returning several strings. I don’t know if my code was saved in remix or not, started on the new ethereum smart contract programming 101. It seems clearer as Felix goes through the basics more thoroughly in that one. Thanks again!

1 Like

Does anybody else have the problem with the right hand menu(compile, run, analisis, testing etc) in remix being absent?
I get directed to the new version, and when I click the button for access to the old version there is no right hand menu. I don’t seem to find a button for it to view either?

@filip
I’m stuck on inheritance. I wasn’t sure if there was a typo somewhere but after copy+pasting the animalcontract and dogcontract straight off Filip’s github I still can’t deploy my dog contract.
There’s an i with a red warning x next to where contract should be showing but isn’t and it doesn’t tell me why or what is wrong.
Anyone knows what’s up or have experienced the same problem?

Hi Filip and everyone,
I have a question about Payable Functions, specifically when you talk about a refund if we transfer a greater amount of wei.
Is there any way we could see how much is returned anywhere? In the transaction it showing still 10000 wei but nothing that was returned. Do you know what I mean?

Cheers

Hey Chakingo,
I had simular problem. Have you tied changing your version in compile bar to 0.5.1+commit.c8a2cb62.Emscripten.clang ?

Hi. Sorry, I am stuck with this:

while I try to reach: https://remix.ethereum.org/

I don’t understand what I have to do to reach the browser/ballot.sol build tool

@filip Hi Filip
I try to deploy a smart contract on remix but I got the error message "Unable to import “@openzeppelin/contracts/token/ERC20/IERC20.sol: File not found”. Here you can see my import statements:

Do you have an idea what went wrong with my code?

Thank you for your help.
Best regards Henning

1 Like