New answers tagged

0

I raised this question to the OpenZeppelin forum and they quickly replied with the following feedback: It is a Beta release and there may be small breaking changes prior to the stable release. There isn’t documentation on this yet. To store & retrieve the URI, you can override tokenURI with your required logic. You only need to override _baseURI if you ...


0

The original poster was almost definitely working on an exercise from the book, or Udemy course, "Ethereum and Solidity: The Complete Developer's Guide". The course is quite outdated by now and most users will struggle to test the examples in Remix using the examples provided. I'm working through the course myself and found this repo very useful: ...


1

what does .div() do here? Divide. The contract you're looking at uses SafeMath.sol to protect against integer overflows.


0

In terms of naming convention, you would normally use capitalised words for your enum declarations and mixed case for variables. This Solidity guideline will help you. As per your specific case: enum Stage {Init, Reg, Vote, Done} Stage public stage = Stage.Init;


0

There're so many wrong stuff with this code: allMerchants is array of addresses and you're trying to push bytes32 variable to that array? Judging by the logic of the contract you want to save the initiator of the transaction here, so change that line to: allMerchants.push(msg.sender); You're trying to create instance of struct merchant, but the value of ...


0

You can't call usedTokens.push(_token) when creating a new merchat structure


0

msg.sender is either the account that signed the transaction or the contract that called your contract and it's created automatically. msg.sender cannot be faked and you can rely on it, otherwise Ethereum network won't be secure


0

Change either the name of the enum or the name of the public property of Stage type.


0

Just some random ideas in case it helps. I am not sure you can transfer tokens from an ERC712 contract to an ERC1155 one. If possible, there might be better ways, but I am assuming it is not the case. Therefore, the goal would be to find the cheapest way to create ERC1155 tokens and burn the ERC721 ones. Fortunately, you have the option to create ERC1155 ...


0

That contract doesn't follow the final ERC20 specification. The declaration for transferFrom doesn't return anything: function transferFrom(address _from, address _to, uint _value) public; The calling contract defines transferFrom returning a bool instead: function transferFrom(address sender, address recipient, uint256 amount) external returns (bool); ...


0

I found that smart contracts supporting IERC1155Receiver can receive ERC1155 tokens. https://docs.openzeppelin.com/contracts/3.x/api/token/erc1155#IERC1155Receiver


0

You can try to get pending transactions and calculate an average amount of gasprice. pending_transactions = web3.provider.make_request("parity_pendingTransactions", []) gas_prices = [] for tx in pending_transactions["result"[:10]]: gas_prices.append(int((tx["gasPrice"]),16)) print("Average:") print("-"*...


2

Just to add to Shane's good answer: In Python and other languages this variable type is called a tuple. In Solidity they're not considered a proper type, but can be used as a shorthand. See the docs: Destructuring Assignments and Returning Multiple Values


2

If I understand what you are asking, you are wondering what (bool success, bytes memory data) are. In Solidity, a call (or delegatecall) returns two values that describe the status and result of the call. The first return value is a bool that states whether a call was successful or unsuccessful. The second parameter is the return data of the call, usually ...


4

No issue. It is economically, not technically constrained. You might say the market runs out of money before the EVM runs out of space. You can write as much data as you and your users can afford. Someone pays for the gas to do it. The insert, overwrite, and delete costs within a mapping are scale-invariant. There are some non-obvious, possible effects at ...


0

This part is suspicious. ["Inbox.sol"].Lottery You read Inbox.sol, why do I access "Lottery" instead of "Inbox"?


0

The ERC721Metadata specification specifies the following function declaration: It doesn't matter how you implement it. function tokenURI(uint256 _tokenId) external view returns (string); In the previous version of openzepplin, it was implemented as a mapping because it used a method of storing tokenURI by tokenId. In the latest version, the baseURI and ...


0

Do you need to use a newer Solitude compiler? If not, stick with the pragma that works for you, by getting rid of the caret and specify a fixed version.


0

The comment is right, removing the [] fixes it. stateStorageForNumbers_[tokenIDs[i]] = _numbers[i]; ^ This works.


0

If you look through the comments on OP's question, it becomes clear that there was an issue with the ABI the OP was originally using (h/t @Ismael) - perhaps it was copy pasted incompletely, or maybe there was some file corruption. By regenerating the ABI, the code worked as expected.


2

For all those who would fall for Dark Lord's honey pot or future similar ones. I remember asking Etherscan to also list internal transactions that do not transfer Ether. They have now implemented this feature, that you can activate here by toggling "advanced". This honey pot relies on: The Start function being called in the clear with question and ...


2

For people to follow along... I called contract's Try function by passing the same string which was passed in Start function. The Start function was called in this transaction, and passed the following arguments, together with the 20 ETH seed: 0 _question string What two things you can never eat for breakfast? 1 _response string lunch and Dinner ...


0

Create the cards array containing random numbers (466,35,77,2466,....) in the NFT's constructor or some initialize method. When rewarding the card just use the first element from the cards array then remove it. Still not sure how much gas would consume such a deploy or initialize of the NFT smart contract


0

Trying the Solidity code on my local environment running go-ethereum, it worked just fine. It may sound dumb but after you altered the smart contract code and re-deployed it, did you add files to the storage? Because it's a new smart contract, new address, new storage. Myself, I got rid of Ganache because it was acting different that the production network (...


0

This is probably because you are establishing the web3 connection only in your index.js; therefore, it is not accessible when you navigate into other pages. You can either use Redux to have global variables accessible from any page, or share data between components through properties. ** UPDATE: ** In case it helps, this is the way I normally connect to web3 ...


0

Contracts don't have any concept of an "owner" by default. Contracts only have the functionality you write into them. A quite common scenario is that functionality is added, which creates the concept of "owner" and assigns it to the contract deployer. This is for example what the OpenZeppelin Ownable contract is for: https://github.com/...


1

You have to approve the DAI transfer NOT in you smart contract, but in the DAI's contract by the owner of the DAIs; otherwise, it is your contract trying to approve itself an amount of DAIs belonging to another user. You can go to the DAI's smart contract in Kovan and do the approval there from the user who wants to send DAIs to your Uniswap contract.


1

With the increased gas price and the increased ETH price nowdays you can see more and more developers trying to optimize their smart contracts as much as they can to reduce tx costs. I wrote this article about saving transactions costs about 2 years ago, but I do still believe it is valid even now. Check it out.


0

The function web3.eth.sendTransaction can be used to transfer directly to the contract receive function. web3.eth.sendTransaction({ from: USER_ADDRESS, to: CONTRACT_ADDRESS, value: AMOUNT_IN_WEI, gas: GAS_AMOUNT }) .then(function(receipt){ ... });


0

While I did not find a solution on why the .on() method is not working, I found a workaround using the transaction's receipt. The following code describes this workaround: let tx: ContractTransaction = await myToken.connect(accounts[0]).transfer(accounts[1].address, 1); let receipt: ContractReceipt = await tx.wait(); console.log(receipt.events?.filter((x) =&...


0

For ERC20 the usual approach is to require the user to approve your contract. You have to do something like this from the front end. // USDT parameters const erc20Token = new web3.eth.Contract(USDT_ABI, USDT_ADDRESS) // Contract that will receive USDT const recipient = new web3.eth.Contract(RECIPIENT_ABI, RECIPIENT_ADDRESS) // Require user approval await ...


1

You could use try/catch if exchange is in another contract. try anotherContract.exchange() { // succeeded } catch (bytes memory err) { // failed } If it is in the same contract you could use this.exchange() just be aware that it will change msg.sender and requires exchange to be public or external.


1

One approach could be through events: You can emit an event whenever there is a transfer from/to your token smart contract from/to an external account. Afterwards, you can retrieve all the related events off-chain without any cost Any other alternative on-chain might have significant gas fees.


1

You are referring to ERC20-based token balances (DAI, USDT), therefore, you can't set such as balances without defining the related contracts. However, it is not too complex. You can create a mock for these tokens, for instance, a DAI.sol contract: pragma solidity ^0.6.12; import '@openzeppelin/contracts/token/ERC20/ERC20.sol'; contract Dai is ERC20 { ...


0

If you want to compile from one version and upwards, you need to include symbol ^: pragma solidity ^0.4.18; However, this will only take up to version 0.4.26, which is the latest from 0.4, but not versions above (0.5, 0.6...). As described in the official documentation: pragma solidity ^0.5.2; A source file with the line above does not compile with a ...


1

Some remarks: Usually commit and reveal phases are separated such that no commit message are allowed after certain point. That way if someone send a reveal message an attacker no longer can send a commit with the answer. The committed message must include something extra that an attacker cannot alter like msg.sender or something he cannot guess like a ...


1

This is because the ether passed to matchBet() was added to the previous amount of ether. Write a non-payable function like matchBet(uint betAmount) to compare.


1

You cannot directly iterate a mapping or enumerate the keys that exist because all keys in a hash table do definitely exist ... it's just that most of them have 0x0 values. You can only solve the problem by creating a structure that uses a mapping for effective random access and an array for iteration. It's up to you to maintain the structure. Have a look at ...


2

Question 1: What do you think ? Am I right about Solution above ? Agree. To prevent front-running, use a factor like msg.sender in the hash function so the front-runner can know the secret and still be unable to use that knowledge. For example, consider a piggy bank with a secret word that releases the money. If the withdraw function uses (pseudo) hash(...


0

Are there any other solutions Can't say definitively that there isn't another solution but the core problem boils down to this. If it is possible for the contract to use any form of deduction whatsoever to deduce the result then the result is calculable by everyone which clearly defeats the secrecy goal. This is the generalized problem that commit/reveal ...


1

When you declare an enum, each element is assigned an integer sequentially. In your case: rock = 0 paper = 1 scissors = 2 Not sure why you want to pass this enum in the constructor, but if you want to implement a commit-reveal scheme, you should have at least commit() and reveal() functions where you pass the player's move, and you probably need also ...


0

If the malicious owner sees the hash you submitted and submits the same hash, your solution breaks down. Commit-reveal can be used only if it is hidden when committing and open when revealing. When committing, there are so many people who have committed it, so it should be difficult to know who's right. A suitable example of commit-reveal is to answer a quiz ...


1

Since gas usage is a factor outside the contract, it cannot be calculated within the contract. The account that called the function (EOA) pays for gas. It is not paid by the contract.


1

Work in the following order. Use the USDT contract's approve function to allow the user USDT to be sent to your contract address. Write a payment function in your contract. The user calls this function. In the payment function, the USDT corresponding to the payment amount is transferred to your contract.


1

Using the ERC20 standard as it is cannot solve this problem. Refer to the link below for a proposal to change the ERC20 API to prevent this problem. https://docs.google.com/document/d/1YLPtQxZu1UAvO9cZ1O2RPXBbT0mooh4DYKjA_jp-RLM/edit Commit-reveal is a solution to a front running attack, but its use is slightly different. Even if you commit-reveal your ...


0

You can do this in 2 transactions first approve for zero tokens, wait for that transaction to go through approve again for 50 tokens.


1

If the MAIN contract inherits from RandomNumberConsumer making editDna internal should be enough. // Declare contract as abstract abstract contract RandomNumberConsumer is VRFConsumerBase { // Forward declaration function editDna(uint randomN, uint carId, bytes32 requestId) internal virtual; constructor() VRFConsumerBase(..) public { .. ...


0

Web3 has a estimateGas method which can be used to get the amount of the gas used. Then either use web3's getGasPrice or use an external service, like https://ethgasstation.info/api/ethgasAPI.json, to get the current price of a gas unit. The final step is to do the math: gas cost = estimated gas * gas price (be aware of WEI/GWEI conversion)


0

Javascript doesn't support integers of arbitrary length yet. You need to pass addresses as a string. const MyContract = artifacts.require("MyContract"); module.exports = async function (deployer) { await deployer.deploy(MyContract, "0x587242da6dde74aA602AF3595d271333421c7E20"); };


1

It looks like your contract doesn't have LINK funds to perform the random number generation. Note this require in function getRandomNumber(): require(LINK.balanceOf(address(this)) >= fee, "Not enough LINK - fill contract with faucet"); In the same documentation from this example, there is an explanation on how to fund this contract with LINKs ...


Top 50 recent answers are included