New answers tagged

0

The original workaround web3.toBigNumber(2).pow(256).minus(1) is no longer working. To pass in -1, try using web3.utils.toBN(2).pow(window.web3.utils.toBN(256)).sub(window.web3.utils.toBN(1));


0

After digging into the question I think that the root of the problem is Ganache. The code in the post has no issues with it, compiles and migrates properly even with Ganache; and when deployed in Remix IDE or Truffle Develop has fully functional methods. While I don't have the knowledge to assess what part of Ganache or interaction between it and Truffle ...


1

This is because accounts[1] is undefined, since you don't have a 2nd account. This is likely because of your truffle config. Do you mean to use accounts[0]?


0

The solidity version required by OpenZeppelin's contracts don't match the version configured in Truffle. Either you can upgrade Truffle to use solc v0.6, or downgrade OpenZeppelin to version 2.5 that uses solc v0.5. OpenZeppelin v3.0, v3.1 require solc v0.6 OpenZeppelin v2.5 require solc v0.5


0

just responding as faced this issue in July 2020 and it took me quite a while to fix it as there aren't many resources for Solidity v0.6 So, here are things that I did to get my code compiled successfully. Update Truffle, if you installed truffle before a significant amount of time to your development(I used it for a gig 6 months after I installed it as I ...


0

GitHub Action truffle: runs-on: ubuntu-latest defaults: run: working-directory: ./contracts steps: - uses: actions/checkout@v2 - name: Set up NodeJS 12 uses: actions/setup-node@v2-beta with: node-version: '12' - name: Cache npm packages uses: actions/cache@v2 with: path: ./node_modules ...


0

A couple of things you have to fix Provider should be a function that returns the provider, and not the provider directly. Check truffle's documentation. ropsten: { provider: function () { return new HDWalletProvider(mnemonic, "URL"); }, network_id: 3, gas: 4000000 } Once you have registered with Infura they will provide an URL for ...


1

Great, it seems you found my tutorial. You are mixing up the two different functions of swapETHForExactTokens swapExactETHForTokens If you want to use the swapETHForExactTokens, the first parameter defines how many DAI you want to buy. You are passing along 0, so it fails. Instead pass the amount of DAI along and make sure to send enough ETH to pay for it. ...


0

MetaMask is not only kind of the wallet anymore. There is now more generic Web3modal solution that allows e.g. mobile wallets to connect with your dApp. It supports both web MetaMask and MetaMask mobile via WalletConnect protocol: https://ethereum.stackexchange.com/a/82532/620


0

I had the same issue, after asking a around and searching around a bit, here is the quick solution and reason. My setting is: Truffle v5.1.31 node v14.4.0 Solidity v0.5.0 downgrade the ndoe to 12, which is not I want, so i found way 2 run "truffle migrate --network ropsten --skipDryRun" (https://github.com/trufflesuite/truffle/issues/3008) ...


2

Subscriptions are only supported by WebSockets provider. The URL you are giving is for HTTP provider return new HDWalletProvider(mnemonic, "https://mainnet.infura.io/v3/"+infuraKey);` Change https:// to wss://.


0

OK, so the problem wasn't in my solidity code (although I made changes to arrive at a solution) but rather in the call I was making in the truffle console. my payOut function now looks like this: function payOut(uint amount) public { //check if players guess == randomNumber and pay pay out //if it does. if(player[msg.sender].guess != ...


0

Yes, your contract was not deployed. To deploy your new contract you have to use truffle migrate --reset. Be aware that the contract is deployed at a new address and the old contract still remains on the blockchain. To "override" your current contract (in reality it's not overriden) you have to use the Proxy Pattern. OpenZeppelin provides a good ...


0

As said by MajdTL unlocking an account is not a good idea from a security perpective. Usually the approach is to create a mnemonic account and use @truffle/hdwallet-provider to sign transactions without having to unlock it. If you are just practicing the you will have to launch geth with an extra parameter --allow-insecure-unlock to indicate that you will ...


1

Looking at the medium article you've referred, it looks like the balanceInEth function is just a reference to web3.eth.getBalance. The function returns a Promise which resolves into a string. getBalance(address).toString() would convert the Promise into a string and not the result returned by the Promise. You can use async-await to wait for the promise to ...


1

Truffle 5.0.5 uses solc 0.5.x by default (not sure about the value of x). The override keyword is supported only from solc 0.6 onward. You should add in your Truffle configuration file: compilers: { solc: { version: "0.6.0" // or find out what the latest version is and use that instead } } See here for more details.


0

Still not sure why it returns undefined but this works and creates a new instance on the contract on ganache: truffle(development)> myToken = await MyCoin.new() The error while minting was just a matter of changing the brackets: truffle(development)> myToken.mint('0x63103644D45820EFb3cEBe188C7dA26F087797b4',100000) It works now


0

I just tried to execute one of my smart contracts function with a wrong address and it gave me the following error in remix- Error encoding arguments: Error: invalid address (arg="", coderType="address", value="0x5398EC4AE74D9a98dD5318026A6de997f6E19FB", version=4.0.45) I am not very sure - why the Value in your case is - ## (...


0

The problems is that you cannot compare objects with == (since numeric values in javascript do not have enough precision they are wrapped in an BN object). So you have to use the methods provided by the BN library return !ev.value.eq(tokens_sent); The BN library has several methods besides .eq() take a look at their documentation. For backward ...


1

I think you are trying to get the accounts of ganache using JavaScript in truffle console I advise you to write the following snippet Web3.eth.getAccounts(function(err,res){accounts=res}); and then you can access the list of accounts in truffle console using the following command accounts


1

The error tells you exactly what the issue is. In the line deployer.deploy(adoption); you are using a variable which was not declared previously. You can add var adoption = artifacts.require("adoption"); to the top of the file if you have the adoption contract defined in that Truffle project. If you haven't defined it there, you will have to copy it over ...


1

yes it is in solidity version 0.4.8 the constructor function's name is the contract's name itself. The attacker contract constructor function has a param and it is the address of the victim contract. So first he deploy Victim contract then after that he deploy Attacker contract with Victim contract address as the param for constructor function. You can ...


0

For anyone coming here and using Truffle v5+, use .address after a call to await ContractName.new(). For example: some_erc20_contract_instance = await ERC20.new() console.log(`address: ${some_erc20_contract_instance.address}`)


0

You don't need Truffle, you can do it directly with Web3, for example (tested with web3.js v1.2.1): async function send() { const web3 = new Web3(YOUR_NODE_ADDRESS); const contract = new web3.eth.Contract(YOUR_CONTRACT_ABI, YOUR_CONTRACT_ADDRESS); const account = web3.eth.accounts.privateKeyToAccount(YOUR_PRIVATE_KEY); const ...


2

Related to how to test overloaded function in truffle?, but slightly different with passing a struct. The solution is simple: MyContract.methods['init((address,address,address))'](myStruct)


0

I think if you console.log(ins.address, ans); ... you will find they are the same. If so, the issue is confusion about the instance of the contract that deployed() is using. It is the most recent, on this network, that the deployer knows about, but not necessarily what you expect. It gets updated with each deployer.deploy(). Hope it helps.


Top 50 recent answers are included