Learning Truffle

This happens sometimes unfortunately.
Have you fixed it?

If not let us know which version of truffle you are using.

Cheers,
Dani

@filip pls can i run trufle on my hp laptopā€¦ive been trying it but getting crazy resultā€¦help me opls

Hey there. Installation worked fine.
I had to upgrade node.js from LTS to the current version first.

Some vulnerabilities reported: 38 vulnerabilities (16 low, 17 moderate, 5 high)

Most are in UUIDā€¦ any idea how I can update that to version 4.

Also running truffle version gets me:

PS C:\Users\rapha> truffle version
Truffle v5.3.10 (core: 5.3.10)
Solidity v0.5.16 (solc-js)
Node v16.3.0
Web3.js v1.3.6

Why shouldnā€™t we use PowerShell? I find it much better than cmdā€¦

Which Ethereum client are you using?

When deploying the MultiSigWallet I figured out how to pass arguments to the constructor.
That would be a nice add to one of the chapters.

What I havenā€™t figured out:
My contract has a getBalance() function.

        function getBalance() public view returns (uint){
            return address(this).balance;
        }

The return looks like this:

BN {
  negative: 0,
  words: [ 56885248, 2993385, 222, <1 empty item> ],
  length: 3,
  red: null
}

I was expecting an integer.

Prior to this i called deposit and sent 1 ether as value:

wallet.deposit({value: web3.utils.toWei('1', 'ether')})
truffle(develop)> wallet.deposit({value: web3.utils.toWei('1', 'ether')})
{
  tx: '0xea38370315bb52be6149f46db6a395e85ac841b2fd280db68c5446cf8d898f74',
  receipt: {
    transactionHash: '0xea38370315bb52be6149f46db6a395e85ac841b2fd280db68c5446cf8d898f74',
    transactionIndex: 0,
    blockHash: '0x826343702d1954ed3bf98550fd64eef937529beae73bb50b42feefcaac277151',
    blockNumber: 5,
    from: '0x4fa345696c9d7b548ed7208eb0abf066f3d09fd2',
    to: '0xa1850bb936ddc884e4168e8715e551c64be98c50',
    gasUsed: 22823,
    cumulativeGasUsed: 22823,
    contractAddress: null,
    logs: [ [Object] ],
    status: true,
    logsBloom: '0x00000000000000000000000000000000400000000000000080000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000080000000000000000000000000080000000000000000000000000100000000400000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000040000000000000000000000008000000',
    rawLogs: [ [Object] ]
  },
  logs: [
    {
      logIndex: 0,
      transactionIndex: 0,
      transactionHash: '0xea38370315bb52be6149f46db6a395e85ac841b2fd280db68c5446cf8d898f74',
      blockHash: '0x826343702d1954ed3bf98550fd64eef937529beae73bb50b42feefcaac277151',
      blockNumber: 5,
      address: '0xA1850bb936DdC884E4168E8715e551C64Be98c50',
      type: 'mined',
      id: 'log_2a20b0b0',
      event: 'depositDone',
      args: [Result]
    }
  ]
}

Any idea how I could output the contracts balance?

Thanks a lot!!

Hi @Phaxsam

Can you elaborate your question?

Hi @raphbaph

All good in your configuration, no need to do anything else.

Have fun coding,
Dani

Hi @raphbaph

Truffle uses bignumber, you can convert it to string to get a human readable version of your result.

Interestingly, this doesnā€™t work.

Check this out:

let result = await wallet.getBalance()
truffle(develop)> let result = await wallet.getBalance()
undefined
truffle(develop)> result
BN {
  negative: 0,
  words: [ 46661632, 5986771, 444, <1 empty item> ],
  length: 3,
  red: null
}
truffle(develop)> result.toNumber()
C:\Users\rapha\AppData\Roaming\npm\node_modules\truffle\build\585.bundled.js:6525
    if (!val) throw new Error(msg || 'Assertion failed');
              ^

Uncaught Error: Number can only safely store up to 53 bits
    at assert (C:\Users\rapha\AppData\Roaming\npm\node_modules\truffle\build\webpack:\node_modules\bn.js\lib\bn.js:6:1)
    at BN.toNumber (C:\Users\rapha\AppData\Roaming\npm\node_modules\truffle\build\webpack:\node_modules\bn.js\lib\bn.js:506:1)
    at evalmachine.<anonymous>
    at sigintHandlersWrap (node:vm:269:12)
    at Script.runInContext (node:vm:137:14)
    at runScript (C:\Users\rapha\AppData\Roaming\npm\node_modules\truffle\build\webpack:\packages\core\lib\console.js:270:1)
    at Console.interpret (C:\Users\rapha\AppData\Roaming\npm\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:849:10)
    at REPLServer.emit (node:events:394:28)
    at REPLServer.emit (node:domain:470:12)
    at REPLServer.Interface._onLine (node:readline:487:10)
    at REPLServer.Interface._line (node:readline:852:8)
    at REPLServer.Interface._ttyWrite (node:readline:1204:14)
    at REPLServer.self._ttyWrite (node:repl:944:9)

But toString() worksā€¦
Something definitely isnā€™t right hereā€¦ Letā€™s say Iā€™d do WebUI for this contract, Iā€™d have a hard time handling balancesā€¦

You can use parseInt(), Number() or toString(), give it a try

Regarding UUIDā€¦ It all works. But having 5 high-impact vulnerabilities isnā€™t really cool. Iā€™ll research how to update this.

Cool, this works! parseInt(result)! Awesome! Thanks a lot!

1 Like

1623857246401475754864120158206

hereā€™s what Iā€™m getting many hours on the installation since but all to no avail

1 Like

@Filip I canā€™t count how many hours used now to find a way of running my truffle yet I canā€™t figure it outā€¦pls help me check the image below to see the result Iā€™m havingā€¦20210616_184541

1 Like

Hi @Phaxsam

These are warnings not errors, nothing be be afraid of.

Cheers,
Dani

I googled the error message and the first link suggests the follow, give it a try and let us know:

  • Run powershell as administrator;
  • Type the command: Set-ExecutionPolicy Unrestricted

Now you should able to use truffle init

Happy coding :slight_smile:

pls I need helpā€¦Iā€™ve been trying to install my mom
install truffle-assertions but it keeps saying file not foundā€¦below is the screenshotā€¦help me check plssā€¦Iā€™m stucked hereIMG-20210620-WA0011

Hi @Phaxsam

The package name seems to be correct npm i truffle-assertions.
I am able to install it.
Npm is telling you that you are facing a connection issue, you should check your connection or try a different one.

Cheers,
Dani

Hello -
Managed to install node.js, but truffle installation process took a long time and seems to have errored. It seems it is a permissions problem, but then on this laptop I have only a single user installed.
see screenshot.
would appreciate your help with this.
Thanks.
Screenshot 2021-06-25 at 17.39.51

Hi @yestome

Run sudo npm i -g truffle

Cheers,
Dani

thanks dan-i - that was very efficient command, truffle now running
(out of curiosity: what do the ā€œiā€ and ā€œ-gā€ flag do?)
yestome