Programming Project - Phase 2

Am stuck here. am getting

Data location can only be specified for array, struct or mapping types, but “memory” was given. function __callback(bytes32 _queryId, string memory _result, bytes32 memory _proof) public{ ^-------------------^

function that throws the error

function __callback(bytes32 _queryId, string memory _result, bytes32 memory _proof) public{
require(msg.sender == provable_cbAddress());

    uint256 randomNumber = uint256(keccak256(abi.encodePacked(_result))) % 100;
    lastedNumber = randomNumber;
    emit generatedRandomNumber(randomNumber);
}

Hey @chim4us

bytes32 memory _proof this should be bytes memory _proof if I am not wrong.
Give it a try.

Cheers,
Dani

For the second stage, I created a folder is the same repository: https://github.com/BogdanStirbat/double-or-nothing/tree/master/oracle-version/smart-contract

I added a screenshot:

1 Like

I found this problem and try to find out how to fix in google and I can’t fix its anyone can help me.

truffle compile

Compiling your contracts...
===========================
Error: TypeError: soljson.Pointer_stringify is not a function
    at Object.compile (/usr/local/lib/node_modules/truffle/build/webpack:/packages/workflow-compile/legacy/index.js:72:1)
Truffle v5.0.42 (core: 5.0.42)
Node v10.22.0

Here is my work
https://github.com/Aoi020608/eth_CoinFlip

Hi @Anonymous

Please follow this faq to downgrade nodeJS and try again: FAQ - How to downgrade Node.Js

Regards,
Dani

Good day! Here is the github link to my project: https://github.com/jlthcrypto/coin-flip

Could definitely use some UI/UX improvements and other best practices regarding smart contract security. Looking forward to update when I get to those courses!

Here are some screenshots:

1 Like

Hi @dan-i

Here is my 2_Deploy_coinflip.js file contents :point_down:

const Coinflip = artifacts.require("Coinflip");

module.exports = function(deployer,network,accounts) {
  deployer.deploy(Coinflip).then(function(instance){
    instance.fundContract({value : web3.utils.toWei("1", "ether"), from : accounts[0]}).then(function(){
      console.log("The Contract successfully got funded with 1 ether from Owner address: " + accounts[0]);
      console.log("The Contract address is :" + Coinflip.address);
    }).catch(function(err){
      console.log("The contract couldn't get funded " + err);
    });
  }).catch(function(err){
    console.log("Failed to deploy ! ");
  });
};


Thanks and Regards

su.kal Crypto

@dan-i I have downgrade node version but it don’t work

 truffle compile

Compiling your contracts...
===========================
Error: TypeError: soljson.Pointer_stringify is not a function
    at Object.compile (/usr/local/lib/node_modules/truffle/build/webpack:/packages/workflow-compile/legacy/index.js:72:1)
    at process._tickCallback (internal/process/next_tick.js:68:7)
Truffle v5.0.42 (core: 5.0.42)
Node v10.21.0

@dan-i @filip I had concluded the smart contract security course and used the information to revisit my implementation of the coin flip contract. The contract was possible to compile and deploy to ropsten test net
(Proxy Contract Address: 0x8bEa7B0a7eA6E4a2eB6DC0e3300Bb968cc9FD22c)
The issue I am having is my front end would return with an error on each request sent to the contract. This example shows the message received on a simple Balance value request but looks similar if I attempt the actual flip function.


I did use the ABI from the proxy contract.
I would highly appreciate a hint in which direction I should check to resolve this
This is the git hub branche I am working on: https://github.com/rkindle/Coinflip/tree/Upgradeable
Thank you,
Ralf

Hi @Su.kal.Crypto

Run truffle migrate --reset --network Ropsten.

Regards,
Dani

Hi @Anonymous

Seems to be an issue in the truffle pkg installed.
In your terminal run: sudo npm uninstall -g truffle

Now run sudo npm install -g truffle (it’s ok if you receive a ridiculous amount of warnings during the installation).

Then try again.

Cheers,
Dani

Hey @rkindle

I just checked you abi and I see an error, the compiler helps you a lot in these cases.
The first hint you have is the wrong indentation, the column should be closed correctly but is not:

Also the compiler is telling your that something is missing with the red line under the bracket.

Fix your abi and try again :slight_smile:

Keep me posted,
Dani

@dan-i
it’s doesn’t work too.

truffle compile

Compiling your contracts...
===========================
Error: TypeError: soljson.Pointer_stringify is not a function
    at Object.compile (/usr/local/lib/node_modules/truffle/build/webpack:/packages/workflow-compile/legacy/index.js:72:1)
Truffle v5.0.42 (core: 5.0.42)
Node v10.21.0

@dan-i

hello,

I finally finished my projects :slight_smile:

this is the project made with ganache: https://github.com/enricofabris/COIN_CONTRACT-GANACHE

this is the project made with provable oracle and ropsten: https://github.com/enricofabris/COIN_CONTRACT—ORACLE—ROPSTEN

I tried both of them and they seem to work.
Could you please let me know some feedbak? :slight_smile:

besides I was able to use the test only with the first project because in the course it is shown to use the test through console.
But in the second project when we use ropsten how can we do the test of the contract?

thanks :slight_smile:

Thanks @dan-i

I was able to access the New Contract Address.
But Now i am getting this below issue :point_down:

Can you please look up at my code on Github and advise, because i believe the Code is right (In fact initially i couldn’t understand much o i cheated a lil bit and copied your code only and later i tried to understand it by googling it and found it to be correct and explanatory for myself, and now i am unable to wrap my head around where exactly the fault lies ??

https://github.com/Suveett/CoinFlip-Phase-2.git

Thanks, I shall be highly grateful

also, Dani , whats the role of this Ropsten end point :point_down:

https://ropsten.infura.io/v3/1abdd5862c3e43139b7bcccc9a1401b0

as Filip didn’t explain anything about this endpoints in his video?

Even I am unable to interact on this webpage with my Metamask ( I have checked Metamask account is same as before and is currently on the Ropsten Network)

Please Help :pray:

Su.Kal Crypto

1 Like

UPDATE: I managed to deploy to the Kovan Testnet. After doing lots of research I figure that ropsten has some issues at the moment, probably with the block limit. But what do I know, haha. So if you run into this issue, try to use kovan instead. In the truffle-config.js you can add kovan like this:

kovanconfig

kovan: {
provider: () => new HDWalletProvider(mnemonic, https://kovan.infura.io/v3/InfuraProjectIDHere),
network_id: 42, // Ropsten’s id
gas: 12487794, // 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 )
},

OLD:
Started Phase 2, although my ETH account on ropsten holds 6 ETH I still get the Insufficient Gas Error. I tried to change things in the truffle-config.js but with no success so far. Anybody any solutions?

InsufficientGasError

1_initial_migration.js

Deploying ‘Migrations’

Error: *** Deployment Failed ***

“Migrations” – insufficient funds for gas * price + value.

at C:\Users\sound\AppData\Roaming\npm\node_modules\truffle\build\webpack:\packages\deployer\src\deployment.js:365:1
at processTicksAndRejections (internal/process/task_queues.js:93:5)
at Migration._deploy (C:\Users\sound\AppData\Roaming\npm\node_modules\truffle\build\webpack:\packages\migrate\Migration.js:68:1)
at Migration._load (C:\Users\sound\AppData\Roaming\npm\node_modules\truffle\build\webpack:\packages\migrate\Migration.js:55:1)
at Migration.run (C:\Users\sound\AppData\Roaming\npm\node_modules\truffle\build\webpack:\packages\migrate\Migration.js:171:1)
at Object.runMigrations (C:\Users\sound\AppData\Roaming\npm\node_modules\truffle\build\webpack:\packages\migrate\index.js:150:1)
at Object.runFrom (C:\Users\sound\AppData\Roaming\npm\node_modules\truffle\build\webpack:\packages\migrate\index.js:110:1)
at Object.runAll (C:\Users\sound\AppData\Roaming\npm\node_modules\truffle\build\webpack:\packages\migrate\index.js:114:1)
at Object.run (C:\Users\sound\AppData\Roaming\npm\node_modules\truffle\build\webpack:\packages\migrate\index.js:79:1)
at runMigrations (C:\Users\sound\AppData\Roaming\npm\node_modules\truffle\build\webpack:\packages\core\lib\commands\migrate.js:262:1)
at Object.run (C:\Users\sound\AppData\Roaming\npm\node_modules\truffle\build\webpack:\packages\core\lib\commands\migrate.js:227:1)
at Command.run (C:\Users\sound\AppData\Roaming\npm\node_modules\truffle\build\webpack:\packages\core\lib\command.js:136:1)

Truffle v5.1.67 (core: 5.1.67)
Node v14.15.5

truffle-config.js

/**

  • Use this file to configure your truffle project. It’s seeded with some
  • common settings for different networks and features like migrations,
  • compilation and testing. Uncomment the ones you need or modify
  • them to suit your project as necessary.
  • More information about configuration can be found at:
  • trufflesuite.com/docs/advanced/configuration
  • To deploy via Infura you’ll need a wallet provider (like @truffle/hdwallet-provider)
  • to sign your transactions before they’re sent to a remote public node. Infura accounts
  • are available for free at: infura.io/register.
  • You’ll also need a mnemonic - the twelve word phrase the wallet uses to generate
  • public/private key pairs. If you’re publishing your code to GitHub make sure you load this
  • phrase from a file you’ve .gitignored so it doesn’t accidentally become public.

*/

const HDWalletProvider = require(’@truffle/hdwallet-provider’);
const infuraKey = “XXXX”;
//
const fs = require(‘fs’);
const mnemonic = fs.readFileSync(".secret").toString().trim();

module.exports = {
/**

  • Networks define how you connect to your ethereum client and let you set the
  • defaults web3 uses to send transactions. If you don’t specify one truffle
  • will spin up a development blockchain for you on port 9545 when you
  • run develop or test. You can ask a truffle command to use a specific
  • network from the command line, e.g
  • $ truffle test --network
    */

networks: {
// Useful for testing. The development name is special - truffle uses it by default
// if it’s defined here and no other network is specified at the command line.
// You should run a client (like ganache-cli, geth or parity) in a separate terminal
// tab if you use this network and you must also set the host, port and network_id
// options below to some value.
//
ganache: {
host: “127.0.0.1”, // Localhost (default: none)
port: 7545, // Standard Ethereum port (default: none)
network_id: “5777”, // Any network (default: none)
},
// Another network with more advanced options…
// advanced: {
// port: 8777, // Custom port
// network_id: 1342, // Custom network
gas: 85000, // Gas sent with each transaction (default: ~6700000)
gasPrice: 20000000, // 20 gwei (in wei) (default: 100 gwei)
// from: , // Account to send txs from (default: accounts[0])
// websocket: true // Enable EventEmitter interface for web3 (default: false)
// },
// Useful for deploying to a public network.
// NB: It’s important to wrap the provider as a function.
ropsten: {
provider: () => new HDWalletProvider(mnemonic, https://ropsten.infura.io/v3/XXXX),
network_id: 3, // Ropsten’s id
gas: 3000000, // 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: {
// provider: () => new HDWalletProvider(mnemonic, https://network.io),
// network_id: 2111, // This network is yours, in the cloud.
// production: true // Treats this network as if it was a public net. (default: false)
// }
},

// Set default mocha options here, use special reporters etc.
mocha: {
// timeout: 100000
},

// Configure your compilers
compilers: {
solc: {
version: “0.5.16”, // Fetch exact version from solc-bin (default: truffle’s version)
// docker: true, // Use “0.5.1” you’ve installed locally with docker (default: false)
// settings: { // See the solidity docs for advice about optimization and evmVersion
// optimizer: {
// enabled: false,
// runs: 200
// },
// evmVersion: “byzantium”
// }
}
}
};

@Su.kal.Crypto

The endpoint is refering to the config as you can see in the picture. So make sure in your truffle-config.js provider is set to ropsten.infura. The project ID stays the same, wether endpoint is mainnet or ropsten…

Hi @Anonymous

Please push your project to GitHub and give me the link.
I want to deploy locally and see if I get the same error.

Regards,
Dani

Ciao @enrico

I am going to focus on your oracle project as I am sure your pseudo-randomness is correct :slight_smile:
Few suggestions:

  • A smart contract should not care too much about the frontend.
function checkOwner() public returns(uint){         
       if(msg.sender == owner){
       hide = 1;
       }
       else {
       hide = 0;
       }

       return hide;
    }

If I am not wrong, this function is there so that you can hide/show elements in your HTML (document.getElementById("hide").style.display="block";).
This should not be done.
You can obtain the same result in a much more elegant way (actually more than one):

Your variable owner is public address public owner; so web3 can easily retrieve and use it (look for how to do this), another way can be to have a function getOwner() that returns owner.
Then you can compare address[0] (in JS) and check if it matches the owner returned by the smart contract.

As a rule, the only time your contract should care of your front end is when you emit events.
Events are extremely important both for your and other Dapps that want to use your contract data.

  • Avoid arrays and loops as much as you can.

Although arrays are sometimes really helpful, Solidity does not really like them, keep in mind that each operation (such as iterating an array) costs gas.
Arrays and loops should be used only when they are strictly necessary.
Imagine what can happen if you have a endless loop :heavy_dollar_sign:
Are you sure you cannot obtain the same results by using mappings?
Mappings are the most powerful tool you have in Solidity, use them as much as you can.

Except for these two things the logic works so well done.
I am also happy to see that you understood how Solidity works, now that you have a broad overview of this programming language do not stop and keep studying and learning as much as you can.

Do not forget the smart contract security course, in my opinion the most interesting one. Do not skip it :smiley:

Well done!
Dani

1 Like