New answers tagged

0

There's no way to destroy contracts in general. They can be set to self destruct if such functionality is codes in then but this is quite rare. Normally old contracts just stay where they are and people just stop using them. If you issue the same deploy command again you will get a new contract at a new address. There's no harm in doing it this way. Except ...


0

Let's clarify some concepts first: A (client) node is used to connect to the blockchain. A node is the only possible way to communicate with the blockchain. You can either run your own node (quite much effort) or use a ready node service provider which offers you access to their nodes (such as Infura). Metamask is a browser extension which facilitates ...


0

From the code I see you're using web3 0.2.x correct? I looked at your contract code and got a bit confused what is method betOnTeam doing, I didn't see ETH transferring inside of it. Anyway if you are using MetaMask this is the way to fire transaction: function ready(){ document.getElementById("bet").addEventListener("submit", function(e){ e....


1

See the example below Warning from Remix: Experimental features are turned on. Do not use experimental features on live deployments. pragma solidity ^0.5.12; // Enable the ABI v2 Coder pragma experimental ABIEncoderV2; contract AbiTwoTest { struct Item { string str; uint num; bool bol; } struct Arg { Item[]...


0

Looks like you have some syntax errors (also that test is checking the total supply, not setting it), please try the following: contract('TtdmToken', (accounts) => { it('Checks whether or not the total supply is equal to 1,000,000', () => TtdmToken.deployed() .then(tokenInstance => tokenInstance.totalSupply()) .then((totalSupply) =>...


0

window.addEventListener('load', () => { // Wait for loading completion to avoid race conditions with web3 injection timing. if (window.ethereum) { const web3 = new Web3(window.ethereum); try { // Request account access if needed await window.ethereum.enable(); // Acccounts now exposed return web3; } catch (error) { ...


1

There is no need to hardcode a private key or import a dependency. The accounts supplied by truffle+ganache are accessible in the web3.eth provider. You can use web3.eth.sign to sign arbitrary data. It will hash the data using keccak256 and sign the hash. It is async so you have to await it, and it returns the 65-byte signature. const sig = await web3.eth....


0

The compiler complains because function TtdmToken() ends unexpectedly (your second attempt). Use constructor() instead of function() (of any name) to make a constructor. pragma solidity ^0.5.0; contract TtdmToken { uint256 public totalSupply; constructor () public { totalSupply = 1000000; } } Hope it helps.


0

A web3 call means you're just reading from a local node, not mutating the state of the blockchain, see What is the difference between a transaction and a call? As you noticed, avoiding call and just calling the method on the web3 contract instance will mutate the contract state. This is because you are sending a transaction. In web3, sending a transaction ...


1

I see you modified the question after several valid/correct answers: Question is: how to invoke GenNextID like a regular function, that is: call to this function mutates internal state it returns result returned from the contract's code YOU DON'T You either mutate the state and get a receipt, or you get a response but you don't mutate the ...


-1

The code worked and return the migration with the following correction; pragma solidity ^0.5.0; contract TtdmToken { uint256 public totalSupply; function constructor_TtdmToken () public { totalSupply = 1000000; } }


1

Try this: let myContract = await MyContract.new("constructor argument", {from: accounts[9]}); Same thing for calling functions of that contract using various accounts. You can use that object argument in order to specify various transaction details such as from, value, gas and gasPrice. It is optional (i.e., assigned default values if not specified ...


1

If you're using Truffle 4.x, then you can patch their source code as follows: Step 1 - open file: /node_modules/truffle/build/cli.bundled.js Step 2 - search for: dir.files(config.test_directory, callback); Step 3 - replace it with: dir.files(config.test_directory, (x, y) => callback(x, y.filter(f => !f.includes(".#"))));


0

When you want two contracts to be closely related I create both before running the tests contract('MyContract', async () => { let token let faucet // This function will execute once before all the tests before(async () => { token = await MockToken.new() faucet = await Faucet.new(token.address) }) it('Faucet', ...


1

No no no. The accepted answer above is incorrect, and the fact that you've accepted it means that not many users will even read your question (let alone try to answer it). The integer value of 1000000000000000000 is indeed larger than Number.MAX_SAFE_INTEGER, and you should therefore use "1000000000000000000" or "1e18". But that's not what the error ...


0

There may be a better way to do this, but usually, I pre-calculate the expected deployed contract address(es) and then I run a check to validate that the deployed contract address(es) matches the expected address(es), if any don't match, I abort the migration: const ethers = require('ethers'); const utils = require('../lib/utils/utils.js'); const Governance ...


0

Truffle Flattener Yes, there is truffle-flattener (https://github.com/nomiclabs/truffle-flattener/) that combines all your smart contracts files into one. And it works well with Truffle. Here is how to use it: 1) Install globally: npm install -g truffle-flattener 2) Use it, for example, to flatten your smart contract 'SimpleToken.sol' like this: truffle-...


0

While writing tests using truffle or for that matter if you are using the mocha library, you have to place the it blocks inside a describe block. contract("Name of a contract", accounts => { describe("What are you testing e.g. a function", () => { it("the function does something", async () => { \\ your assertions go here }); it("the ...


1

please try this: contract("DappToken", function(accounts) { it("Token buying", function() { return DappToken.deployed().then(function (instance) { console.log(instance, 'instance'); }); }); }); This is my example in other smart contract, where the tests are running smoothly: contract("CarData", function(accounts) { /...


0

The same way a mainnet contract gets used - same options. You can use truffle console which might be sufficient because you seem to be set up to connect to Rinkeby. You'll get a JavaScript interface with Web3 loaded. You can build a HTML interface and, after loading dependencies, get the MetaMask plug-in going. It gives the user a way to select the ...


1

I think I know what the problem with this is, just in the place of network_id: 3 put it as network_id:'3', and I think this should start working. AFAIK the problem is that truffle identifies networks based on network id and it is not able to parse your network_id in a proper way. Please upvote and accept if it helps. Thanks!!! Reference: https://www....


0

web3.eth.getBalance returns a Promise, with the actual balance in Wei a a string. To get the balance, you can use Promise.then() or async/await: web3.eth.getBalance(address) .then(balance => { // You can use balance here console.log(balance); }) .catch(console.error); // or const getBalance = async () => { const balance = await web3....


2

Your scheme relies on your account being unlocked on the node that you're connected to. While this scheme is reasonable for testing your system on your local host via Ganache, it is not recommended for an operational system, because anyone hacking your node could exploit your (unlocked) account at will. Instead of unlocking your account on the node that ...


Top 50 recent answers are included