Learning Truffle

@dan-i hey so i was wondering what could be the issue.

1 Like

So I figured I enter my params in the migrations file:
Capture2

This is what I receive on the terminal when migrating, is this correct?
Capture3

1 Like

Hello! This is regarding the Multisig truffle assignment, I am a bit stuck here. It keeps giving me errors like "unexpected token: ’ [ ’ " , what can I improve on?

2021-04-07 (2)

1 Like

Hi, it’s me again, this time around I can’t compile my MultiSigWallet Contract, it sends out different error messages but here’s the latest I received.

  • Error Message
truffle(develop)> compile

Compiling your contracts...
===========================

<--- Last few GCs --->

[16616:0000017B8C2C67B0]     2703 ms: Scavenge 123.6 (140.4) -> 117.7 (147.9) MB, 11.4 / 0.0 ms  (average mu = 1.000, current mu = 1.000) allocation failure
[16616:0000017B8C2C67B0]     3104 ms: Scavenge 127.3 (152.6) -> 123.9 (155.8) MB, 6.3 / 0.0 ms  (average mu = 1.000, current mu = 1.000) allocation failure


<--- JS stacktrace --->

FATAL ERROR: wasm code commit Allocation failed - process out of memory

truffle(develop)>
  • Here’s my migration file
const MultiSigWallet = artifacts.require("MultiSigWallet");

module.exports = function (deployer, network, accounts[]) {
    var sigRequired = 2;
    deployer.deploy(MultiSigWallet, ['0x6EF694F14D5633eFfE6190eF56BBCDBb6BC7560C',
    '0x2C202FFc76A4E0440a10735d706747a768f7F17d','0xFaA0734ab190D1B5C3eF428f7aedE11Be2b8AE46',
    '0xC4c838CBE714dEAae536DBE11886eBECe53864B7',], sigRequired);
};

Thank you devs!

Hey @Karla

Can you run truffle -v in your terminal and post the result here?

Thanks,
Dani

1 Like

Hey @Javier_Flores

It really does not matter which compiler you are going to use, just pick one 0.7 or higher.
Also you have to keep in mind that the version used needs to be compatibile with all the inherited contracts (for example if you import libraries from Openzeppelin).

Feel free to refer to this guide if you need help to change Truffle version: FAQ - How do change truffle version

If you still face an issue, please post the error message here and I will take a look :slight_smile:

Happy coding,
Dani

1 Like

Sorry @inzhagey I totally missed your question!

npm install -g truffle --force did not work.

This one fails because it does not have the right access to your files.

Run sudo npm i -g truffle

Cheers,
Dani

1 Like

Hey @cecilia

There is a syntax error.

You can either:

deployed.deploy(Wallet, [0x00000000,0x000000000],2);

or

const addresses = [0x000000,0x000000];
const limit = 2;
deployed.deploy(Wallet, addresses, limit);

Cheers,
Dani

Hey @Bripeachy

Check this post Learning Truffle

Let me know if that helps :slight_smile:

Hey @bjamRez

Your code works, you just have to keep in mind that these calls are async so you should use await or promises.

const instance = await Wallet.deployed()
await instance.deposit({value: web3.utils.toWei('1', 'ether') } )
const res = await instance.getWalletBalance()

Now as discussed the number you get back is always a BigNumber, you just have to parse it:

console.log(parseInt(res))

Screenshot 2021-04-08 at 10.53.42

Cheers,
Dani

1 Like

thanks that make it work!

1 Like

It’s telling me:
Error: Truffle is currently using solc 0.5.16, but one or more of your contracts specify “pragma solidity 0.8.0”.
Please update your truffle config or pragma statement(s).
(See https://trufflesuite.com/docs/truffle/reference/configuration#compiler-configuration for information on
configuring Truffle to use a specific solc compiler version.)

what should I do @dan-i

Screen Shot 2021-04-08 at 10.58.17 AM
Screen Shot 2021-04-08 at 10.58.24 AM

He Guys,

I’m having an issue with interacting with the ERC20 contract once the Ownable contract is added. My code below is slightly different from the video as openzeppelin is having an issue with the compiler so this is the current workaround.

//SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
import "../node_modules/@openzeppelin/contracts/token/ERC20/extensions/ERC20Capped.sol";
import "../node_modules/@openzeppelin/contracts/access/Ownable.sol";

contract MyToken is ERC20Capped , Ownable {

    constructor(uint256 initialSupply) ERC20("MyToken", "MKTN") ERC20Capped(10000){
       ERC20._mint(msg.sender, initialSupply);

    } 


}

When I use the terminal I get the following error…

truffle(develop)> compile

Compiling your contracts…

Everything is up to date, there is nothing to compile.

  • Fetching solc version list from solc-bin. Attempt #1

truffle(develop)> let instance = await MyToken.deployed()
undefined
truffle(develop)> instance.owner()
Uncaught:
Error: Returned values aren’t valid, did it run Out of Gas? You might also see this error if you are not using the correct ABI for the contract you are retrieving data from, requesting data from a block number that does not exist, or querying a node which is not fully synced.
at evalmachine.:0:10
at sigintHandlersWrap (node:vm:271:12)
at Script.runInContext (node:vm:139:14)
at runScript (/opt/homebrew/lib/node_modules/truffle/build/webpack:/packages/core/lib/console.js:270:1)
at Console.interpret (/opt/homebrew/lib/node_modules/truffle/build/webpack:/packages/core/lib/console.js:285:1)
at bound (node:domain:416:15)
at REPLServer.runBound [as eval] (node:domain:427:12)
at REPLServer.onLine (node:repl:844:10)
at REPLServer.emit (node:events:369:20)
at REPLServer.emit (node:domain:470:12)
at REPLServer.Interface._onLine (node:readline:418:10)
at REPLServer.Interface._line (node:readline:763:8)
at REPLServer.Interface._ttyWrite (node:readline:1108:14)
at REPLServer.self._ttyWrite (node:repl:936:9)
at ReadStream.onkeypress (node:readline:259:10)
at ReadStream.emit (node:events:369:20)
at ReadStream.emit (node:domain:470:12)
at emitKeys (node:internal/readline/utils:358:14)
at emitKeys.next ()
at ReadStream.onData (node:readline:1242:36) {
hijackedStack: “Error: Returned values aren’t valid, did it run Out of Gas? You might also see this error if you are not using the correct ABI for the contract you are retrieving data from, requesting data from a block number that does not exist, or querying a node which is not fully synced.\n” +
’ at ABICoder.decodeParameters (/opt/homebrew/lib/node_modules/truffle/build/webpack:/node_modules/web3-eth-abi/src/index.js:332:1)\n’ +
’ at Contract._decodeMethodReturn (/opt/homebrew/lib/node_modules/truffle/build/webpack:/node_modules/web3-eth/node_modules/web3-eth-contract/src/index.js:572:1)\n’ +
’ at Method.outputFormatter (/opt/homebrew/lib/node_modules/truffle/build/webpack:/node_modules/web3-eth/node_modules/web3-eth-contract/src/index.js:932:1)\n’ +
’ at Method.formatOutput (/opt/homebrew/lib/node_modules/truffle/build/webpack:/node_modules/web3-eth/node_modules/web3-core-method/src/index.js:169:1)\n’ +
’ at sendTxCallback (/opt/homebrew/lib/node_modules/truffle/build/webpack:/node_modules/web3-eth/node_modules/web3-core-method/src/index.js:640:1)\n’ +
’ at /opt/homebrew/lib/node_modules/truffle/build/webpack:/node_modules/web3/node_modules/web3-core-requestmanager/src/index.js:177:1\n’ +
’ at /opt/homebrew/lib/node_modules/truffle/build/webpack:/packages/provider/wrapper.js:107:1\n’ +
’ at XMLHttpRequest.request.onreadystatechange (/opt/homebrew/lib/node_modules/truffle/build/webpack:/node_modules/web3/node_modules/web3-providers-http/src/index.js:111:1)\n’ +
’ at XMLHttpRequestEventTarget.dispatchEvent (/opt/homebrew/lib/node_modules/truffle/build/webpack:/node_modules/xhr2-cookies/dist/xml-http-request-event-target.js:34:1)\n’ +
’ at XMLHttpRequest.exports.modules.996763.XMLHttpRequest._setReadyState (/opt/homebrew/lib/node_modules/truffle/build/webpack:/node_modules/xhr2-cookies/dist/xml-http-request.js:208:1)\n’ +
’ at XMLHttpRequest.exports.modules.996763.XMLHttpRequest._onHttpResponseEnd (/opt/homebrew/lib/node_modules/truffle/build/webpack:/node_modules/xhr2-cookies/dist/xml-http-request.js:318:1)\n’ +
’ at IncomingMessage. (/opt/homebrew/lib/node_modules/truffle/build/webpack:/node_modules/xhr2-cookies/dist/xml-http-request.js:289:47)\n’ +
’ at IncomingMessage.emit (node:events:381:22)\n’ +
’ at IncomingMessage.emit (node:domain:532:15)\n’ +
’ at endReadableNT (node:internal/streams/readable:1307:12)\n’ +
’ at processTicksAndRejections (node:internal/process/task_queues:81:21)’
}

If anyone could get back to me, that would be great :slight_smile:

Hi @dan-i

It still says the same, it’s written in German though but I will still post it.
I need to say that I can compile in the terminal window only not in VSC.

image

Thanks so much Dani - I forget that we are also using JavaScript with Truffle - thanks again.

I found a solution to my problems, turns out that I just forgot to include

pragma abicoder v2;

at the start :sweat_smile:

Hi Dani, this was working fine but had to close my session on VS Pro and when I re-opened the same file, I could not get the getWalletBallance() call to work again. I am now getting these errors:

truffle(develop)> let res = await instance.getWalletBalance()
Uncaught:
Error: Returned values aren’t valid, did it run Out of Gas? You might also see this error if you are not using the correct ABI for the contract you are retrieving data from, requesting data from a block number that does not exist, or querying a node which is not fully synced.
at evalmachine.:1:18
at evalmachine.:2:49
at sigintHandlersWrap (vm.js:273:12)
at Script.runInContext (vm.js:140:14)
at runScript (C:\Users\benX\AppData\Roaming\npm\node_modules\truffle\build\webpack:\packages\core\lib\console.js:270:1)
at Console.interpret (C:\Users\benX\AppData\Roaming\npm\node_modules\truffle\build\webpack:\packages\core\lib\console.js:285:1)
at bound (domain.js:413:15)
at REPLServer.runBound [as eval] (domain.js:424:12)
at REPLServer.onLine (repl.js:817:10)
at REPLServer.emit (events.js:315:20)
at REPLServer.EventEmitter.emit (domain.js:467:12)
at REPLServer.Interface._onLine (readline.js:337:10)
at REPLServer.Interface._line (readline.js:666:8)
at REPLServer.Interface._ttyWrite (readline.js:1010:14)
at REPLServer.self._ttyWrite (repl.js:907:9)
at ReadStream.onkeypress (readline.js:213:10)
at ReadStream.emit (events.js:315:20)
at ReadStream.EventEmitter.emit (domain.js:467:12)
at emitKeys (internal/readline/utils.js:345:14)
at emitKeys.next () {
hijackedStack: “Error: Returned values aren’t valid, did it run Out of Gas? You might also see this error if you are not using the correct ABI for the contract you are retrieving data from, requesting data from a block number that does not exist, or querying a node which is not fully synced.\n” +
’ at ABICoder.decodeParameters (C:\Users\benX\AppData\Roaming\npm\node_modules\truffle\build\webpack:\node_modules\web3-eth-abi\src\index.js:332:1)\n’ +
’ at Contract._decodeMethodReturn (C:\Users\benX\AppData\Roaming\npm\node_modules\truffle\build\webpack:\node_modules\web3-eth\node_modules\web3-eth-contract\src\index.js:572:1)\n’ +
’ at Method.outputFormatter (C:\Users\benX\AppData\Roaming\npm\node_modules\truffle\build\webpack:\node_modules\web3-eth\node_modules\web3-eth-contract\src\index.js:932:1)\n’ +
’ at Method.formatOutput (C:\Users\benX\AppData\Roaming\npm\node_modules\truffle\build\webpack:\node_modules\web3-eth\node_modules\web3-core-method\src\index.js:169:1)\n’ +
’ at sendTxCallback (C:\Users\benX\AppData\Roaming\npm\node_modules\truffle\build\webpack:\node_modules\web3-eth\node_modules\web3-core-method\src\index.js:640:1)\n’ +
’ at C:\Users\benX\AppData\Roaming\npm\node_modules\truffle\build\webpack:\node_modules\web3\node_modules\web3-core-requestmanager\src\index.js:177:1\n’ +
’ at C:\Users\benX\AppData\Roaming\npm\node_modules\truffle\build\webpack:\packages\provider\wrapper.js:107:1\n’ +
’ at XMLHttpRequest.request.onreadystatechange (C:\Users\benX\AppData\Roaming\npm\node_modules\truffle\build\webpack:\node_modules\web3\node_modules\web3-providers-http\src\index.js:111:1)\n’ +
’ at XMLHttpRequestEventTarget.dispatchEvent (C:\Users\benX\AppData\Roaming\npm\node_modules\truffle\build\webpack:\node_modules\xhr2-cookies\dist\xml-http-request-event-target.js:34:1)\n’ +
’ at XMLHttpRequest.exports.modules.996763.XMLHttpRequest._setReadyState (C:\Users\benX\AppData\Roaming\npm\node_modules\truffle\build\webpack:\node_modules\xhr2-cookies\dist\xml-http-request.js:208:1)\n’ +
’ at XMLHttpRequest.exports.modules.996763.XMLHttpRequest._onHttpResponseEnd (C:\Users\benX\AppData\Roaming\npm\node_modules\truffle\build\webpack:\node_modules\xhr2-cookies\dist\xml-http-request.js:318:1)\n’ +
’ at IncomingMessage. (C:\Users\benX\AppData\Roaming\npm\node_modules\truffle\build\webpack:\node_modules\xhr2-cookies\dist\xml-http-request.js:289:47)\n’ +
’ at IncomingMessage.emit (events.js:327:22)\n’ +
’ at IncomingMessage.EventEmitter.emit (domain.js:529:15)\n’ +
’ at endReadableNT (internal/streams/readable.js:1327:12)\n’ +
’ at processTicksAndRejections (internal/process/task_queues.js:80:21)’

Hi @inzhagey,
I had the same problem and I uncommented version and updated to the version I’m using and it worked.
image

3 Likes

yay it worked, thank you!

1 Like

I’m glad I could help ! :slight_smile:

1 Like