Programming Project - Phase 2

@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

Hi @dan-i
Thank you very much for taking the time and providing feedback.
I did not see this, probably I did set something differently in my Atom editor. I did fix the ABI. Figured out I need to use the ABI of my actual contract not of the proxy. The ABI of the proxy would return “is not a function”.
Unfortunately I still get the same error message in the browser console.
I did try to deposit to the contract and it seems kind of work. The contract (checked on Ropsten Etherscan) has the balance of what I sent.
I did deploy the contracts again and did consol log the addresses of both, the contract and the proxy.
Proxy: 0x880a084927b0A7F07c96a739C0ac439E482a0ab1
Main: 0x3380C3552Be3EBeAD90148c9C1E9d273D03fFA78
There is a connection between the two. When depositing balance to the proxy the internal transaction in the main contract shows up. The actual flip function though seems to have no effect on the main contract, the proxy balance gets increased.
So I did exchange the address in the main.js to check if the main contract works. All functions work as expected. This means the storage contract is fine but on the other hand, there is something wrong with my proxy contract or better to say my front end can not handle the information being returned from the proxy.
Any idea where I am missing the point.
Thank you,
Ralf

@dan-i hi dan this is my test by uniswap tutorial I post it to GitHub please help me how to fix I think it error by version of solidity because on the solidity program 201 I found this error too when I compile and I fix it by change to 0.5.12 and it work for me but on this project it’s doesn’t work.
https://github.com/suppapan/uniswaptestdeploy

Hey @Anonymous

The contract does not compile at all but I don’t get the error message you get.
Can you compile a different project and check if it works?

If you are able to compile a different project, delete the folder node_modules in your uniswap clone.

If it does not work post a screenshot of another project that does not compile.

Cheers,
Dani

Hey @rkindle

I cloned your project.
Flip:

Seems ok.

Get balance:

Seems ok.

I do not have any error in my console.

Just for the sake of testing, can you try with another browser and, if you get the error message, write me the steps to replicate it step by step.

Edit: I played twice and everything was good, also I clicked on “get balance” 15 times and still no error :slight_smile:
Cheers,
Dani

@dan-i i do this uniswap follow this doc and I get this error I will try another project and will screenshot error to you but it always prompt this error
https://uniswap.org/docs/v2/smart-contract-integration/quick-start/

I think this should be sufficient enough to pass. The code may be messy but I will return in the future to tidy things up. I took a long break from coding so I wasn’t sure where I leftoff. I am very anxious to continue learning :wink:
https://github.com/zanjakob/Coin-flip-Provable.git

1 Like

Alright, I am a bit lost right here. I don’t know where the mistake is. I can deploy to kovan testnet (cannot make ropsten work, no matter what I do due to insufficient funds, although lots of test-eth in the wallet)
but the contract seems to be broken now and I can’t find the error(s). can anyone have a look? @dan-i CoinFlipOracleGitHubRepo

Hi @dan-i,
Thank you for taking the time.
I did all my testing so fare with Chrome, did try now additionally with Brave and Edge, but the same picture on all of them.


I am sorry but I have to ask: Witch branch did you use to clone the project?
The following is the one I am working on an giving me troubles:
https://github.com/rkindle/Coinflip/tree/Upgradeable
All works fine if I deploy the contract and use the contract address of the coinflip (main functional) contract. But when attempting to work through the ProxyFlip contract (proxy contract which supposed to redirect all calls to the coinflip contract) the issue arises.
Which contract address did you use for the testing?
If I do interpret the log correctly the contract instance is created, but as soon as a function is called the response of the proxy contract is not valid.
I did search a bit and the error message can appear if the ABI does not match the byte code of the contract. This is the case as the proxy contract does hold fewer functions.But as far as I read the ABI of the functional contract is the correct one to be used.
What confuses me, if I need to call functions from my functional contract, I need the ABI of the functional contract (to know the functions which can be used) but the functions of the Proxy contract are not part of this ABI. Would I not need a second ABI to use the functions of the proxy (for example to change the address to the functional contract). I guess for the upgrading I would need a separate interface to work with only the functions of the proxy an the ABI for it.
What version of web3 are you using? PowerSehll: “npm view web3 version” does return 1.3.4 for me.
The searching into this topic did not bring much further clarity.

Cheers,
Ralf