I got it working. Thanks for the help
Hello @dan-i @gabba i looked through forums for days and i did not find solution to my problem.
Seams like i got some import error after adding SafeMath functionality,
https://github.com/p4perclip/CoinToss
Truffle v5.1.5 (core: 5.1.5)
Solidity - 0.5.12 (solc-js)
Node v10.12.0
Web3.js v1.2.1
truffle migrate --network ropsten --reset
Compiling your contracts...
===========================
Error: Error: Could not find
import from any sources; imported from /home/bipp/CoinToss/CoinTossTest/contracts/CoinToss.sol
at Object.compile (/home/bipp/.nvm/versions/node/v10.12.0/lib/node_modules/truffle/build/webpack:/packages/workflow-compile/legacy/index.js:80:1)
Truffle v5.1.5 (core: 5.1.5)
Node v10.12.0
Hey, @Lukasz
I do see in your code, it seems you imported it correctly, and applied it with Using SafeMath in the .sol contract. However, when I used it I also had to link to the SafeMath() in the migration file…
My migration file for CoinFlip.sol and the CoinFlip contract.
const CoinFlip = artifacts.require("CoinFlip");
const SafeMath = artifacts.require("SafeMath");
module.exports = function(deployer) {
deployer.deploy(SafeMath);
deployer.link(SafeMath, CoinFlip);
deployer.deploy(CoinFlip);
};
I hope this helps.
Finally! It has been a lot of work but an awesome path to greater knowledge. Thank you to IvanOnTech academy and the members who have helped a lot to get to this point.
Please take a look at my finished Dapp. I hope it provides a clean and easy to use experience. Please let me know what you think.
To use this app, run your http.server (command: “python -m http.server”) in the “Front End” directory. Then use your web browser to go to localhost:8000. You can download the files here: https://github.com/CrazyCanadia/Coin-Flip-Dapp---IvanOnTech-SC201
Any and all feedback is welcome And again, thank you to the community, @gabba, @dan-i, and many others. I have been inspired along the way and this course has really let me see some of the opportunity that exists ahead.
Thanks for suggestion @CrazyCanadia, unfortunately after adding SafeMath to my migration file im still getting error
Compiling your contracts...
===========================
Error: Error: Could not find
import from any sources; imported from /home/bipp/CoinToss/CoinTossTest/contracts/CoinToss.sol
at Object.compile (/home/bipp/.nvm/versions/node/v10.12.0/lib/node_modules/truffle/build/webpack:/packages/workflow-compile/legacy/index.js:80:1)
Truffle v5.1.5 (core: 5.1.5)
Node v10.12.0
What else could i do to make it work?
In the oracle code lecture on the academy there is the random example contract in remix.
I have taken it and deployed it on the ropsten testnet.
But how do I interact with the deployed contract in the truffle console?
I was able to get the latestNumber integer from the console by using:
truffle console --network ropsten
rn = await.RandomExample.deployed()
rn.latestNumber()
But how do I call the update function in the truffle console. The command line below does not seem to work.
rn.update({value: web3.utils.toWei(“0.01”, “ether”)})
I just took another quick look at your github… if it is up to date… it looks like you are missing ‘;’ after most of your import statements…
Hopefully, that does it. Good luck!
My github repo
After few days of trial and error, finally getting the contract and the dapp working:
Placing a bet:
After the bet was placed, showed a notification and waiting the callback from oracle:
Show the result of the bet:
Withdraw funds from contract:
Thank you Filip for a great course! looking forward for your other courses in the academy.
Hey @Lukasz
Add safemath to migration is not the right way.
As @CrazyCanadia correctly said, you are missing ;
when importing projects.
Double check and let us know,
Dani
Hey @Jian_Hao_Wei !
truffle console --network ropsten
rn = await.RandomExample.deployed()
rn.latestNumber()
Seems all good except for rn = await.RandomExample.deployed()
, remove the dot between await and RandomExample.
Once done just print the content of rn.
Let me know
Dani
Hello @dan-i, semicolons and brackets are now in place and i’ve reversed my migration file to the previous state, now my error looks like this :
Compiling your contracts...
===========================
Error: Error: Could not find __Truffle__NotFound.sol from any sources; imported from /home/bipp/CoinToss/CoinTossTest/contracts/SafeMath.sol
at Object.compile (/home/bipp/.nvm/versions/node/v10.12.0/lib/node_modules/truffle/build/webpack:/packages/workflow-compile/legacy/index.js:80:1)
Truffle v5.1.5 (core: 5.1.5)
Node v10.12.0
Hey @dan-i ,
I still does not work. See the result below.
truffle(ropsten)> rn = await RandomExample.deployed()
undefined
truffle(ropsten)> rn
TruffleContract {
constructor: [Function: TruffleContract] {
_constructorMethods: {
setProvider: [Function: setProvider],
new: [Function: new],
at: [AsyncFunction: at],
deployed: [AsyncFunction: deployed],
defaults: [Function: defaults],
...
truffle(ropsten)> rn.latestNumber()
BN { negative: 0, words: [ 15, <1 empty item> ], length: 1, red: null }
truffle(ropsten)> rn.update({value: web3.utils.toWei("0.01","ether")})
Uncaught TypeError: Cannot read property 'address' of undefined
at end (C:\...\CoinFlip-Dapp\project\node_modules\@trufflesuite\web3-provider-engine\index.js:217:5)
at C:\...\CoinFlip-Dapp\project\node_modules\async\internal\doLimit.js:9:16
at eachLimit (C:\...\CoinFlip-Dapp\project\node_modules\async\eachLimit.js:43:36)
at C:\...\CoinFlip-Dapp\project\node_modules\async\internal\eachOfLimit.js:71:9
at replenish (C:\...\CoinFlip-Dapp\project\node_modules\async\internal\eachOfLimit.js:61:25)
at C:\...\CoinFlip-Dapp\project\node_modules\async\internal\once.js:12:16
at C:\...\CoinFlip-Dapp\project\node_modules\@trufflesuite\web3-provider-engine\index.js:240:9
at C:\...\CoinFlip-Dapp\project\node_modules\async\internal\parallel.js:36:13
at C:\...\CoinFlip-Dapp\project\node_modules\async\internal\onlyOnce.js:12:16
at iterateeCallback (C:\...\CoinFlip-Dapp\project\node_modules\async\internal\eachOfLimit.js:48:24)
at C:\...\CoinFlip-Dapp\project\node_modules\async\internal\once.js:12:16
at C:\...\CoinFlip-Dapp\project\node_modules\async\internal\parallel.js:39:9
at C:\...\CoinFlip-Dapp\project\node_modules\@trufflesuite\web3-provider-engine\subproviders\hooked-wallet.js:653:5
at C:\...\CoinFlip-Dapp\project\node_modules\async\internal\onlyOnce.js:12:16
at next (C:\...\CoinFlip-Dapp\project\node_modules\async\waterfall.js:23:9)
at nextTask (C:\...\CoinFlip-Dapp\project\node_modules\async\waterfall.js:16:14)
at HookedWalletSubprovider.signTransaction (C:\...\CoinFlip-Dapp\project\node_modules\@truffle\hdwallet-provider\src\index.ts:150:22)
at new Transaction (C:\...\CoinFlip-Dapp\project\node_modules\ethereumjs-tx\es5\index.js:59:16)
at new TruffleContract (C:\...\AppData\Roaming\npm\node_modules\truffle\build\webpack:\packages\contract\lib\contract\constructorMethods.js:195:1)
at TruffleContract.Contract (C:\...\AppData\Roaming\npm\node_modules\truffle\build\webpack:\packages\contract\lib\contract.js:33:1)
I get the error that it cannot read the property address of undefined.
I think the problem lies that it cannot find the address of my metamask accounts.
But how do i get my metamask account into truffle?
truffle(ropsten)> rn.update({value: web3.utils.toWei("0.01","ether"), from: ???})
@dan-i i ve got some red warnings about missing files in node modules folder, is that because of a update yesterday?
https://github.com/MetaMask/metamask-extension/issues/8077
Also i have a problem with "Error: *** Deployment Failed ***
“Migrations” – insufficient funds for gas * price + value."
And i have a enough testnet eth, and i am on ropsten network. Any idea what could also cause this issue?
Hey @Lukasz
Your file SafeMath.sol
is missing the closing }
at the bottom of the contract.
Once added the error is fixed.
There are other errors but these are related to your code
Give it a look.
Cheers,
Dani
Hey @Jian_Hao_Wei
It works
truffle(ropsten)> rn = await RandomExample.deployed()
undefined
truffle(ropsten)> rn
TruffleContract {
constructor: [Function: TruffleContract] {
_constructorMethods: {
setProvider: [Function: setProvider],
new: [Function: new],
at: [AsyncFunction: at],
deployed: [AsyncFunction: deployed],
defaults: [Function: defaults],
...
Add await before calling the method tawait rn.latestNumber()
Keep me posted!
Dani
Hey @Spartak
Are you sending Ether when migrating the project?
If yes how many?
What’s the balance of your wallet?
Cheers,
Dani
Thank you very much, SafeMath.sol was copied as it is from Openzepplin, from now i will check all files thoughtfully
Cheers ^^
Hey @dan-i,
The await rn.latestNumber()
gives me the same result as rn.latestNumber()
, which is the number 15 and this is correct.
But I still get the error when I use the command await rn.update({value: web3.utils.toWei("0.01","ether")})
. See result below.
I still get the error that it cannot read the property address of undefined.
I think the problem lies that it cannot find the address of my metamask accounts.
But how do i get my metamask account into truffle?
await rn.latestNumber()
BN { negative: 0, words: [ 15, <1 empty item> ], length: 1, red: null }
truffle(ropsten)> await rn.update({value: web3.utils.toWei("0.01","ether")})
Uncaught TypeError: Cannot read property 'address' of undefined
at end (C:\...\CoinFlip-Dapp\project\node_modules\@trufflesuite\web3-provider-engine\index.js:217:5)
at C:\...\CoinFlip-Dapp\project\node_modules\async\internal\doLimit.js:9:16
at eachLimit (C:\...\CoinFlip-Dapp\project\node_modules\async\eachLimit.js:43:36)
at C:\...\CoinFlip-Dapp\project\node_modules\async\internal\eachOfLimit.js:71:9
at replenish (C:\...\CoinFlip-Dapp\project\node_modules\async\internal\eachOfLimit.js:61:25)
at C:\...\CoinFlip-Dapp\project\node_modules\async\internal\once.js:12:16
at C:\...\CoinFlip-Dapp\project\node_modules\@trufflesuite\web3-provider-engine\index.js:240:9
at C:\...\CoinFlip-Dapp\project\node_modules\async\internal\parallel.js:36:13
at C:\...\CoinFlip-Dapp\project\node_modules\async\internal\onlyOnce.js:12:16
at iterateeCallback (C:\...\CoinFlip-Dapp\project\node_modules\async\internal\eachOfLimit.js:48:24)
at C:\...\CoinFlip-Dapp\project\node_modules\async\internal\once.js:12:16
at C:\...\CoinFlip-Dapp\project\node_modules\async\internal\parallel.js:39:9
at C:\...\CoinFlip-Dapp\project\node_modules\@trufflesuite\web3-provider-engine\subproviders\hooked-wallet.js:653:5
at C:\...\CoinFlip-Dapp\project\node_modules\async\internal\onlyOnce.js:12:16
at next (C:\...\CoinFlip-Dapp\project\node_modules\async\waterfall.js:23:9)
at nextTask (C:\...\CoinFlip-Dapp\project\node_modules\async\waterfall.js:16:14)
at HookedWalletSubprovider.signTransaction (C:\...\CoinFlip-Dapp\project\node_modules\@truffle\hdwallet-provider\src\index.ts:150:22)
at new Transaction (C:\...\CoinFlip-Dapp\project\node_modules\ethereumjs-tx\es5\index.js:59:16)
at new TruffleContract (C:\...\AppData\Roaming\npm\node_modules\truffle\build\webpack:\packages\contract\lib\contract\constructorMethods.js:195:1)
at TruffleContract.Contract (C:\...\AppData\Roaming\npm\node_modules\truffle\build\webpack:\packages\contract\lib\contract.js:33:1)
I’m having the same exact issue as you Uncaught TypeError : Cannot read property ‘events’ of undefined, it’s also doing my head in, I can’t logically grasp why this is throwing an error:
Did you manage to figure it out yet?
EDIT:
I just realised the event needs to be inside a function in order for events to be recognised and contractInstance isn’t recognised outside of the window.ethereum.enable() for me.
I thought I had as I put the event listener into a different place and it started recognising it but it doesn’t work on the other games so I don’t know. I made a DApp wih 3 different games: coin flip, dice roll and high card draw…I have only gotten it working on the coin flip (obviously by fluke as I replicated what I did on the dice roll with no luck).
I have put it on the back burner for now though
Perhaps @dan-i can shed some light on this for the both of us
Good luck