Truffle Introduction

Hi @dan-i thanks so much - the issue has been resolved!

1 Like

Hello.

Currently watching the Truffle Introduction section, just a minor question. I see that writing code using a text editor doesn’t show the errors unlike Remix does. Would it be better to write code first on Remix and when the code is ready, transfer it then to the whole process of Ganache, truffle etc?

Thanks.

Hi @newavel

Remix is useful when you need to test small functions and you quickly want to see if the logic works.
If you are writing code in Atom (or any other text editor), you can check for compiling issue such as a typo by opening the Truffle console, then migrate --reset.
An example below:

Code with a typo:

Cheers,
Dani

2 Likes

Hi How do you see this menu? When I open node . JS I dont get this screen nor can I create new workspaces . Can anybody assist me ?

Thanks

Thomas

Hi @Thomas_VL

What you see in my console is Truffle.
There are really nice videos from Filip that teach how to use Truffle, have a look : https://academy.ivanontech.com/products/ethereum-smart-contract-programming-201/categories/1993907/posts/6668000

Check it out and let me know if you have questions.

Happy learning,
Dani

1 Like

Hello.

A couple of noob questions regarding the payable functions section.

  • The ‘deployer’ is like a built-in tool from Truffle, right? Like, it is required to use so that the contract will migrate without errors?
  • Not sure if I understood what Filip meant in the ‘network’ and ‘accounts’ parameter. Can someone explain to me why these are used? And what could be the importance of the two?
  • The options object is where we can specify how much should a function cost?
  • Is the migrations.sol/ migrations.js a constant in Truffle? If I delete it so I can start in a ‘clean’/‘blank’ state, how would that affect my contract?

Thank you :sweat_smile:

Hi @newavel

I suggest you to read the truffle documentation, where most of your questions have been answered :slight_smile:
Documentation

  • The deployer object is responsible for deploying smart contracts indeed. It is a wrapper provided by Truffle.

  • The network specifies the behaviour of you migration file based on which network you are using.
    It might happen that you want to migrate your project differently based on the network you are using testnet / mainnet etc…

  • Accounts is an array of accounts(accounts[0],accounts[1] etc,), you can specify which account does what. In your screenshot above, accounts[0] is calling the function setMessage().

  • Not sure what you mean with “the object”, if you clarify I will be happy to answer :slight_smile:

  • You cannot remove migration.sol and migration.js as they are needed for truffle to work correctly.

Cheers,
Dani

1 Like

I can’t get what’s the point of writing “instance.getmessage” here:
image
why doesn’t it work without it? I mean the"message" is set to the new value and the function is getting it as input, why doesn’t it log without “instance.getmessage” ?

Hello,

this is my own version of the error handling example. I wondered why Filip deleted the two lines of code in the video about Error Handling. This was for simplicity, because one has to take care of catching the error at the right level of indentation. This example of the 2_Helloworld_deploy.js file works and results in the same expected error message, because only 1000000 wei is sent, while the smart contract requires 1 ETH in the setMessage function: require(msg.value >= 1 ether);

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

module.exports = function(deployer, network, accounts) {
  deployer.deploy(HelloWorld).then(function(instance){
    instance.setMessage("Hello again!", {value: 1000000, from: accounts[0]}).then(function(){
      instance.getMessage().then(function(message){
        console.log("Current message is " + message);
      });
    }).catch(function(err){
      console.log("error: " + err);
    });
  });
};

Have fun trying!

Regards Ouzo69

1 Like

Hello @filip
in previous course we used msg.value to check the balance of message sender, if it is true then it shouldn’t get error when we used require(msg.value >= 1ether). I mean the value of tx is less than 1 ether but the balance is more.
can you explain this please?

Hey @sajede.k

The code needs to know which function has to be called in order to display the message this is why you need to call instance.getMessage.

Happy learning,
Dani

1 Like

Hey @sajede.k

msg.value is not the balance of the sender, but is the amount sent to the transaction.
If a sender has 100 ether in his wallet but send 1 ether to the function, msg.value will be equal to 1 ether.

Cheers,
Dani

2 Likes

Hello,
Thank you
but the contract itself calls the getmessage not any body outside.
and the function that displays the message is " function(message){
console.log("Current message is " + message);
} "
can’t we get the variable “message” directly from the Helloworld contract to use in this function?

Hello again,
Thanks a lot, you’re right.

@filip

I typed in truffle(ganache)> let instance = await HelloWorld.deployed and got undefined
then I typed instance and did not get the command list. I got instead “[Function: bound deployed] AsyncFunction”

Not sure what this means or why it did not give the command list.

Hey @CryptoEatsTheWorld

The right syntax is let instance = await HelloWorld.deployed().
Git it a try, if it still fails post your migration file and your contract ABI here.

Happy learning,
Dani

1 Like

Thanks! I tried that and at first it didn’t work and said “Identifier ‘instance’ has already been declared”, so I had to do “.exit” and then go back in to “truffle console” and do the process again and this time it worked.

Hey @CryptoEatsTheWorld

If you declare instance once let instance = await HelloWorld.deployed(), you cannot declare it again but you can assign a new instance to instance.
Example:

1st time = let instance = await HelloWorld.deployed()
2nd time = instance = await HelloWorld.deployed()

Happy that it worked :slight_smile:

If you have issues let me know.

Cheers,
Dani

1 Like

Thanks again.

Is there any good place online to get a general primer for beginners on using these kinds of terminal commands? I feel like this course just threw us in to the terminal part of this work without any familiarity and explanation as to how that works. Even though using the terminal is not directly about learning solidity, the fact of being dipped into another area of tech that I don’t have familiarity with tends of overwhelm a bit as to how much I don’t know. And it leaves me in the position of just needing to use a “cheat sheet” of these commands to “get by” instead of really understanding what I am doing.

@CryptoEatsTheWorld

The commands you are using are in JavaScript.
You are not using terminal related commands :slight_smile: