New answers tagged

0

function createProduct(string memory _name, uint _price, string memory _info, uint _quantity) public payable { This function signature has _price in ethers. So try changing the default units to the ether from Wei and send the appropriate price of the product. Mine is working [vm]from:0x4b0...4d2dbto:Buyproduct.purchaseProduct(uint256,uint256) 0x1df......


0

Here is the full contract that worked for me: pragma solidity ^0.5.0; import "./ERC721Full.sol"; import "./Counters.sol"; contract MyContract is ERC721Full { using Counters for Counters.Counter; Counters.Counter private _tokenIds; constructor(string memory myName, string memory mySymbol) ERC721Full(myName, mySymbol) public { } ...


2

Both immutable and constant are keywords that can be used on state variables to restrict modifications to their state. The difference is that constant variables can never be changed after compilation, while immutable variables can be set within the constructor. From the docs: State variables can be declared as constant or immutable. In both cases, the ...


0

The immutable keyword was added to Solidity in 0.6.5. State variables can be marked immutable which causes them to be read-only, but assignable in the constructor. The value will be stored directly in the code. From the docs: Variables declared as immutable are a bit less restricted than those declared as constant: Immutable variables can be assigned an ...


1

In your case there is no interactions between smart contracts. HelloWord.getSaluto() is actually an internal call, i.e. your smart contract calls its own function, just defined in base smart contract. Real interaction scenario would look like this: contract A { uint state = 0; function foo (uint x) public returns (uint) { return state += x; } } ...


0

While fractions are not supported natively by Solidity nor EVM, they could be emulated at reasonable cost. First thing you need to decide is what kind of fractions to use. Most common types are: simple, fixed-point, or floating point. Fixed- and floating- point fractions could be decimal (base 10), binary (base 2), or use come other base. Then you will ...


0

Well you can either calculate it externally or calculate it inside the contract. If you calculate externally you lose some of the benefits of decentralization (you'll lose the trustless nature as everyone has to trust you to input the right value) but you'll save in gas costs. If you want to calculate it in the contract you will have problems with the ...


0

Floating-point arithmetic is not supported in Solidity. In other words, x / y yields the floor of dividing x by y. As a bonus fact, x ^ y yields the bit-wise XOR of x and y. In order to claculate x to the power of y, you need to use x ** y. But again, this only works for integers.


0

Delete all files in the build\contracts folder. That fixed the error for me.


2

It's probably easiest to accomplish with a modifier which you add to each function. So something like this: pragma solidity 0.6.0; contract Example { bool _isActive = true; modifier checkActive() { require (_isActive); _; } function do1() checkActive public { // do something } function do2() checkActive ...


1

You could get rid of it in the function-call as well, i.e.: (uint128 stakeId, address behalf) = abi.decode(userData, (uint128, address)); But I suppose that would just beat your purpose to begin with. So the quickest workaround which comes to mind is to just add a dummy reference: (uint8 _, uint128 stakeId, address behalf) = abi.decode(userData, (uint8, ...


0

In order to store a string and access it, you can do the following: pragma solidity ^0.6.5; contract SimpleStorage{ string storeddata; function set(string memory x) public{ storeddata = x; } function get() public view returns(string memory){ return storeddata; } } A few notes on the differences between this code and ...


3

You seem to have missed the explanation at the bottom of that example: Both f function overloads above end up accepting the address type for the ABI although they are considered different inside Solidity. Translation to English: While B and address are considered by the compiler as different types, for the ABI they are identical (B is essentially ...


1

Answer from the OpenZeppelin Community Forum: https://forum.openzeppelin.com/t/proxy-that-routes-to-multiple-logic-contracts-based-on-param/2595/2 Is there a reason that you can’t use OpenZeppelin upgradeable contracts and just have a single logic contract? See Upgrading Smart Contracts Learn guide. I would suggest looking at this first to see if it meets ...


0

It is possible to do something like this: struct Location { string city; string street; uint time; } struct Product { uint id; string name; mapping (uint => Location) locations; } mapping (uint => Product) products; Then the implementations will be like: function viewLocation(uint _productID, uint _location) public returns(...


0

The method you described would work. A cost optimization would be to log an event whenever a user sent their tokens to the contract. This would remove the requirement for both an array and a mapping. When attempting to read the data off-chain (for the swap to the other token), you can simply read each event that occurred on that contract. An example would be:...


0

The second function returns execution to the previous function. So for example if you have something like this: pragma solidity 0.6.0; contract Example { address owner; event SomeEvent(); event OtherEvent(); function doSomething(address _someowner) public { transfer2(_someowner); emit SomeEvent(); transfer1(...


0

I found this to be helpful. The answer also has a link to the official docs.


0

Use await this.auction.contractBalance().call().


0

// Web3 v1.2.6 const Web3 = require('web3'); const web3 = new Web3(new Web3.providers.HttpProvider('http://localhost:8545')); const contractJSON = require('/path/to/build/contracts/Contract.json'); const contractInstance = new web3.eth.Contract(contractJSON.abi, 'CONTRACT_DEPLOYED_ADDRESS'); async function getTimeFromContract() { const time = await ...


1

You can't. There is no way to know how many entries there are in a mapping. If you need to keep tract of the mapping's elements you can use a separate array which holds extra information about the mapping elements


0

In solidity the hash is generated using: function generateHash(param1, param2, ... paramN) public pure returns (bytes32) { return keccak256(abi.encodePacked(param1, param2, ... paramN)); } In web3.js v1.2.6, the same hash can be generated using: web3.utils.soliditySha3(param1, param2, ... paramN); Example: > const web3 = require('web3'); > ...


0

The problem was Node version. so npm install was technically not installing the package since it depends on scrypt and node-gyp (both are having issues with node 12 and higher) if you are facing the same problem, downgrade to node 10.xx or simply do not use this package and deploy your contract using remix.


1

You can use a clone factory smart contract to do so. https://github.com/optionality/clone-factory/blob/master/contracts/CloneFactory.sol An example of your ERC721 factory would be pragma solidity ^0.6.0; import "./clone_factory.sol"; import "./erc721.sol"; contract ERC721Factory is cloneFactory { address payable template; constructor(address ...


0

It depends on how you have deployed your contract. If it was deployed correctly then you can call. einstance.functions.getTime().call() where einstance must be instance of web3._utils.datatypes.Contract. Little brief on how to install your contract Step1: Compile your contract and get the bytecode and abi. You can install a specific version of sold ...


0

You can pass the strings to the constructor instead hardcoding them (if I understood your question correctly). pragma solidity ^0.5.0; import "./token/ERC721/ERC721Full.sol"; import "./drafts/Counters.sol"; contract MyContract is ERC721Full { using Counters for Counters.Counter; Counters.Counter private _tokenIds; constructor(string myName, ...


0

Sorry, i can't leave a comment because i don't have enough reputation points. Have you checked if the revert is caused by an out of gas ? Your contract is executed directly by you (as a msg.owner) ? because if you execute the function from another contract you are the tx.origin, so msg.owner is the in the middle. Make a function that return msg.owner and ...


0

I'd suggest to upgrade to solidity 0.5. The constructor have an invalid syntax error. It should be something like this function TokenERC20(uint256 initialSupply, string tokenName, string tokenSymbol) public { totalSupply = 250000000 * 10 ** uint256(decimals); // Update total supply with the decimal amount balanceOf[msg.sender] = totalSupply; // ...


0

Two obvious approaches spring to mind. PUSH An off-chain process would listen to Token A's event log to compile a list of holders and then proactively send Token B. Since Token A is constantly in motion, either a cut-off time or a continuous process and the requirement should be clarified. A notable disadvantage of this approach is the centralized gas ...


1

To import from a tag or branch use /blob/<tag> import "https://github.com/OpenZeppelin/openzeppelin-contracts/blob/v2.4.0/contracts/math/SafeMath.sol"; It is not mentioned explicitly in the documentation https://remix-ide.readthedocs.io/en/latest/import.html but it works.


1

The expression address(this) will evaluate to the same value in every function which uses it, when called on a given instance of the contract. Of course, when such function is called on different instances of the contract, this expression will evaluate to a different value for each instance.


0

you are using old api on new version of solc. here is the implementation. const lotteryPath = path.resolve(__dirname, 'contracts', 'Lottery.sol'); const source = fs.readFileSync(lotteryPath, 'utf8'); var input = { language: "Solidity", sources: { "test.sol": { content: source } }, settings: { outputSelection: { "*": { "*": ["*"] ...


1

OK, I've realized that I can simply use this, without having to rely on gasleft(): pragma solidity 0.4.26; import './IERC20Token.sol'; contract Tester1 { address public to; uint256 public value; function transfer(IERC20Token _token, address _to, uint256 _value) public returns (bool) { to = _to; value = _value; return ...


0

You have to encode arguments with abi.encode and bytes with abi.encodePacked. Compiles with Solidity 0.4.0. contract DeployContract { function deploy(bytes _bytecode) external returns(address addr) { bytes memory bytecode = abi.encodePacked(_bytecode, abi.encode(msg.sender)); assembly { addr := create(0, add(bytecode, 0x20),...


1

There is no reasoning in your question for not using this: contract IA { function setNumber(uint n) public; } contract B { IA public a; function setContract(IA _a) public { a = _a; } function setNumber() public { a.setNumber(10); } }


1

Public key recovery of an ECDSA signature uses the ECRECOVER operation and costs 3000 gas. If you have the public key you can derive the address and afaik a keccak operation(sha3) costs 30 gas.


0

The code uses indexed parameters. In case of a string parameter it is not stored in the event log as is, but its keccak256 value instead. See solidity documentation about that https://solidity.readthedocs.io/en/v0.6.4/abi-spec.html#encoding-of-indexed-event-parameters. It is not possible to retrieve the value of an indexed string from the event log. As an ...


1

I tried the deployed contracts and they work as expected. KombuchaProxy shouldn't update Kombucha contract. It updates its own storage. The whole idea of a proxy is that it contains the data and point to another contract that has the code. To test this in Remix I instantiated Kombucha contract at KombuchaProxy address. Now you can execute Kombucha ...


1

TL;DR receive is a new keyword in Solidity 0.6.x that is used as a fallback function that is only able to receive ether. receive() external payable — for empty calldata (and any value) fallback() external payable — when no other function matches (not even the receive function). Optionally payable. Long Answer Solidity 0.6.x introduced the receive ...


1

You can simply view the code of upgradable contracts already deployed to mainnet: BUSD Token AMPL Token USDC Token REP Token TUSD Token SNX Token JRT Token


1

This is a bug in either web3.js OR the node that you're communicating with. It happens only if the require statement includes an error-message. It happens when the node is Infura, but not when the node is Ganache. Note that your function shouldn't be returning false in either case. Either it returns true, or the function-call reverts.


0

The Error: TypeError: Type address is not implicitly convertible to expected type address payable. receiver = _receiver; ^-------^ The compiler reports such errors whenever you assign a variable of type address to a variable of type address payable In Solidity: The address type comes in two flavors, which are largely identical: address: Holds a 20-byte ...


0

This is a bug in either web3.js OR the node that you're communicating with. It happens only if the require statement includes an error-message. It happens when the node is Infura, but not when the node is Ganache.


0

That's just how web3.js processes the data before handing it over to your application. It is quite useful in the sense that you can access it directly by name, for example: const ControlNumber = myEvent.returnValues.ControlNumber; And also iterate it sequentially using the __length__ field (which you forgot to mention): for (let i = 0; i < myEvent....


0

This is normal behavior. You can just now access your data either by index key returnedData.sender or index iteration returnedData[0] If you want to trim/supress this data, you have to do it on the client layer.


1

That BN stands for BigNumber. It's a JavaScript framework for representing..well...big numbers. If you simply console.log a BigNumber it will give you such internal data of the single BigNumber, such as those length and words. Those are not trivially interpretable. So what you should do it simply .toString() it to get the actual number. It really is just ...


1

I'd like to return to the first issue: Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at http://localhost:8545/. (Reason: CORS request did not succeed). If you're trying to connect to localhost:8545, I assume that you're trying to connect MetaMask to a local node. Essentially, MetaMask is trying to connect to ...


1

That statement doesn't make much sense. In solidity 0.5 gas is the remaining gas. With sub(gas, 34710) it would seem they want to send all the remaining gas minus 34710 to the called contract, but from the comment it appear they want to send at least 34710. The error is trying to say that in solidity 0.6 you have to use gas() as it were a function. I will ...


1

Gnosis Multisig Wallet was implemented under solc v0.4.x. If you tried to compile your code, then you would know why this is not possible: _confirmations.push(ownersArr[i]); Because the compiler would to you: TypeError: Member "push" is not available in address[] memory outside of storage. _confirmations.push(ownersArr[i]); ^------...


Top 50 recent answers are included