Learning Truffle

Just want you guys to know that your making a real developer out of me.Ive been studying outside the course about node js and im starting to understand the front and backend of development and how we use the javascript runtime environment to run the blockchain. Or at least Im gussing that much from the fact that we call miners nodes and node js gives us the asynchronous i/o that we can use to modify they state of a block. I still dont see where the sha 256 would come in but im guessing that that is a synchronus process that operates within the mining rigs separate from the api that actually acceses the chain. Still have about 20 more hours of additional research before i feel comfortable enough to take on the final project but i can definitely say that ive come a long way. It feels like that with open zepplin being a developer will be kinda easy once i get this truffle ande node js stuff down because we won’t actually have to write much code but instead will be combining pre written code into programs and handling compatibility issues and other errors. I kinda feel like i got most of the hard stuff over with. Hope im not speaking to soon…

nevermind I figured it out. :nerd_face: :love_you_gesture:

1 Like

Thanks Dani, I forgot that.

1 Like

Hey @Riki

What’s the error message you get?

Hmm I don’t know what I have done wrong mate, but I restarted, used this: await instance.createTransfer(10000, ‘0xEA1AFdB05fd89c2C61186b28665085F214D25A39’ , {from:accounts[0]})

and it worked!

Unfortunately I do not remember what was the error message 2 days ago, should be good to know for more knowledge but guess next time.

1 Like

Ah I found what was the error:

hijackedStack: 'Error: Returned error: VM Exception while processing transaction: revert\n' +
    '    at Object.ErrorResponse (C:\\Users\\Judit\\AppData\\Roaming\\npm\\node_modules\\truffle\\build\\webpack:\\node_modules\\web3-core-helpers\\lib\\errors.js:28:1)\n' +
    '    at C:\\Users\\Judit\\AppData\\Roaming\\npm\\node_modules\\truffle\\build\\webpack:\\node_modules\\web3\\node_modules\\web3-core-requestmanager\\lib\\index.js:303:1\n' +
    '    at C:\\Users\\Judit\\AppData\\Roaming\\npm\\node_modules\\truffle\\build\\webpack:\\packages\\provider\\wrapper.js:107:1\n' +
    '    at XMLHttpRequest.request.onreadystatechange (C:\\Users\\Judit\\AppData\\Roaming\\npm\\node_modules\\truffle\\build\\webpack:\\node_modules\\web3\\node_modules\\web3-providers-http\\lib\\index.js:98:1)\n' +
    '    at XMLHttpRequestEventTarget.dispatchEvent (C:\\Users\\Judit\\AppData\\Roaming\\npm\\node_modules\\truffle\\build\\webpack:\\node_modules\\xhr2-cookies\\dist\\xml-http-request-event-target.js:34:1)\n' +
    '    at XMLHttpRequest.exports.modules.996763.XMLHttpRequest._setReadyState (C:\\Users\\Judit\\AppData\\Roaming\\npm\\node_modules\\truffle\\build\\webpack:\\node_modules\\xhr2-cookies\\dist\\xml-http-request.js:208:1)\n' +
    '    at XMLHttpRequest.exports.modules.996763.XMLHttpRequest._onHttpResponseEnd (C:\\Users\\Judit\\AppData\\Roaming\\npm\\node_modules\\truffle\\build\\webpack:\\node_modules\\xhr2-cookies\\dist\\xml-http-request.js:318:1)\n' +
    '    at IncomingMessage.<anonymous> (C:\\Users\\Judit\\AppData\\Roaming\\npm\\node_modules\\truffle\\build\\webpack:\\node_modules\\xhr2-cookies\\dist\\xml-http-request.js:289:47)\n' +
    '    at IncomingMessage.emit (events.js:327:22)\n' +
    '    at IncomingMessage.EventEmitter.emit (domain.js:529:15)\n' +
    '    at endReadableNT (internal/streams/readable.js:1327:12)\n' +
    '    at processTicksAndRejections (internal/process/task_queues.js:80:21)'
1 Like

Hi guys. why is it my compiler doesn’t throw an error when I follow the code of Filip?
->

pragma solidity 0.8.3;

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

The code was intended to not have a “public” and I save it many times and enter the command truffle compile and it doesn’t throw an error, my compiler has this always ->
nothingToCompile

Thank you in advance. :slight_smile:

1 Like

No need to bother, I already fixed the issue, I just went back from the beginning of the truffle introduction and installation and do it all over again, and its all fine now.

Thanks :slight_smile:

1 Like

Is truffle the the business standard for creating smart contract? What is the differences of remix and truffle?

1 Like

Hey @Riki

hijackedStack: ‘Error: Returned error: VM Exception while processing transaction: revert\n’ +`

This is most likely a require statement that did not pass therefore your function throw.
Happy anyway to see that you’ve fixed the issue.

Cheers,
Dani

Hi @Javier_Flores

Remix is basically a testing playground nothing more.
Truffle allows you to specify the migration rules and to write tests which are fundamental features for a smart contract developer.

Cheers,
Dani

image

Not very user Friendly lol.

Hi,

I have a problem with installing Truffle. I installed latest node.js 16.0.0.

However my cmd does not work. It jut flashes and then quit. I tried some forums but nothing worked.

So I tried Windows Powershell instead, and it does nothing. I enter “npm install truffle -g” into Powershell and hit enter.
image

And this is what happens, it just opens new window instead and it does nothing.
image

Can you help me please?

Hi @Tomahawk

Open powershell as administrator;
Run npm i truffle
Run truffle -v and check the version.

Cheers,
Dani

I run npm i truffle -> new window instead of old one -> I run truffle -v and this happens

image

I run truffle -v again and this happens
image

Really simple problem: I’ve managed to compile the Helloworld example contract just fine, so I duplicated it and made a Helloworld2 contract for the expanded functions, and I made a duplicated migrations file as well following the same instructions, and now compiling it doesn’t actually save any artifacts to the build>contracts folder. I went through and copy-pasted the contract name into the migrations file to make sure it is correct. It should work, but it doesn’t.

Truffle doesn’t throw any errors when I compile it either, it says it successfully saves the artifacts, but the artifacts aren’t there. When I go to migrate the contract it throws the error saying the artifacts aren’t there. So, Truffle thinks it’s saving the artifacts, but somehow it’s not.

Truffle Error 1

I tried using 2_hello2_migrations.js and also 3_hello2_migrations.js, and neither works. Whenever I migrate the files I get this error:

Truffle Error 2

Atom doesn’t show any new files in the build>contracts folder either:
Truffle Error 3

Any idea what might be causing this?

Hi @Tomahawk

Can you share the full screenshot of your terminal when you run npm i truffle?

Hi @CryptoPhoenix

It’s an error in the migration.
Please share the hello2 contract and migration.

Cheers,
Dani

I enter this
image

And this happens
image

Hi Dani,

I’m following Filip his steps to build the Dex wallet but I get two error messages in the below code:

Schermafbeelding 2021-04-22 om 10.26.44

I can’t see where I missed the semicolon, can you help me out?

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

import "../node_modules/@openzeppelin/contracts/token/ERC20/IERC20.sol";
import "../node_modules/@openzeppelin/contracts/utils/math/SafeMath.sol";
import "../node_modules/@openzeppelin/contracts/access/Ownable.sol";


contract Wallet is Ownable{
    using SafeMath for uint256;

    struct Token {
        bytes32 ticker;
        address tokenAddress;
    }

    mapping(bytes32 => Token) public tokenMapping;
    bytes32[] public tokenList;

    mapping(address => mapping(bytes32 => uint256)) public balances;

    modifier tokenExist(bytes32 ticker){
        require(tokenMapping[ticker].tokenAddress != address(0), "Token does not exist");
        _;
    }

    function addToken(bytes32 ticker, address tokenAddress) onlyOwner external {
        tokenMapping[ticker] = Token(ticker, tokenAddress);
        tokenList.push(ticker);
    }

    function deposit(uint amount, bytes32 ticker) tokenExist(ticker) external{
        IERC20(tokenMapping[ticker].tokenAddress.transferFrom(msg.sender, address(this), amount);
        balances[msg.sender][ticker] = traderBalances[msg.sender][ticker].add(amount);
    }

    function withdraw(uint amount, bytes32 ticker) tokenExist(ticker) external{
        require(balances[msg.sender][ticker] >= amount, "Balance not sufficient");

        balances[msg.sender][ticker] = balances[msg.sender][ticker].sub(amount);
        IERC20(tokenMapping[ticker].tokenAddress).transfer(msg.sender, amount); 
    }   

}