Looks good! One improvement you could make is not displaying the only owner buttons unless the owner is connected to the dapp.
Great idea! Iâll try that.
Programming Project - Phase 2
working with oracles
Hello yet again,
Iâve completed my version of the betting Dâapp. It successfully works on the Ropsten testnet and communicates with Oracles for randomness. I will be writing tests soon to account for the new betting mechanic. Feel free to look at the source code or clone it and get it working locally for yourself. If you have questions, donât hesitate to ask!
You can find the source code on my Github => https://github.com/santdeleon/coinflip .
Cheers
I love it! Youâre using react, amazing
Hey @filip I have a small question if you wouldnât mind lending some advice. Iâm trying to revise my dâapp after getting halfway through the smart contract security track and realizing my code is super hackable lol.
My issue is this
Whatâs happening is the the Contractâs Balance is actually less than balances[contractAddress]
when this bet()
function finishes running. â Im assuming there is some sort of cost to run the update()
function from within bet()
but iâm not sure what to look for to calculate it. Any thoughts?
Hey @rainbows
Their is a price yes, you can get it with the getPrice() :
https://docs.provable.xyz/#ethereum-best-practices-precalculating-the-query-price
The return of this function is the price for the request + the gas needed for the callback.
About security you can add a require which check if the balance of the contract is equal to the balances[contractAddress] to make sure you are keeping fees for each update calls you can also add an assert at the end .
I m implementing a mechanism to make the user pay for this request to avoid a gap in the contract balance.
@gabba Hmm, interesting. Im a bit confused though. Since getPrice()
takes a string you would need to use it in the actual __callback()
since thats the only place a string is used (in this instance). But, thats not actually correct because you want to get the gas price before the callback is even called. Also, the docs also show a âURLâ which we arenât given?
Alsoo, I wouldnât have getPrice take a bytes32
instead of a string
because that would mean we wouldâve called the callback to get it. Maybe im overthinking thisâŚ
Iâd be interested in seeing how you abstract the gas payment to the user.
provable_getPrice take a string (datasource) which is an enum, you can use Random in our case.
So you call this function inside the flip function then you subtract the price of the request from the amount the player gonna bet. You will keep the fees for your contract.
it should be 0.004 eth at the moment.
"args": {
"0": "4000000000000000",
"price": "4000000000000000",
"length": 1
}
provable_getPrice(âRandomâ);
Run your provable_newRandomDSQuery() one time before , because the first request is free so it will send you back zero
Explained perfectly, now it works perfectly. Youâre a lifesaver Thanks Gabba!
Hello people,
I am unable to use âtruffle consoleâ when Ropsten is set as network.
I get:
truffle-config.js has been set as shown in the video.
Am I missing something?
Thanks a lot!
Can you share your truffle-config.js ?
It seems it tries to run truffle in localhost
host -> 127.0.0.1
port -> 7545
Remove the mnemonicDev and infuraKey before you share it.
You can also look at my previous post in this thread, this truflle config file works.
Hi Gabba thanks for your reply.
Iâve checked your config, however I am still not able to connect.
I might be missing my âmnemonicDevâ, as I am just using the const mnemonic where my seed is stored.
const HDWalletProvider = require("truffle-hdwallet-provider");
const infuraKey = "***";
const fs = require('fs');
const mnemonic = fs.readFileSync(".secret").toString().trim();
module.exports = {
networks: {
development: {
provider: () =>
new HDWalletProvider(mnemonic, "http://127.0.0.1:7545"),
network_id: "*" // Any network (default: none)
},
geth: {
provider: () =>
new HDWalletProvider(mnemonic, "http://127.0.0.1:8545"),
network_id: "*"
},
ropsten: {
provider: () => new HDWalletProvider(mnemonic, `https://ropsten.infura.io/v3/c5f5c354a87f493e83e2ef49a48554fd`),
network_id: 3, // Ropsten's id
gas: 5500000, // Ropsten has a lower block limit than mainnet
confirmations: 2, // # of confs to wait between deployments. (default: 0)
timeoutBlocks: 200, // # of blocks before a deployment times out (minimum/default: 50)
skipDryRun: true // Skip dry run before migrations? (default: false for public nets )
},
// Useful for private networks
private: {
}
},
mocha: {
// timeout: 100000
},
// Configure your compilers
compilers: {
solc: {
version: "0.5.2",
}
}
}
! Update !
- Edited the code above to make it more readable;
- I donât get the connection error anymore after changed the config file following your guidelines, now once I write âtruffle consoleâ just nothing happens.
Oh i get it it fails when you run truffle console not truffle migrate.
Try to run
truffle console --network ropsten
Edit: When you deploy also use
truffle deploy --network ropsten
Hey Gabba,
I will take some time to get what I am doing wrong. I will update this post once I find the solution
I use @truffle/hdwallet-provider as the other one has been deprecated.
You can try the new package @truffle/hdwallet-provider.
It seems that your error is related to your infuraKey and your .secret file
Hello people,
I was able to connect to ropsten by creating a freshly new folder, pasting the contracts in it and deploying.
Then I added the provable api. sol to the project folder and from that moment on the connection to ropsten is failing again. I am able to deploy all the project that do not have the provable api in it.
Although it does not really makes too much sense to me, I am quite sure that is the issue.
I got the api from here: https://github.com/provable-things/ethereum-api/blob/master/provableAPI_0.5.sol
Is that link the one you used too?
Took me two days but I am seeing the light at the end of the tunnel
Here a video for you @gabba
I do show that the contract is deployed in truffle but then fails when import provable api:
Yo i opened i pull request on your repo it works now.
https://github.com/dani69654/Test/pull/1
The few steps:
rm -rf node_modules
rm -rf build/contracts/
npm install -g
n 11.12.0
truffle version
Truffle v5.1.0-next.1 (core: 5.1.0-next.1)
Solidity - 0.5.12 (solc-js)
Node v11.12.0
Web3.js v1.2.1
I changed you contract name for CoinFlip.sol (before coinFlip.sol) because in your migration you called
const CoinFlip = artifacts.require(âCoinFlipâ);
btw i changed it for
const CoinFlip = artifacts.require("./CoinFlip.sol");
I change the compiler version for :
compilers: {
solc: {
version: "0.5.12", // Fetch exact version from solc-bin (default: truffle's version)
}
}
And change the version in all your files. Then
truffle migrate --reset --network ropsten --verbose-rpc
truffle console --network ropsten --verbose-rpc
I also install âweb3â: â^1.0.0-beta.34â because i remember that i had issues with the last version.
i maybe have forgotten few things because i was doing something else in the same time.
But if you try my pull request it will works.
Just rm -rf you build/contracts and node_modules before.
Pm me if you still have issues
You were, of course, right. Downgrading the Node to v11.12.0 solved.
For the others, if you need to download node 11.12.0 (https://nodejs.org/download/release/v11.12.0/)
Thanks a lot man
@filip give a medal to this guy please