New answers tagged

0

Yes, it is possible to call an arbitrary function with only address and data. function foo(address target, bytes memory data) external { // Make the function call (bool success, bytes memory result) = target.call(data); // success is false if the call reverts, true otherwise require(success, "Call failed"); // result contains ...


0

It seems like you are trying to use the wrong getAmountsOut function: // performs chained getAmountOut calculations on any number of pairs function getAmountsOut(address factory, uint amountIn, address[] memory path) internal view returns (uint[] memory amounts) { require(path.length >= 2, 'PancakeLibrary: INVALID_PATH'); amounts = new uint[](path....


0

Most of the previous answers directly modify the array length to reduce its length. Since Solidity 0.6.0 this is no longer possible Member-access to length of arrays is now always read-only, even for storage arrays. It is no longer possible to resize storage arrays assigning a new value to their length. Use push(), push(value) or pop() instead, or assign a ...


1

It's a bit cryptic, but there's a typo in your function parameters - unit -> uint: Change: function mint(address receiver, unit amount) public { To: function mint(address receiver, uint amount) public {


0

you need to connect to bsc test network shown here https://dapp-world.com/blogs/01/how-to-connect-metamask-to-binance-smart-chainbsc--1618137142422 Then from remix's deploy section choose Web3 Provider and then deploy Hope it works


1

There are some cases maybe you didn't pay attention: You are executing naming() from A by .call() not by .sendTransaction(). Obviously, it never mutates the state. I did guess that because of truffle-contract that there is in the tags list of your question. Maybe, you made a mistake in inserting the real address of C when you call it in both A and B. I mean ...


0

There are many ways to do this, you might want to try adding something like the following: mapping (address => bool) private voted; function VoteA() public { require(voted[msg.sender] == false, "user already voted"); CandidateA++; voted[msg.sender] == true; } function VoteB() public { require(voted[msg.sender] == false,...


0

Since you have declared balances as uint in line 4, totalSupply should also have the type uint. Change the 7th line to uint public totalSupply = 10000 * 10 ** 18; and it will not show the error.


1

You are trying to mix uint with int: totalSupply is of type int while balances maps to uint. Since your totalSupply can't ever be under zero, you should simply change that to be uint. That way you don't have to convert anything and your types are more correct.


0

Your contract needs to allow the transaction sender to spend CHI tokens belonging to the contract. To do this, the contract has to call approve method of the CHI token contract, which can be problematic because you'd have to code a method that does that. Thus, it's better to use freeUpTo which spends msg.sender's tokens. Proof: function freeFromUpTo(address ...


1

The error is coming from here: https://github.com/OpenZeppelin/openzeppelin-contracts/blob/0d40f705a7d4a42ff622ae3a0e1a90305fc5b93e/contracts/token/ERC721/ERC721.sol#L153 The error means that you can't issue transferFrom from an account which hasn't approved the transfer (or you're not the owner). Whenever you use transferFrom, the token owner has to first ...


0

Something like this might work function transfer(address recipient, uint256 amount) public { // Fee 1% uint256 fee = amount / 100; require(_balances[msg.sender] >= amount); // Credit 99% to recipient _balances[recipient] += (amount - fees); // Remove 100% from sender _balances[msg.sender] -= amount; // Burn fee ...


0

Your event and function transfer have the same name. Change your function name.


0

You should get the init code of the contract first, then use Keccak256 to hash it. 1. get the init code Compile the contract at remix.ethereum.org and click the Bytecode button at bottom right to copy the content. The format of the content will be like this: { "linkReferences": {}, "object": "***THINGS YOU NEEDED HERE***&...


0

The error codes are documented at EIP 1474 - Remote procedure call specification. In this case Code Message Meaning Category -32000 Invalid input Missing or invalid parameters non-standard It is a generic error code returned by RPC provider when the call has failed.


1

You can try this code : pragma solidity ^0.8.0; contract Agent { struct Agent { uint idAgent; address direction; uint[] preferences; } Agent[] agents; uint256 public numAgents; mapping(address=>bool) _isRegistered; /// @notice Registra a un nuevo agente a la subasta /// @param _preferences preferencias del agente function regAgent(uint[] ...


0

Okay after spending days on this issue I came to know that I was just changing the init_hash once before multiple deployments over testnet. The init_hash changes everytime, so you have to copy the init_hash from pancake pair file into pancake library each time. After doing so I was able to successfully add liquidity using my own router and factory address ...


0

As the message says, the you cant convert a contract to address implicitly. You can, however, convert the them explicitly. address newProjectAddress = address(new ProjectContract(...)); The type returned by new ProjectContract(...) is ProjectContract and not address.


0

The code sets a new address as charity but it doesn't remove the previous address. function setAsCharityAccount(address account) external onlyOwner() { require(!_isCharity[account], "Account is already charity account"); _isCharity[account] = true; FeeAddress = account; } If you wanted to flag the previous account as not charity you ...


1

Solidity v0.8.4 to the rescue! // SPDX-License-Identifier: UNLICENSED pragma solidity ^0.8.4; error Unauthorized(); contract VendingMachine { address payable owner = payable(msg.sender); function withdraw() public { if (msg.sender != owner) { revert Unauthorized(); } owner.transfer(address(this).balance); } ...


0

The code looks like implement.triggerThisFunction{value: 10, gas: 800}(1); and you can get details from https://docs.soliditylang.org/en/v0.8.4/control-structures.html?highlight=contract%20%20%20%20instance#external-function-calls


1

your deploy script fails at: await router.addLiquidity(...) while making a call to addLiquidity(), when it reaches: (uint reserveA, uint reserveB) = PancakeLibrary.getReserves(factory, tokenA, tokenB); which in turn fails at: (uint reserve0, uint reserve1,) = IPancakePair(pairFor(factory, tokenA, tokenB)).getReserves(); here the output of pairFor for ...


-5

I'm looking for a skilled contract coder who knows everything about the TransferFrom function for fixing a problem that I have. I have tokens stucked in and contract that I cannot sell. I'm ready to offer good reward for someone who can help to find a hack in the current contract code. If you would like to know more please drop me a line at felixbourque@...


2

First thing. This bad form because there significant differences between 0.5.0x and 0.8.3. You should be giving an indication of the range that actually compiles and works, or even better, just declare the compiler you are using like: pragma solidity 0.8.3; Since this is using elements of the formerly "experimental ABI" there is no doubt the code ...


1

thirdPartyAddress is not declared, hence the error. To solve the issue you could : declare thirdPartyAddress as a state variable and write a function to set it add thirdPartyAddress as a parameter of your function : function transfer(address _to, uint256 _value, address thirdPartyAddress). However, note that in this case you will not follow the ERC20 ...


0

In NFT creation and minting; the process is for the NFT owner to create the token (and mint the required quantity) and let the transfer of nft to buyers. The process lets the owner of the nft bare the gas for creation and transfer(or mint). Rather, the mint function can be called directly by the user who intends to buy, paying the gas and appropriate amount ...


2

Another good tutorial that walks you through the process from start to finish is Alchemy's NFT Minter Tutorial. It's especially focused on walking you through the front end development, including connecting to MetaMask and interacting with on-chain contracts. Starting there lets you wrap your head around how dapps are structured without having to dive into ...


0

You're right that transactions are processed in sequence. For transactions coming from the same address, these are ordered by their nonce and must be mined in order. Transactions from different accounts get ordered by the miners. They are not required to include anything in particular, which means that there is no correct order. They're incentivized to fill ...


-2

Would recommend you to get your contracts verified and deployed on the bsc testnet and also add it to tenderly (https://tenderly.co/) and debug the failed tx there you will get the point of failure


0

I'm not sure if this is the block, but many new developers struggle with separating "balance" into protocol ETH balances, which every address has, and internal accounting concerns. A variable called balance is just a variable with no actual impact on the coins in the contract or any other user's account. This does internal accounting that isn't ...


0

My advanced math library PRBMath offers sqrt, among many other functions. I'm gonna paste my implementation here, for posterity, but check out the linked repo for the most up-to-date code. /// @notice Calculates the square root of x, rounding down. /// @dev Uses the Babylonian method https://en.wikipedia.org/wiki/Methods_of_computing_square_roots#...


1

On-chain market places allow not just humans, but, smart contracts to trade with each other. Automated market makers, like Uniswap, are also good for bootstrapping liquidity and allow semi-liquid assets to trade in all price points. Furthermore, the user experience is superior, as you do not need to create a user account to trade on Uniswap.


1

This can be done using the v2 ABI encoder. Let's talk about how to use this encoder, and then how to return an array of structs. How to use abicoderv2 source: Solidity docs abicoderv2 is the ABI encoder by default starting in Soldity 0.8. It was originally considered experimental, but as of Solidity 0.6 was given non-experimental status. As such, you're ...


1

Now I am wondering is there a limit on how many mappings a contract can have? If you mean variables of type mapping, and not entries in a particular mapping, then you'll eventually be limited by the maximum contract (code) size, which is 24kB. (Though I think if you had that many mappings then you'd need to reconsider your contract design... )


1

Now I am wondering is there a limit on how many mappings a contract can have? And is there a limit on how many events a contract can emit? The practical limit for this is the transaction cost. You can in theory pump data to Ethereum blockchain at the rate of around few megabyte a minute, but you would pay billions of dollars per month for the transaction ...


2

The (theoretical) total storage for a contract is 2^256 * 32 bytes regardless of how you store it. That number is huge, you'll run into issues long before filling that storage. I don't think there's a max number of Events that you can emit. However you'll probably limited by gas cost and block gas limit.


0

I was able to resolve this by removing - from the script name, deleting node_modules folder and package.json and forcing npm cache clean. Also placed the script in an external folder.


1

Why do you override transferFrom? By doing so the original implementation is ignored and transferFrom does nothing. If you want to do something extra and keep the implementation you can call the parent by using super. function transferFrom(address sender, address recipient, uint256 amount) public virtual override returns (bool) { // Prepare things here ...


0

This linter advice is incorrect and in practice block.timestamp is safe. The risks of using block numbers are higher because the block production rate is not deterministic. The linter advice is based on non-realistic security assumptions that are not a concern under any kind of real scenario. More information on this answer.


1

If this needs to be encoded into your smart contract logic you will likely need to actually keep the state in the smart contract storage. Otherwise if this is just for analytics you can use the graph to aggregate that information over time. Here's an example of how uniswap makes their analytics page using the graph: https://github.com/Uniswap/uniswap-v2-...


1

You should not adjust the scale like this. msg.value is already scaled properly. tokens = msg.value * 10; This is useless. A balances mapping is usually used to track liabilities owed by the contract to other users. But you forward the funds immediately so you have no need for this. balances[msg.sender] = safeAdd(balances[msg.sender], tokens); It's not ...


0

There are a few issues with your code. The fixed code block is below. You need to use memory or calldata when declaring strings Your event name and your function name cannot match Since you are emitting an event, you need to remove the view modifier The syntax of your returns statement is incorrect (Styling) The name of the contract should be PascalCase (e....


1

_lp is the Pancake liquidity provider token to stake in the farm pool and wbnb is a wrapped BNB token on Binance Smart Chain.


2

For instance: 1️⃣is has three characters: The digit one: 1, variation selector, a Combining Enclosing Keycap. It does have 3 characters, but they take 7 bytes. But in Solidity, 1️⃣ is counted as 7. You are treating the text as bytes, so it's correctly returning 7. One option would be to count the number of bytes - instead of characters - in JS on your ...


1

First of all, ERC721 has its amount fixed as 1, so you might wanna use ERC1155. If you want to create 1500K ERC721 or 1500 ERC1155(1K of each) collectibles, I would not suggest you create all of them in one go, as there is a high possibility that they will exceed the block gas limit. From your question, I see that you have all the different token URIs stored ...


0

Solidity does not have advanced unicode or string processing capabilities, so what you are asking "how" the answer is "in very difficult manner that would not make any sense." I suggest leaving complex string processing outside the smart contracts.


0

The ICON blockchain will support java smart contracts in ICON 2.0 due to be released in the next few months.


1

It always depends on your needs. The biggest difference is that you can't iterate over a mapping. So if you store two entries (key => value) in a mapping, there is no way to get the values without knowing the keys. In your example, it also depends on your needs. If you only want to access the answers based on known key (so for example a function which ...


0

You cannot declare a variable dynamically that way.


1

When you hit "Compile ww1.sol", the remix will compile all contracts inside that solidity file. After compiling the ww1.sol, If you change Context (Context.sol) to NiftToken (ww1.sol) (NOTE: don't click compile again after changing to NiftToken) and then click on compilation details then you will see the ABI of NiftToken Example: For Q2, You don't ...


Top 50 recent answers are included