Learning Truffle

Hey @jahh, hope you are ok.

Would be great if you can share an screenshot about the error that the console shows to you, it will help us to identify how to solve your issue :face_with_monocle:

Carlos Z

hey there,
im trying to install truffle and im having some issues,
image
this is what i see after i try to install.

Note:

  • i have installed node,js(not latest vs) and npm

Hey @Bogdan_Manzar, hope you are well.

The “vulnerabilities” warning message is just that, a warning message, you could either try to solve them (by running npm audit fix, which i do not advice for your case) or just ignore them (also the “WARN”, they are warning messages about an error in the module that you are downloading, but will not affect the procedure of it).

Carlos Z

hey thanks for your time,

I tried solving the warns but it only ended up with me getting new ones
image
maybe there is another way to install truffle?

  • Bogdan

(edit) if you want to see the picture right click and click open image in new tab

The only way to install truffle is through npm, but you could try to run the command truffle version, which will return the version of all truffle modules, and its returned, means that your truffle should be installed properly and ready to go.

Here is mine, if you get a message like this one (versions could be different, but does not matter) means that your truffle package should be working properly:
image

Carlos Z

1 Like

Hey everyone,

Regarding the first migration lesson,

I’m getting errors when I am trying to migrate the hello file,
this is the full command prompt message:
image
the helloworld contract does not appear under the build/contracts after this.

I’m unsure if this is just something that is from a new update or something but if you know how to fix this or have any ideas why this happened plz lmk,
thanks for your time
-Bogdan Manzar :smiley:

1 Like

Hey there @thecil,

I’ve got the truffle download down, now I am having a little more trouble with the migrations, when you have some time do you mind taking a quick look?

thanks!

  • Bogdan Manzar :smiley:
1 Like

Hey @Bogdan_Manzar, hope you are well.

Based on your console message, you have 2 errors:

First, your hello contract is apparently missing the solidity version.
Second is on your migration file, which apparently have invalid parameters.

Please share your contract and migration file in the following way:
FAQ - How to post code in the forum

Carlos Z

In my vs code it does tell me that I am not writing the version correctly

pragma solidity 0.8.7;

contract helloworld{
    function hello()pure public returns(string memory){
        return"Hello world";
    }
}

the pragma word is underlined in yellow and it is asking about an SPDX license.
Migrations file:

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

module.exports = function (deployer) {
  deployer.deploy(helloworld);
};

What is the name of your contract? Any case, the file should start with capital letter “Hello.sol” for example, and the contract name also “Helloworld”.

Then your migration file must import it has:
const helloworld = artifacts.require("Helloworld");

Carlos Z

i just changed the name to capital and it is the same, when i try to use terminal in vs code it does not recognize the command npm or truffle
image
although in cdm it worked to use truffle develope

1 Like

hello filip , when im installing truffle im getting erros please suggest .

1 Like

I’m on the Truffle Assignment and I’m trying to compile the Wallet.sol contract and I keep on getting the same error:

> Compilation warnings encountered:

    project:/contracts/WalletContract.sol:3:1: Warning: Experimental features are turned on. Do not use experimental features on live deployments.
pragma experimental ABIEncoderV2;
^-------------------------------^

project:/contracts/WalletContract.sol:37:5: SyntaxError: No visibility specified. Did you intend to add "public"?
    constructor(address[] memory _owners, uint _limit) {
    ^ (Relevant source part starts here and spans across multiple lines).

Compilation failed. See above.
Truffle v5.4.7 (core: 5.4.7)
Node v16.9.1

Here is the contract code:

// SPDX-License-Identifier: MIT
pragma solidity >=0.4.22 <0.9.0;
pragma experimental ABIEncoderV2;

contract Wallet {
    address[] public owners;
    uint limit;
    
    struct Transfer{
        uint amount;
        address payable receiver;
        uint approvals;
        bool hasBeenSent;
        uint id;
    }
    
    event TransferRequestCreated(uint _id, uint _amount, address _initiator, address _receiver);
    event ApprovalReceived(uint _id, uint _approvals, address _approver);
    event TransferApproved(uint _id);

    Transfer[] transferRequests;
    
    mapping(address => mapping(uint => bool)) approvals;
    
    //Should only allow people in the owners list to continue the execution.
    modifier onlyOwners(){
        bool owner = false;
        for(uint i=0; i<owners.length;i++){
            if(owners[i] == msg.sender){
                owner = true;
            }
        }
        require(owner == true);
        _;
    }
    //Should initialize the owners list and the limit 
    constructor(address[] memory _owners, uint _limit) {
        owners = _owners;
        limit = _limit;
    }
    
    //Empty function
    function deposit() public payable {}
    
    //Create an instance of the Transfer struct and add it to the transferRequests array
    function createTransfer(uint _amount, address payable _receiver) public onlyOwners {
        emit TransferRequestCreated(transferRequests.length, _amount, msg.sender, _receiver);
        transferRequests.push(
            Transfer(_amount, _receiver, 0, false, transferRequests.length)
        );
        
    }
    
    //Set your approval for one of the transfer requests.
    //Need to update the Transfer object.
    //Need to update the mapping to record the approval for the msg.sender.
    //When the amount of approvals for a transfer has reached the limit, this function should send the transfer to the recipient.
    //An owner should not be able to vote twice.
    //An owner should not be able to vote on a tranfer request that has already been sent.
    function approve(uint _id) public onlyOwners {
        require(approvals[msg.sender][_id] == false);
        require(transferRequests[_id].hasBeenSent == false);
        
        approvals[msg.sender][_id] = true;
        transferRequests[_id].approvals++;
        
        emit ApprovalReceived(_id, transferRequests[_id].approvals, msg.sender);
        
        if(transferRequests[_id].approvals >= limit){
            transferRequests[_id].hasBeenSent = true;
            transferRequests[_id].receiver.transfer(transferRequests[_id].amount);
            emit TransferApproved(_id);
        }
    }
    
    //Should return all transfer requests
    function getTransferRequests() public view returns (Transfer[] memory){
        return transferRequests;
    }
     
}

I have searched the forum if anyone else has ran into the same error I have and I have not found anything. In the meantime I will do some further research elsewhere on the internet. But if anyone has ran into this, I’d love to know how to solve this issue. Thank you!

1 Like

It seems that I needed to specify the visibility in the constructor, which I have:

constructor(address[] memory _owners, uint _limit) public {
        owners = _owners;
        limit = _limit;
    }

But I am confused on how others don’t have this specified in their final code?

1 Like

Apparently you have not installed neither truffle nor npm, but if this comes from vs code, it might be using powershell, you should check that, any case there are some guides on google or youtube to change the terminal on vs code.

Carlos Z

Hey @Narsi1111, hope you are well.

Please provide any details of the error, could be an screenshot of the terminal. :face_with_monocle:

Carlos Z

Hey @GahuckImGoofy, hope you are ok.

Please take a look into this post, which explain how to send the proper constructor parameters from the migration file to deploy the contract properly:

Carlos Z

1 Like

Hi all,

I tried to interact with the multisig wallet contract using the Truffle console but I came across the following errors shown in the screenshots:

truffle develop error 1

truffle develop error 2

What needs to be done first in order to interact with the multisig wallet contract using the Truffle console?

1 Like

Thank you very much! After I posted I tried to dig here in the forum some more and found what I needed. Your conversation with @Joey was very helpful!

1 Like

Untitled

1 Like