New answers tagged

0

Update 1: You have to write the argument like: string memory ownername. Update 2: Use uint256 for indexing variables in arrays. Update 3: You don't need to initialize the dogarray Here the the updated code: pragma solidity ^0.5.1; contract MyContract { struct dog { string name; string ownername; int8 age; } dog[3] ...


0

The error is in this line Customer storage customer = customers[uName]; Your customers mapping maps address to the Customer struct whereas you are trying to map a the string uName to the struct. There are different ways you can receive customer data. Get an address as a function parameter and return the name of the customer at this address. Use pragma ...


0

You might need to remove the truffle build in your directory rm -R build/


0

You can try this: // SPDX-License-Identifier: GPL-3.0 pragma solidity >=0.7.0 <0.9.0; contract Credentials { uint256 _numberOfProviders; mapping(address => bool) public _owners; uint256 _numberOfOwners; constructor(address[] memory owners) payable{ _owners[msg.sender] = true; _numberOfOwners = 1; for (uint ...


0

I am not sure how .at(addr) works in front-end but you can connect to an already deployed contract in the following way using web3: myContractInstance = new web3.eth.Contract( contractABI, contractDeployedAddress ); I hope it helps.


1

Just increase the allocated gas from 5000 to 10000 in the call inside the testCallBar function and it will work. In fact, setVal is more expensive than foo as it updates a state variable (bar).


2

You can accomplish something like this using staticcall: contract Test { function test (bool transaction) public view { if (transaction) { (bool success,) = address(this).staticcall(abi.encodeWithSignature("foo()")); require(success, "Contract call failed"); } } function foo () public { // ... } } ...


0

As far as I know, you cannot access the storage of a contract from another contract directly. Given contracts C1 and C2, C1 can only access the storage of C2 by invoking a method on C2 that returns data from C2's storage. You can use the following ways to accomplish this: Inherit contract A in B and then call contract's A method . Add a function in ...


1

the answer is no. it will not compile view functions cannot modify the state and the compiler check this and give you back TypeError: Function declared as view, but this expression (potentially) modifies the state Tested it with solidity 0.8.3


0

Basically, you need to deploy the contract to your local hardhat net just as you would to any other. That means currently you have to set up a deploy.js like in the official hardhat tutorial. I'm assuming you followed the official tutorial at least until Chapter 7: Deploying to a live network and e.g. @nomiclabs/hardhat-ethers is already properly installed. ...


0

This line makes no sense: (bool success, ) = recipient.call; value; amount ;(""); Change to: (bool success, ) = recipient.call{ value: amount }(""); Note that using raw calls - i.e. .call() - isn't recommended. The author of the code seems to know this, as they've explicitly added the avoid-low-level-calls comment to disable the ...


2

From release 0.11.1 auto-migration of files is turned off, so you will need to migrate your files manually to be able to see them again. See the release notes, here -> https://medium.com/remix-ide/remix-release-0-11-1-cdb3063327d "Automatic migration of files to Workspaces has been turned off. So you cannot see your current files unless you migrate ...


0

Lots of things work. I would suggest a default style to help keeps things organized and untangled. contract A is initializing the inherited variable b through its constructor If you mean: contract A is B { constructor() { b = something; // var inherited from A } } I would instead do: contract B { bool public b; constructor() { b = true; ...


0

In my case (I'm using Azure blockchain service), I modified my contract file but forgot the build and deploy it again to my Azure blockchain service. Instead, I jump to the truffle exec command directly. So, after I re-do those two missing steps, everything works fine.


0

You have to inherit the ChainlinkClientinto your contract. Change your contract line from: contract VersionControl { to contract VersionControl is ChainlinkClient {


1

I was giving wrong input to a bytes32 array. The correct way was to convert each value to 0x followed by a 64-character hexadecimal string. Thus "this is token uri", ["maham",67,"Silver","first token","image url"] became ["0x6d6168616d000000000000000000000000000000000000000000000000000000","...


2

The problem is that you populate the params array with uint and string arguments whereas it only accepts bytes32 values. Basically a bytes32 is an hexadecimal of length 64 without the 0x prefix (1 byte = 2 hex characters). To convert something to bytes32, convert it to hexadecimal first, then add as many 0s as needed at the beginning to get a hexadecimal of ...


2

First, I don't see why you link a token ID with a supply value. When you transfer a token, you use the tokenId then what will happen with the supply? Will it go entirely to the new owner? Then you declare a public (not a good idea, keep it private) Cards[] public card which you overwrite when creating a new card (card = Cards({supply:_supply, description:...


0

Okay, I figured it out. In the video I put in one of my comments, I was forgetting to tell Remix to use injected web3 instead of Javascript VM. However, the more important thing I learned, was that you have to fund the "contract factory" with LINK tokens so that it can create the individual contracts and transfer LINK to them. Thanks @...


0

Your first problem is in line 1, ^. This doesn't really disambiguate while compiler was actually used so you need to know that or have to try to them all. Normally, you still need to know about compiler optimization runs but the search area is smaller. Source code verification works by compiling the code you provide, with the parameters you specify and then ...


1

To access an array item people[index] with an index it has to be a valid position, ie index >= 0 and index < people.length. In your example people[0]._firstName = _val will fail if people is empty. If you first call addPerson it should work.


1

It appears the current version sort contracts by the file's name and within the same file contracts are sorted by name. - Welcome to Remix 0.10.10 -


0

The classic way of dealing with decimals involves upscaling and downscaling. This doesn't necessarily involve the DS_Math library, we'll try and circle back to that. Upscaling and Downscaling While it is true that Solidity doesn't have decimal values, you can upscale a value by multiplying it by some constant, then multiply by your decimal value as a whole ...


0

You contract actually cannot be compiled. You need to replace studentList by shoppinglist in the shoppingloop function. The getitemcount method always returns 0 because no item address is saved in the shoppinglist array. Just add shoppinglist.push(itemID); in the addshoppingitem method to fix this. You should also check the itemId address not to overwrite ...


2

The answer is made by @Ismael this.executeOrder(orderId);


0

The error message indicates that the calculation is working as is. Your actual problem is that 'theCalc' is declared in a such way that expects an integer to be returned ('returns(uint)').


1

You need to create the init_code_hash using your newly deployed Factory contract. This address hard-coded in Uniswap's Github repo is specifically for their deployment in Ethereum networks. In your UniswapV2Factory.sol code, add the following piece of code. bytes32 public constant INIT_CODE_PAIR_HASH = keccak256(abi.encodePacked(type(UniswapV2Pair)....


1

Typical logic operators can be used in Solidity. So: if (price == StopOrder || price == LimitOrder) { do stuff }


0

You need to add a pragma statement at the beginning of your file. See the official documentation for more information. As an example: pragma solidity >=0.7.0; contract Test { // Contract logic goes here }


1

Based on @alberto's suggestion in the comment, I changed the return type from int128 to bytes memory and re-wrote my function like this: function doPow(int128 x, uint256 y) external pure returns (bytes memory) { int128 result = ABDKMath64x64.pow(x, y); bytes memory encodedResult = abi.encodePacked(result); return encodedResult; } Now the result ...


0

I think I met the same problem, although forking the mainnet with hardhat. This set it right when using web3py: preparedTx = myContract.functions.myFun(*params).buildTransaction({ 'chainId': 31337, 'gas': 700000, 'gasPrice': web3.toWei('1', 'gwei'), 'nonce': nonce, }) Note the gasPrice set low and chainId switched ...


1

You can transfer value in Remix by adding the amount in section value within the "Deploy & Run transactions" section. Note that just on the right of this field, you can select the units in ether, wei, etc. By the way, this error message you get is quite generic. I've had it for a number of multiple reasons not always related with payable ...


0

A failed transaction cannot emit an event, because failed == nothing happened. This is inconvenient for debugging. You can check assumptions with require() and emit a reason. Reasons are observable when the require() expression evaluates to false. There are many reasons why a contract can fail. Some are deliberately caught and emit a reason but others are ...


0

In the case you have pending transactions there are two fast options to solve the issue: Increase the Gas you spend for the transaction with the same account (do this in your truffle configuration or in your deployment code). Especially when the reason are pending transactions with the same nonce. Change the account for the deployment. Pending transactions ...


Top 50 recent answers are included