New answers tagged

0

The Ether is always stored in the contract itself, but nothing stops you from storing the amount also in a variable. This is quite typical in contracts which have multiple people sending it Ethers and you need to keep records of who sent and how much. But you can't prevent the Ether from being in the balance of the contract - unless you send it somewhere ...


0

A more modern style, as the last answer has gone a bit out of date: (tokenInAfterFee, tokenOutAmt) = spclContract.swap{value: msg.value}(_spctToSwap);


0

I also had problems getting Ether for Testnets because it was taking time and even by posting my wallet address to social media , i was receiving nothing. At the end, the simplest way i found, was using chainlink website for Kovan network. It was straight forward and fast without posts on Twitter or Facebook.. and i even received LINK :D https://faucets....


0

Without more info it's hard to tell what problem you're facing, but in general it might be worthwhile to try the Rinkeby testnet instead of Goerli. Here's the faucet for Rinkeby: https://faucet.rinkeby.io/


0

To initialize the contract you have to deploy it as stated in the OpenZeppelin-upgrades official doc. If you're using hardhat you should have : const { accounts, contract } = require('@openzeppelin/test-environment'); const [ owner ] = accounts; const { expect } = require('chai'); const { ethers, upgrades } = require("hardhat"); describe('...


0

Let's find out the answer empirically, with Remix. Take this contract: // SPDX-License-Identifier: Unlicense pragma solidity >=0.8.9; contract SingleConstant { uint256 internal foo; function getFoo() external view returns (uint256) { return foo; } function getFoo(uint256 newFoo) external { foo = newFoo; } } ...


1

Yes, it's possible. You can directly interact with UniswapV3 or Sushiswap router contracts to swap ETH to DAI and send that to a particular receiver address. Here's the example with Sushiswap (UniswapV2) router: payableAmount: ETH amount you want to swap path: [WETH, DAI] to: walletB


0

yes indeed. Here's a small example of how we do it: function mint(uint _parentTokenIndex) public payable { require(msg.value >= NFT_PRICE, "Not enough ETH sent."); require(!_assetExists[_parentTokenIndex], "The asset does not meet the unique constraint."); _mint(msg.sender, _id); _setTokenURI(_id, METADATA_URL); ...


0

The problems is that since solc v0.6.0 userIndex.push(userAddress) no longer return the length as in previous versions. You can fix the code with something like this userIndex.push(userAddress); userStructs[userAddress].index = userIndex.length - 1;


0

You cannot set up cron jobs in Solidity. Actually, Ethereum as a whole does not natively support this kind of operation. You have to use an automation protocol that runs on top of Ethereum, e.g. Gelato Network.


0

if your question is about making a scheduled execution functionality on the smart contract? I don't think it's possible currently. execution must be initiated by an account whether a smart contract or a user account with ether


1

Based on the topic, I'm guessing the owner is actually a function, and not a variable. Therefore you need to call the function, instead of just comparing it. Change your line to: require(msg.sender == owner(), "You are not the owner");


0

latest version truffle has an inbuilt debugger that can be used to debug state of a failed transaction. $ truffle debug <transaction-id> where <transaction-id> is id of the errored transaction, once debugger is launched follow the instruction to walkthrough and print variable state etc find out more here : https://www.trufflesuite.com/blog/...


0

Amplifying @Travis's answer. This line Original original; adds considerable size to SecondContract because it contains Original. That's a separate issue that can be solved with an interface. SecondContract doesn't require the complete bytecode for Original. That is repetitive and unnecessary. It only needs the function signature and address of the instance ...


2

I was facing the same issue on Windows 20H2, I tried to use npm install -g ganache-cli But did not work for me uninstalled and reinstalled many times. After that, I've checked my node version which was 12.xx and it was the problem. I've upgraded it to 14.18.0 and now the brownie works for me. https://nodejs.org/en/


0

It seems like my setContractURI function had one encodepacket too much. it looks like it is working now on OpenSea. function setContractURI(string memory contractURI_) public onlyOwner() { _contractURI = string(abi.encodePacked( "data:application/json;base64,", Base64.encode( bytes( ...


1

replace swapExactTokensForETHSupportingFeeOnTransferTokens with swapExactTokensForTokensSupportingFeeOnTransferTokens. They're both the exact same but the forETH version require the last member of the path to be WBNB and adds 2 lines of code to unwrap it before sending it to you


0

Assuming that your initial "deck of cards" is [0, 1, ..., N-1], the following should roughly work. I've made basically no attempt to compile or check this, but the underlying algorithm should be sound. Roughly, the approach is this: You start with a sorted "deck of cards", [0, ..., N-1]. This deck is implicit. To pick a random card, you: ...


0

I encountered this issue while confusing the private key with other keys and addresses. Using MetaMask, the correct private key can be found under "Account details > Export Private Key".


2

In Solidity was old method to get multi-return values from function through keyword var but is was deprecated in 0.5.0 if i'm not mistake Solidity allows functions to return multiple values. Here is an example to demonstrate this: { function a() returns (int a, string b) { return (1, "Hello"); } function b() { ...


1

You can able to check account balance by web3.eth.getBalance("your contract address")


0

I think smart contracts could be promising if the official currency is a government-issued cryptocurrency. I'm thinking that a government could first create a currency (call it the smartcoin). The smartcoin's design stipulates that the government can offer smart contract bonds (call them smartbonds) that work like this: The smartbonds give their holders ...


0

These are two separate questions, and this "thereby leading to some people not receiving tokens after payment" plus "I currently have a crowdsale contract" are unclear, as it sounds like you have a crowdsale that failed to distribute, not an airdrop that you pay to distribute. This: "after payment" should mean the blockchain ...


1

I know this is very old question, but as newer I also faced this problem. // SPDX-License-Identifier: GPL-3.0 pragma solidity >=0.6.0 <0.7.0; abstract contract Feline { function utterance() public virtual returns (bytes32); } according to doc this is way of declaring abstract function.


1

This is because IUniswapV2Router02.sol inherits IUniswapV2Router01.sol. Therefore you may think of Router02 interface as an extension of Router01 interface with all of its functions.


0

All these functions are using unsigned integer, uint, So the value can only be positive. In the other hand, msg.value / tokenPrice There are more chances that your value will be decimals represented in WEI but it could never be less than 0. If for a reason the result is negative. your code will revert with underflow error. Because a uint can't be negative. ...


0

Im pretty sure super refers to the contract right before the caller contract in the inheritance tree. Not sure what would happen in the case you're describing. Id suggest testing to find out what happens. If it doesnt check for both maybe make TimedCrowdsale inherits CappedCrowdsale?


0

I am not sure about doing mutation in modifier tho. The following case for example. modifier updateReward(address account) { rewardPerTokenStored = rewardPerToken(); lastUpdateTime = block.timestamp; rewards[account] = earned(account); userRewardPerTokenPaid[account] = rewardPerTokenStored; _; } function stake(uint _amount) external ...


1

b.x = new uint[](0); // will that be a dynamic array in storage? As for now it's not. It's an array of length 0. It could be dynamic but you will still need to know the length of the array on creation. The (0) represent the length of this array. Therefor you should probably use something like; b.x = new uint[](incomingArray.length); so this array will be ...


1

I think it's supposed to be used for meta-transactions. You can find similar examples that OpenZeppelin implemented that was also designed to be used this way. To support native meta transaction, OpenSea inherits NativeMetaTransaction contract that execute another function on itself (on behalf of the user with a signature), which will make the msg.sender ...


0

You should create a smart contract for managing it. Then transfer the ownership of your ERC token to that contract so that the smart contract can mint your token. When someone tries to buy your ERC token from your manager contract, it should mint the ERC tokens and transfer them to the sender. Let me know if there is anything unclear to you.


1

While the answer from @Paddy looks correct, it screws up the length of _returnData before passing it to abi.decode. The screwed up length is much bigger than it should be. Hopefully abi.decode will just ignore extra bytes after the decoded string, but it would be better not to rely on this, so here is cleaner version: function extractRevertReason (bytes ...


1

You can use a simple for loop. Like this: function test() public view { for (uint i; i < entityStructs.length; i++) { address firstAddr = entityStructs[i].entityAddress; } } You can manipulate the values inside the loop as you want.


0

I had the same issue and by doing following, my error disappeared. The syntax change in pragma is giving error. just Change pragma solidity ^0.4.20; to pragma solidity >=0.4.20;.


0

I think this is better handle with better contract design. Instead of handling buy/sell transaction variables one-by-one, you can have a struct defining an escrow transaction. Something like: struct escrowTx { uint256 TransactionID; address Seller; address Buyer; bool Executed; ... } Then each escrow transaction is just a new instance of this ...


0

Well, you can encrypt it with whatever encryption you want, and store it as a string (or bytes). That way the address will not be visible in plaintext in the contract. The obvious downside is, since the contact can't decrypt the data, the contract has no idea what the underlying address is and it can't utilize that address in any way. Furthermore, if the ...


0

Someone explained the solution elsewhere. The issue was not with the code, rather in the way you use remote contracts in Remix: even though you are adding an established contract, you have to select the compiled contract that is at that address.


0

yes you can. You can make a transaction to ethereum to change the atribute of the nft like name 'Charmander' to 'Charmeleon' or other stuff. Doing It is way cheaper than burn the nft and mint a new one (I dont knoww haven't test it but high chance it is).


0

You need to encode the data by using FunctionEncoder.encode Before checking the result you need to check for errors. If an error (for example a contract error) is returned the result will be null and you will get the the error you described. Do something like this: Function function = new Function("nameOfFunction", ...) Transaction tx = ...


1

First, be sure that you have defined the instance of the contract correctly. Then try to use async/await correctly in your orders in terminal. Finally, give this page a read : "https://www.trufflesuite.com/docs/truffle/getting-started/interacting-with-your-contracts"


0

Nobody can have zero address. To be more precise given an address, it is impossible to find the private key correspond to that address. If anybody can do it then the whole world will collapse not just blockchain but the whole modern society as we know it. So you don't need to check the zero address because nobody can have it. Zero address is just a place ...


0

For the first 2 question, here is what I know: Yes and no, when you create a new contract, you send the bytecode of that contract to the ethereum so everybody will know about the contract so you can store the contract bytecode elsewhere with geth. So technique the bytecode is always on the ethereum through the contract creation transaction, but you will ...


0

From BEP20 documentation What is BEP20? A token protocol on BSC which is compatible with BEP2 and ERC20. It extends ERC20 and contains more interfaces, such as getOwner and decimals. BEP-20 compliant doesn't require any support for Pancakeswap.


Top 50 recent answers are included