Learning Truffle

Thank you so much again Dani! You are my hero :wink:

1 Like

Hi Team,

I am working on the assignment to migrate the multi-sig wallet and trying to passing the owners array of addresses however the only thing that has worked is to hardcode the addresses (taken from the accounts arra( in the deployer function as an array.
Is this the only way or is there a more generic approach where we can use specific accounts from the accounts array referencing the accounts array as “accounts[0]” for example.

Any advice would be helpful!

Thanks

Hey @Mariano_Collarte

Sure you can use the array of accounts.
You can do that from your migration file, give it a try if you cannot find the solution post the migration here :slight_smile:

Cheers,
Dani

Thanks Dani!

So I did some reading on the truffle website and noticed that I can pass an array of accounts to the module.exports function so I tried something like this:

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

module.exports = function (deployer,accounts) {
	var numApprovals = 2;
	var arr = [accounts[0],accounts[1]];
	deployer.deploy(Wallet, arr, numApprovals);
};

But that seemed to fail. I tried a few variations of that but the only one that seemed to work was the following:

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

module.exports = function (deployer,accounts) {
	var numApprovals = 2;
	deployer.deploy(Wallet, ['0xb10934df75f7b1f064cce0c3ae41b4726fa0a7a6','0xb10934df75f7b1f064cce0c3ae41b4726fa0a7a6'], numApprovals);
};

Where those addresses were pulled after I ran the truffle develop command.

Ideally I would like to not have to hardcode them in the deployment script but maybe that is the only way :slight_smile:
let me know!

Thanks!

3 Likes

Hey @Mariano_Collarte

You are almost there :slight_smile:

Truffle migration has 3 params: deployer, network and accounts.

Documentation: FAQ - How to post code in the forum

accounts is the 3rd parameter.

module.exports = function (deployer, network, accounts) {}

Try this way and should work.

Cheers,
Dani

2 Likes

I installed truffle like he said and already had visual studio installed. When it came time to create a new .sol file in visual studio, I found that I had the package.json file, but no Migrations.sol or truffle-config.js. What do I do? I checked my command prompt and it looked the same as what he did.

It looks like I fixed it by unboxing metacoin to my folder. I think unboxing any truffle project would have worked? Anyway I googled for how to use truffle and found a youtube tutorial by our teacher (the same guy) and that’s where I got the solution.

I am trying to run my multisig wallet on remix and truffle side-by-side. The remix version is running fine, like it did when I first made it. But when I try to use the “AddOwner” function (that’s all I’ve gotten to so far) on truffle, and I use the exact same address as on remix, it says that I have an invalid argument. Why would the function work fine on remix and not on truffle?

Edit: I solved my own problem again. I added single quotes to the address on truffle and it works. I guess they gave me the quotes automatically on remix.

Edit2: Now I have a new question: In remix, I could switch addresses by using a dropdown list. How do I do this in Truffle? I can’t test the functionality of a multisig wallet without using multiple addresses.

1 Like

I have the same problem; I’m not sure how to switch accounts to do second approval. If you find a solution, please let me know!!

1 Like

I just managed to send a transaction from a different address to approve the transfer using the below command:

instance1.approve(0, {from:accounts[2]})

Great! I had exactly the same problem, this works perfectly! Thanks

Hello, I’ve been trying to sort this issue for a while but can’t seem to find the fix. I’ve tried running sudo npm install but still throws this error (EACCES) and says my operating system rejected it and that i don’t have permission to access this file as the current user. Any Ideas??

Screenshot 2021-03-30 at 10.07.50

I managed it with sudo install. I forgot to uninstall the previous installation attempt before my reinstalling with sudo.

2 Likes

This is for the truffle multi-sig wallet assignment to practice using the terminal.
I ran these commands:
truffle compile
truffle develop
migrate

After the migrate command it said deployment failed. Not sure how to fix this issue

Screenshot 2021-03-30 at 16.54.43

Hi @ol_frank

Post your contract ‘Wallet’ and the migration of it so that I can take a look.
Seems like the contract Wallet (most likely its constructor) requires 2 params but you are not sending them.

Cheers,
Dani

Hey Dan,
Wallet contract:

pragma solidity 0.8.3;

contract Wallet{

    address[] public owners;
    uint limit;

    struct Transfer {
        uint amount;
        address payable reciever;
        uint approvals;
        bool hasBeenSent;
        uint id;
    }

    Transfer[] transferRequests;

    event ApprovalRecieved(uint _id, uint _approvals, address _approver);
    event TransferRequestCreated(uint _id, uint _amount, address _initiator, address _receiver);
    event TransferApproved(uint _id);

    mapping(address => mapping(uint => bool))approvals;

    modifier onlyOwners(){
        bool owner = false;
        for(uint i = 0; i < owners.length; i++){
            if(owners[i]== msg.sender){
                owner = true;
            }
        }
        require (owner = true);
        _;
    }

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

    function deposit()public payable{}

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

    function approve(uint _id) public onlyOwners {
        //owner should not be able to approve twice;
        require (approvals[msg.sender][_id] == false);
        //owner should not be able to approve a tx that has already been sent;
        require (transferRequests[_id].hasBeenSent == false);

        emit ApprovalRecieved(_id, transferRequests[_id].approvals, msg.sender);

        approvals[msg.sender][_id] == true;
        transferRequests[_id].approvals++;
        //condition
        if(transferRequests[_id].approvals >= limit){
            transferRequests[_id].hasBeenSent = true;
            transferRequests[_id].reciever.transfer(transferRequests[_id].amount);
            emit TransferApproved(_id);
        }
    }

    function getTransferRequests() public view returns(Transfer[] memory){
        return transferRequests;
    }

    

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

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

Hey @ol_frank

Yup it’s what suggested in my previous post :slight_smile:

Your wallet contract constructor requires two params but your are not sending them.


  constructor(address[] memory _owners, uint _limit){
      owners = _owners;
      limit = _limit;
  }
module.exports = function (deployer) {
  deployer.deploy(Wallet);
};

Screenshot 2021-03-31 at 14.10.15

Give the requested params to your constructor when deploying and will work.

Regards,
Dani

1 Like

Thank you Dan! Appreciate your help

1 Like

Screen Shot 2021-04-02 at 10.41.32 AM

Screen Shot 2021-04-02 at 10.41.53 AM

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

when i did npm install -g npm: i got this

Screen Shot 2021-04-02 at 10.46.15 AM
Screen Shot 2021-04-02 at 10.46.20 AM

Hi @dan-i!

I have small issue with building NFT game. Its from first video… I have truffle from (npm install -g truffle) Node.js on my computer.
But If I want to compile (truffle_compile) then I have this:
/C/Users/User/Desktop/NFT_GAME/contracts/Token.sol:1:1: Warning: Source file does not specify required compiler version! Consider adding “pragma
solidity ^0.5.16;”

I changed version in truffle-config.js and uncommented compilers, row version and type 0.8.0.
Please, where is problem?

My contract attached…
image