Learning Truffle

I’ve the same problem man unstalling, unistalling, using --force. No way for going forward. So annoying

maybe the problem is with nodejs
:grimacing:

I’ve been getting this error while trying to compile my smart contracts
I need help please, I’ve tried every possible solution I have seen here

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

Take a look from the minute 9:30, https://academy.moralis.io/lessons/truffle-hello-world

you are just forgetting that step in your truffle.config file.

Carlos Z

I’ve done that but it’s not working either

1 Like

I have a little problem with the installation of truffle. Do some of you know a solution? This is only on my laptop. On my desktop PC i followed and did the same steps and did not have any problems.

 78 vulnerabilities (7 low, 49 moderate, 15 high, 7 critical)
npm ERR! code ENOLOCK
npm ERR! audit This command requires an existing lockfile.
npm ERR! audit Try creating one first with: npm i --package-lock-only
npm ERR! audit Original error: loadVirtual requires existing shrinkwrap file

npm ERR! A complete log of this run can be found in:
npm ERR!     C:\Users\pauls\AppData\Local\npm-cache\_logs\2021-12-10T17_21_24_266Z-debug.log   
1 Like

Try change your compiler version of solidity in the truffle.config file to ^0.8.0, also you have to check which is the version of your contracts, should be the same that you will use for the truffle.config.

Carlos Z

Hey @PaulS96, hope you are well.

Sorry but the error message does not said too much about why is the error, which repository did you try to install in your laptop? Maybe the npm version on the laptop is different? or must install git? (i mean maybe your just missing one of the programs in your laptop).

Carlos Z

1 Like

i did just that but its not working

I’ve been on this for long
I’ve updated truffle and solc but it isn’t still working

@thecil Hi, I tried to uninstall and reinstall both Truffle and Node.js. This didn´t solve the problem but I managed to fix it with npm i --package-lock-only followed by npm audit fix. This seema to have fixed the problem. If someone has the same problem I hope this is helpful for you.

1 Like

Hi all…I am working on the Truffle assignment. I was able to successfully deploy Wallet.sol with these parameters for the constructor

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

const owners = ["0xb572975938f0ca7cafa4b383194873538146b415","0xcd18d7a360a17dbbdbfe63aaab4ca933fbdc0b4c","0xbcd560444eaccb9115b48111cc961330e71852c0"];
const limit = 2

module.exports = function (deployer) {
  deployer.deploy(Wallet, owners, limit);
}

Subsequently, I was able to Create and Approve two Transfer requests:

However, I keep getting an out of gas error with I attempt additional approvals. I’ve tried various combinations of the owners - e.g., truffle(develop)> instance.approve(0, {from: accounts[2]}).

Here is the error:

Any suggestions? Thx!

You might have to use await instance.approve(...) since its an async method to invoke, but i suggest to move forward until you reach unit test, then you can write all this tests for the contract instead of manually doing them on the truffle console

Carlos Z

Try following this guide to downgrade node to a older version, probably will do the trick (i use node v 12.0.0, its working fine for me)

https://studygroup.moralis.io/t/faq-how-to-downgrade-node-js/22908/3

Carlos Z

I fixed it by uninstalling everything including truffle globally and openzeppelin. And reinstalling them

1 Like

Hi Carlos, I copied your migration file for the multisig and ran truffle compile, truffle develop and migrate but I am currently facing a few problems:

  1. red swiggly lines on "=’ at module.exports = function(Deployer, network, accounts)
  2. Error: Wallet has not been deployed to detected network (network/artifact mismatch)
const Wallet = artifacts.require("Wallet");
module.exports = function(deployer, network, accounts) {
    const accountArray = [accounts[0], accounts[1], accounts[2]] 

    deployer.deploy(
      Wallet,
      accountArray, // this is _owners Array
      2 // this is _limit
    );
};
1 Like

Hey @nortay, hope you are well.

Is your contract name the same than the artifact? “Wallet”.

Apparently the contract is not deployed yet, so the artifact might run into issues if the contract file is not found.

Carlos Z

Hi guys, I seem to be having an error when running “truffle develop”. Has anyone come across this error? Thanks in advance!

1 Like

Ok, I found a workaround by downgrading nodejs to version 12.0.0. Hope this helps anyone else in the same situation.

1 Like

Hi All,

I have a few questions.

  1. is it possible to not hardcode the addresses in the migrations file for the constructor? (You can find the code below)
  2. when trying to approve one transfer, it keeps failing for the last approvement. Let’s say one transaction needs 2 approvements (Multi-Sig) before the transaction will actually send. The last approver gets rejected. What’s happening??

MultiSigFinalCode.sol

pragma solidity ^0.8.10;
pragma abicoder v2;

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;
    }

    function getOwners() public view returns(address[] memory){
        return owners;
    }
    
    
}

Migrations File

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

module.exports = function (deployer) {
    deployer.deploy(Wallet, ["0xb40a389fa016f5b610d2d21042e72465d9cc2b5a", "0x12812776e84ebeff5c4d0a69453a794e3e4fefe4", "0xeb4461cf9188290db604ba479ca81a90df2c0987"], 1);

};

As you can see, the public addresses are hard-coded.

The last approval gets rejected. Terminal logs that the function has run out of gas. How come?

I hope someone got the time to look into it and tell me what’s going wrong…
@filip