Learning Truffle

Hey @thomascarl

IERC20(tokenMapping[ticker].tokenAddress.transferFrom(msg.sender, address(this), amount);

You need to close the “IERC20 (address).transferFrom etc…” round bracket.

Should be:

IERC20(tokenMapping[ticker].tokenAddress).transferFrom(msg.sender, address(this), amount);

Cheers,
Dani

Ahh perfect! Thanks again Dani

1 Like

Sorry to come back again but now I’m migrating the wallet and try to interact with it. When I use : wallet = await Wallet.deployed() it works but then the: link = await Link.deployed() throws an error message that Link.deployed is not a function. What am I doing wrong?

Schermafbeelding 2021-04-22 om 11.29.06

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

import "../node_modules/@openzeppelin/contracts/token/ERC20/ERC20.sol";

contract Link is ERC20{
    constructor() ERC20("Chainlink", "LINK") {
        _mint(msg.sender, 1000);
    } 
}

Hello2 Hello2Migration

Hey @thomascarl

Can you please share the link migration?

Thanks
Dani

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

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

Hey @CryptoPhoenix

I cannot see any error in the contract and migration you’ve posted.
Make sure to save all your files, delete the folder build -> contracts
Run truffle migrate --reset.

Hey @thomascarl

Can you push your project on github and share the link? I will check it out.

Hi again Guys!

Yesterday I had to switch into a new computer and start all the Dex from scratch and I ran into a new problem.

Here is my code: (for token migration)

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

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

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

  await deployer.deploy(Link);

  let dex = await Dex.deployed()

  let link = await Link.deployed()

  await link.approve(dex.address, 500)

  dex.addToken(web3.utils.fromUtf8("LINK"), link.address)

  await dex.deposit(100, web3.utils.fromUtf8("LINK"))

  let balanceOfLink = await dex.balances(accounts[0], web3.utils.fromUtf8("LINK"));

  console.log(balanceOfLink);

};

And for the wallettest(same as Philip is having on the video):

const Dex = artifacts.require("Dex")

const Link = artifacts.require("LINK")

const truffleAssert = require('truffle-assertions');

contract("Dex", accounts =>{

    it("should only be possible for the owner to add tokens", async() =>{

        let dex = await Dex.deployed()

        let link = await Link.deployed()

        await truffleAssert.passes(

            dex.addToken(web3.utils.fromUtf8("LINK"), link.address, {from: accounts[0]})

        )

        await truffleAssert.reverts(

            dex.addToken(web3.utils.fromUtf8("LINK"), link.address, {from: accounts[1]})

        )

    })

})

When I do truffle test I get following error:

Error: Dex has not been deployed to detected network (network/artifact mismatch)
at Object.checkNetworkArtifactMatch (C:\Users\Riki\AppData\Roaming\npm\node_modules\truffle\build\webpack:\packages\contract\lib\utils\index.js:245:1)
at Function.deployed (C:\Users\Riki\AppData\Roaming\npm\node_modules\truffle\build\webpack:\packages\contract\lib\contract\constructorMethods.js:88:1)
at processTicksAndRejections (internal/process/task_queues.js:93:5)

Anyone can point me somewhere?

Ah man of course after 5 minutes I post I found the solution. All good now!

2 Likes

That worked, thanks!

1 Like

So I keep getting an error that Im not using the right solc but I changed everything to pragma solidity 0.8.3
Screen Shot 2021-04-24 at 9.20.06 AM

Screen Shot 2021-04-24 at 9.20.08 AM

Screen Shot 2021-04-24 at 9.20.13 AM

1 Like

Hey @inzhagey, hope you are ok.

I think you should check which solidity version is used by your openzepellin contracts.

Since you are just specifying truffle to be able to compile with an specific version, only 0.8.3.

Even if your contracts use a version above openzepellin contract’s, your truffle compiler must be able to compile in different solidity versions to fulfill its process between different contract’s requirements (the version of each contract).

Now in the same way you could do something like:
pragma solidity >=0.6.0 < 0.8.0; for a contract, you could (and should) setup your truffle.config file compilers within the same range.

Try to change your compilers version to match the range for your contracts (openzepellin contracts included).

Carlos Z

1 Like

I did change it to pragma solidity >=0.6.0 < 0.8.0; and it said “Source file requires different compiler version (current compiler is 0.8.3+commit.8d00100c.Emscripten.clang) - note that nightly builds are considered to be strictly less than the released version”

Screen Shot 2021-04-25 at 10.48.13 AM Screen Shot 2021-04-25 at 10.48.56 AM Screen Shot 2021-04-25 at 10.49.09 AM

1 Like

Try to change your compilers version to match the range for your contracts (openzepellin contracts included).

Carlos Z

What do you mean, isn’t that what I did above?

Hi @inzhagey

Once you have changed the Solidity version in your truffe-config.js you have to make sure to close Ganache-cli (truffle develop) before compiling your project again (otherwise it will keep compiling with the old version instead of the new one).

Restart your local blockchain then compile again.

Cheers,
Dani

@thecil @dan-i

Hi guys,

I had a problem. My Command Prompt and Windows Powershell is broken. I tried to fix it with other forum tips but none was succesful.

So I’ve got an idea. I created a new user account on windows and there is both Command Prompt and Windows Powershell running fine. It’s not ideal but at least something works.

However when I try to run cmd on my alt account:
node.js version 16.0.0
npm version 7.11.1

I run "npm install truffle -g" and below you can find screenshots. When I try to run “truffle” afterwards, it says the command was not found, so I guess the installation was not successful. Can you help pls? Thanks.

image

image

image

Help guys, I encounter this issue when I try to download the “The Ethereum Solidity Language for Visual Studio Code byJuan Blanco” Screenshot 2021-04-27 001208
Kindly help me guys to resolve this issue.
Thanks.

Hi @Tomahawk

The command you are running looks wrong, run sudo npm i -g truffle

cheers,
Dani