Learning Truffle

Hi Carlos - put that in and i’m still getting the same message i think im missing something .
I put that command in the node.js.

I download node.js . Then i went to the truffle site hit doc and then hit the truffle smart contracts made sweeter tab. Then the installation tab . Which brings me to the command code . I guess my question would be where do i put the commade code
npm install -g truffle? I put that in the node.js right?

Hello Everyone. I’m having some issues with the migration on the first migration section in Eth 201. I’m not able to migrate 2_hello_migration.js. It shows an error code. I’ve tried restarting the migration and changing the compiler, but can’t seem to get around this error in order to proceed.

Any ideas on how to fix this problem??

Error migration

Error migration 2

1 Like

You should use that command in a console which path is your project folder, you might want to check again the videos to install truffle to check the process :nerd_face:

Carlos Z

The contract file name should be the same has the contract name (hello.sol is not equal to contract Helloworld).

Let us know if that works. :nerd_face:

Carlos Z

Hi Carlos, I was able to find and bring up command prompt , however now i am running into errors when i try to install truffle please find attach the issue.Capture Truffle

I want to play around with some contracts in Truffle which require arguments for their constructors.
Is there a way to send arguments to the constructor from the command line when you migrate the contracts? Or do you have to actually code the arguments in the migration.js file?

1 Like

Hey @Attiss, hope you are great.

Take a look into this old reply, which is related to the constructor arguments and how to assign them in the migration file.

Carlos Z

1 Like

Thanks for sharing this Jake… I was having compiling issues and your sample code showed me how to fix the License issue I was having. Good luck with all your learning.

BMC.

2 Likes

Hi. So I noticed I’m not the only one having issues with installing truffle. However I don’t see much answers. Anyways I get bunch of depracated libraries for truffle and in the end it does install but with 84 vulnerabilities (6 low, 43 moderate, 28 high, 7 critical).

So… probably it’s not installed properly? It seems to be working. But those 28 high and 7 critical makes me to ask if this is installed like it should be.

Annotation 2021-10-27 164751

2 Likes

its normal, not related to your installation, just a warning message that the code somewhere in the package have some vulnerability flags from the dev, nothing to worry about :nerd_face:

Carlos Z

1 Like

I was completing the assignment exercise and decided to try out interacting with the following code via the truffle console:

contract Bank{

   struct Person{
       string name;
       uint age;
   }

   Person[] people;

   function addPerson(string memory _name, uint _age) public {
       Person memory newPerson = Person(_name, _age);
       people.push(newPerson); 
   }

   function getPerson(uint index) public view returns (string memory, uint){
       Person memory personToReturn = people[index];
       return (personToReturn.name, personToReturn.age); 
   }

It is basic code from the Ethereum Smart Contract Programming 101 course. I was able to interact with it successfully via Truffle. However, after adding a new person, instead of getting the name and age back, I get the name and a “big number”. How do I convert the “big number” into a readable number within a struct? Here’s an example of the output I get.

First, I add a new person: Name: Bob, Age: 30----using the following code:
truffle(develop)> instance.addPerson(“Bob”, 30)

That works well. I get the following output when I call the “getPerson” function:
truffle(develop)> instance.getPerson(0)
Result { ‘0’: ‘Bob’, ‘1’: <BN: 1e> }

How do I convert that “Big Number” into a readable “30”?

Thanks!

Hey @CaliCrypto22, hope you are well.

Is not easy to do it directly on the truffle console, further in the unit test you will learn how to convert BN into readable format.

Basically will be to convert the result into .toNumber() or .toString().

Carlos Z

For some reason I can use truffle compile in my command prompt, but when I try to run truffle compile in the native Visual Studio Code terminal it tells me ‘truffle’ is not recognized as an internal or external command.

Any ideas? I have tried the command in both the VS Code command prompt and VS Code powershell.

1 Like

Try use CMD instead (windows command prompt), powershell works nice if you configure the the permissions of it, but cmd is a best option since you will find less issues with the terminal.

https://code.visualstudio.com/docs/editor/integrated-terminal

Carlos Z

Hello everyone.
I am having some issues with the migration portion of the course. May be something small that I did on my end. I’m getting an error code when running the second migration file. I am receiving an error code for some reason. Below is an image of the issue that I’m encountering. Thanks.

Hey @jtb, hope you are well.

Could you please share the migration file of the contract? maybe the error is there.

Carlos Z


@thecil

1 Like

artifacts.require("Helloworld");

The problem is that your contract file name is hello.sol so you have to point the artifact to the same filename (or rename the contract, what you prefer). PD: no need for the .sol, just that the artifact points to the proper file name ("hello").

Note: Please share your future code in the following way so i can easily copy/past for quick reviews :nerd_face:
FAQ - How to post code in the forum

Carlos Z
Carlos Z

Hey,
some feedback about ERC20 Coding lecture, I think it is outdated and needs updating. I believe OpenZeppelin and Truffle has updated their software and repeating what Filip does in the video results in different kind of errors that didnt come up back then. I manually modified OpenZeppelin files to be able to get it to compile & recognise the 1000 tokens inputted in the constructor.

I think because of updates you dont need to do result.toNumber() anymore, instead you will see the number directly from balanceOf now.

1 Like