New answers tagged

0

If you want to create your own network you should use ganache, ganache-cli or test-rpc. Those are local blockchain test networks you can configure. After setting up and running your network you should add the network config to your truffle-config.js: module.exports = { networks: { development: { host: "localhost", // your if port: 8545, //...


0

You can create you own simulated blockchain by running Ganache in a separate process. In the truffle-config.js you can change the specifications of the development network and then just run truffle test it will use development by default. In your case it would probably look like this development: { host: '127.0.0.1', // This might be different for you ...


0

BN is a library for calculating with big numbers in JavaScript; see here for more details In order to print a complex object properly, use JSON.stringify on it; for example: Instead of console.log('all info: '+accounts[3], 50, '123', res); Do console.log('all info: '+accounts[3], 50, '123', JSON.stringify(res, null, 4));


1

it('should not generate the hash for same reference number', async()=>{ actions.generateHash.call(100, '123', {from: accounts[0]}); await assertLib.reverts(actions.generateHash.call(100, '123', {from: accounts[0]})); }); In the above test statement you have specified generatehash.call() .call is used to read state ...


0

Now you can use await to simplify code: let accounts = await web3.eth.getAccounts()


1

That BN stands for BigNumber. It's a JavaScript framework for representing..well...big numbers. If you simply console.log a BigNumber it will give you such internal data of the single BigNumber, such as those length and words. Those are not trivially interpretable. So what you should do it simply .toString() it to get the actual number. It really is just ...


1

You can simply start Ganache with -b 15. See here for more details. Update: The above solution is for when you start Ganache as a separate process. In order to simulate a 15-second elpase in your tests, you can simply use this: web3.currentProvider.send({method: "evm_increaseTime", params: [15]});


0

The only way for some to replace your contract is if they have the private key of the account with which you have deployed that contract, as well as the nonce used upon deployment. Truffle is typically used for conducting tests on a private network that you set up on your local machine. If you terminate that network and then create it again from scratch (for ...


0

Where did you found out this? Would you mind to share the details? The information is completely wrong.


0

Your network timeout is very long. delete that line. It will then give you an error telling you what to do next. Probably to do with lack of reply to your infura ping.


0

The options for Mocha seems to have changes more frequently than expected. As of the Truffle v5.1.9, the Mocha used is v5.2.0, And the options for Mocha class can be found at the source code located here : https://github.com/mochajs/mocha/blob/v5.2.0/lib/mocha.js#L83 There are options like the followings enableTimeouts - boolean, Enable timeouts? timeout ...


0

Truffle uses Mocha programatically. So, the Mocha class constructor shows the full options. Truffle v5.1.9 seems to use Mocha v5.2.0 and the constructor code for this version can be found here. https://github.com/mochajs/mocha/blob/v5.2.0/lib/mocha.js#L83 Which shows * @class Mocha * @param {Object} options */ function Mocha(options) { options = ...


0

It is possible to override default network with --network <NETWORK_NAME>. truffle migration --network devel


0

Function send returns a Promise object which, when resolved, returns the transaction-receipt. The transaction-receipt contains all events emitted by your contract function (sendFunds). So first, save that Promise object: const promise = this.state.swapcontract.methods.sendFunds(address).send(...); Then, resolve it in order to get the receipt. You can do ...


2

Just found out that my test code had wrong brackets placement: it was contract("Marketplace"), accounts => { //all tests go inside here let marketplace; before(async () => { marketplace = await Marketplace.deployed(); }); //describe comes from Mocha framework describe("deployment", async () => { it("deploys successfully", ...


1

I have created and compiled a contract according to the one that you've posted in a comment. I have deployed it to Ropsten, and then verified it on Etherscan. As you can see on Etherscan, its byte-code contains the sequence 704f1b94, which is the function-selector of function registerUser(string). And as you can see on Etherscan, the byte-code of your ...


1

It seems you are using your contract from the backend. In that case you cannot use MetaMask because it runs in the browser. You have these options: Execute the transactions that make changes from the frontend. The UI has to connect to MetaMask and use it as provider for @truffle/contract. Use your own wallet in the backend and configure truffle to use it ...


1

Since you are using truffle the correct syntax is tokenInstance.getTokens({ from: accounts[1] }); Adding .call() will make the call but any change will not be recorded in the blockchain.


0

You cannot do it this way. First, you need to do const tokenAddress = await escrow.token();. Then, you need to use this address in order to create a contract object. If you're on Truffle v4.x (web3.js v0.x), then you can do: const tokenContract = web3.eth.contract(<Your ERC20 ABI Array>).at(tokenAddress); If you're on Truffle v5.x (web3.js v1.x), ...


1

If you call transaction.send without providing a gas value, then the value returned (in a Promise) from transaction.estimateGas is used by default. In some cases, this value is an underestimate of the actual amount of gas required for executing the transaction. A possible solution for this is to do something like this: const MIN_GAS = 1000000; const gas = ...


0

While there are a few sources of normal variance: Different EVM versions have different OPCODE pricing Conditional branching in contracts, including ERC20, can lead to a range of possible transaction costs There is no good reason for a valid transaction to shoot up many orders of magnitude. Unless it is a very strange token contract, there would be no ...


0

new web3.eth.Contract calls the constructor of class web3.eth.Contract. This constructor (naturally) returns an instance of class web3.eth.Contract. Your attempt: var contract_object=new web3.eth.Contract(...); var theContract=contract_object.new(...); Fails because class web3.eth.Contract does not have a member function named new. You are most likely ...


0

Is it possible to compile the same contract for evm version istanbul? No. You cannot compile contracts written using v0.5.7 to evm version istanbul. As doing so will generate an error Invalid EVM version requested. Why the above error? Since the EVM versions (Target Versions) as specified in solidity docs for v0.5.7 is till petersburg and istanbul was ...


3

I found openzeppelin-test-environment solving my problem. It allows ephemeral Ethereum blockchain setup, contract deployment, etc. relatively easy. Below is my original Truffle + TypeScript test translated to OpenZeppelin + Jest + power-assert. Jest test import assert = require('assert'); import { accounts, contract } from '@openzeppelin/test-environment'...


3

Error says it all, you need to break down your struct data. Either separate it to different structs, contracts or keep some of the data offchain (database), make connection/ linking with unique parameter and save that unique parameter into the struct. Another solution is what I did for another project I had to save many variables including files for single ...


0

With contract = new web3.eth.Contract(abi, addr), The one and only reason for contract.methods.decimals().call() to throw: Error: Returned values aren't valid, did it run Out of Gas? Is if no contract which implements function decimals() is deployed at addr.


0

Which truffle version are you using? I had same issue and I was using v5.1.15, the latest version for now. And I try an old v5.1.10 and it works. It's due to a compilation OS-compatibility path issue. Here you can find an article about it: https://github.com/trufflesuite/truffle/issues/2834#issuecomment-588321875


0

I also had the same error. I was able to solve it by changing the mnemonic in my truffle-config.js to match the mnemonic given by Ganache CLI. Because each time you run Ganache, the mnemonic changes. but you have to remember to change it in your config file to access the funds in the correct account


Top 50 recent answers are included