New answers tagged

0

Go in your truffle-config.js and modify the lines with the version version ... // Configure your compilers compilers: { solc: { version: "^0.6.12", // Fetch exact version from solc-bin (default: truffle's version) } }, ...


1

a possible way to write your testcase is like this: const Contract1 = artifacts.require("./C1.sol"); const Contract2 = artifacts.require("./C2.sol"); contract("Test", accounts => { let result; // First contract // Do these tests first to modify the state of C1 it("First test", async () => { ...


1

window.web3 is removed by metamask. now everything can be done with window.ethereum - web3 removal link by metamask Below is the new way of getting accounts. import detectEthereumProvider from '@metamask/detect-provider'; initialize ethereum provider async loadWeb3() { const provider = await detectEthereumProvider() if (provider) { console.log('Ethereum ...


0

For your contract, have you used ^0.6.12? That should allow you to interact with any other versions above the one you intend to use.


0

Truffle and Ganache generates different seed phrases. In order to have the same addresses from truffle develop into ganache gui, you need to copy and paste the seed phrase com truffle develop and paste it into the ganache accounts tab, when creating a new workspace


0

You cannot retrieve whole array from solidity. You have to choose the index, that is why it is expecting 1 argument. If you want to get whole array elements in javascript, in solidity define a function to get the length of the array. //Contract Code function getTmpCount() public view returns(uint){ return tmp.length; } then in javascript code: // you ...


1

@alberto has it correct. truffle(ropsten)> Migrations.new.estimateGas() 193243


0

To get the return value you should add callStatic to it. > const shareTokenAddress = await liqminter.connect(actorA).callStatic.createPair([...]) callStatic is a read-only operation and will not consume any Ether. It simulates what would happen in a transaction, but discards all the state changes when it is done.


1

What you are seeing are warnings, not errors. They do not prevent the contract from compiling. In addition to this, your code isn't the same as the VRF code sample in the Chainlink docs. The version in the docs doesn't read immutable variables in the constructor, everything is hardcoded. Finally, as previously stated, if you change your compiler to v0.8.8, ...


1

You can read immutable variables in the constructor in Solidity v0.8.8 and above: Compiler Features ... Immutable variables can be read at construction time once they are initialized.


0

Basically: factory = await Factory.connect(deployAccount).deploy(parameters); Full deployment: [owner, addr1, addr2] = await ethers.getSigners(); const Factory = await ethers.getContractFactory("Factory"); factory = await Factory.connect(addr1).deploy(parameters); await factory.deployed();


0

"UniswapV2 addLiquidity revert ds-math-sub-underflow" error happened because "msg.value" parameter has not been provided for calling "addLiquidity" method. Now call the addLiquidity method as: await uniswapV2Router02.addLiquidity(token0.address, token1.address, 500, 250, 250 , 125, accounts[0], 1618158769, {value : "125&...


0

In the newer versions of solidity, you have to explicitly mention payable wherever it is expected. Crowdsale(_rate, payable(_wallet), _token)


0

I just closed vscode and restarted the laptop. And the truffle develop command started working.


0

To update an artifact, you can simply recompile the contract. But deployed smart contracts are immutable. That's their beauty. If you don't want to redeploy the contract, why you want to recompile it? You cannot simply update the artifact (recompile) and expect the deployed contract to update. Edit: The artifacts (also called ABI) are results of compilation ...


0

This is the code syntax I always use in JS for HDWallet Provider. Works fine every time. provider: () => new HDWalletProvider(secret, "http://IP_address:Port"), Note: I use http, not http(s)


0

If you deployed the contract and lost the address you can simply retrieve it by truffle commands. You just need the name of the deployed contract. For example, I deployed NewContract but lost his address. truffle console --network private truffle(private)> truffle(private)> let contract = await NewContract.deployed() truffle(private)> contract....


0

If the contract is being deployed you can obviously read it from the log. What if the contract has deployed but you did not take a record of it? There are a few ways to do it: 1. Using etherscan (or Rinkeby scan, Ropsten scan etc..) and search your wallet address used for deployment of the contract. But what if I don't recall the wallet address used? You can ...


0

had a similar issue. all I had to do was uncomment the development key under networks in the truffle.config.js and the contracts migrated to dev blockchain just fine.


0

I face-planted on these sorts of errors recently too! Turns out there be additional setup required known as migrations... Truffle -- Running Migrations -- deployer.link(library, destinations) section covers how to link libraries and contracts. TLDR ./migrations/99_link_example.sol const Alireza = artifacts.require("Alireza"); const B = artifacts....


2

Opensea did not supports the BSC network. But you can mint the NFTs on Polygon for cheaper fees. Polygon is supported by Opensea platform. Reference: Which blockchains does OpenSea support?


0

try npx truffle init after you install npm and truffle


0

We have to send a tx object which contains a from parameter like so: const WETH = artifacts.require("WETH") const USDC = artifacts.require("USDC") module.exports = function (deployer, network, accounts) { deployer.deploy(WETH, 2000000000000000000n, {from : accounts[0]}) deployer.deploy(USDC, 50000000000000000000n, {from : ...


0

This is the correct way to link the library to the child contract. The problem I was having was related to the line let address = await metaCoinFactoryInstance.createToken.call({ from: user}) Since it is a transaction, I should use send(). The last truffle version doesn't have the send() function.. It should call the function instead that will return the ...


0

Ganache UI under Windows is not the same as Ganache-cli under WSL The Ganache UI on Windows is listening to Windows Port. The WSL2 instance have it's own set of ports. So Even if they are set to the same port they are not What you should do is use Ganache-cli in WSL2. This will fix your issue. Since they will both be on the same system.


0

The issue was happening in Token.test.js file. Compiler was expecting an exception as the code block ended with rejectedWith. It should have been just rejected. There was nothing wrong with the above code. Hope it helps, as I wasted a whole day an half on it.


1

I solved this issue by installing ganache-CLI via WSL. Able to interact with the local blockchain now.


1

from truffle develop you could try something like let c = await MyContract.deployed() await c.goalScored('a','b') let events = await c.getPastEvents('Score',{ fromBlock:0, toBlock:'latest'}) events furthermore, if you need ALL events, you could use c.getPastEvents('allEvents',{ fromBlock:0, toBlock:'latest'}) full truffle develop input: migrate let c = ...


1

Guys I have tried all the answers shared here and none worked, I don't know if they fixed your issue, but what fixed my issue was running everything normally in the CMD and not POWERSHELL, that's it everything runs smooth and as expected.


0

You want to trigger an event in your front end that will catch these value and store them in the state until you process them. *REACT* <input type="text" onChange={(e) => console.log(e.target.value)}> This will print out the value in the devtool console anytime the value change. To send your transaction to the network, Your app will need ...


1

I found the answer to my problem. The clone factory was missing the transferOwnership of the token contract which prevented the caller to call the functions of the clonable contract. function createNFTContract(bytes32 salt,string calldata name, string calldata symbol,string calldata _tokenURI)external isRegisteredUser returns(address){ NFT ...


Top 50 recent answers are included