New answers tagged

0

In most cases, I would avoid require in a check like that to make it safe to check. if(duration < min) return false; if(duration > max) return false; return true; A caller that is considering a state change can require(contract.durationIsValid()); That is easily incorporated into a modifier if that is wanted, and the intricacies of the logic would ...


0

So you have a smart contract with a function which accepts a string parameter. When you send a transaction to that contract targeting that function with some string parameter the transaction will eventually get mined and included in a block. You can't control to which block it gets added. So, if you send a transaction with a string to a smart contract (...


0

I prefer this syntax: module.exports = function(deployer, network, accounts) { deployer.then(async () => { await deployer.deploy(A); await deployer.deploy(B, A.address); //... }); }; since it's way more readable when you have lots of contracts. See also: https://github.com/trufflesuite/truffle/issues/501#issuecomment-...


1

Your code doesn't make much sense. The function either returns true or throws an exception, so what exactly is the point in returning a single possible value? One could simply conclude that if the function hasn't thrown an exception then the answer is true. With regards to the actual question about using require: Revert (embedded in require) is useful ...


1

I will try sort out some misconceptions in a way that hopefully helps. This doesn't do what you think it does. uint y = x + 1; // just to give it a couple pico seconds Intuitive ideas about temporal time don't apply. Consider how transactions are run redundantly by every node now, and in the future (syncing). What is the start time in temporal terms? It's ...


1

IMHO restricted access to getters is a pointless contract design. It is always possible to access every value. Indeed, every full node has full access necessarily because they need that to process contract functions. If the contract doesn't "permit" access it is really only inconveniencing a determined adversary. Here's a way to circumvent the contract's ...


0

ERC-20 (a.k.a. EIP-20) defined standard interface all token contracts are supposed to implement. Your contract does not implement this interface, so your contract is not compliant. However, your contract is not a token contract (it does not introduce its own tokens, but just uses existing tokens), so your contract is not supposed to implement ERC-20 ...


1

You can simplify your setup to only 2 contracts. I've taken the liberty of editing the contracts a bit to make the testing a lot easier and more specific. You can copy paste them in Remix and test yourself. contract A { B b; constructor(B _b) public { b = _b; } function() external payable { (bool success, bytes memory ...


0

So many basic errors: When stating the return-value type in the function declaration, you should be using returns, not return There is no such type unit; you probably meant uint You forgot to declare 2 out of 3 functions as view; while this will compile successfully, it will make your life harder when you call these functions from the off-chain You named ...


1

It is good treat it as a state change and apply the checks, effects, interactions pattern. This will prevent services that watch the event log from falling victim to re-entrance style attacks. It also makes transaction event logs produced chronologically sensible. Consider three contracts in a chain. You might get 1) Bang! 2) You're 3) Dead or something ...


1

In terms of runtime: It doesn't matter because either the function will be executed to completion and all of the state-changes (including the emitted event) will be written into the blockchain, or the function will revert before completion and none of the state-changes (including the emitted event) will be written into the blockchain. In terms of ...


0

Since web3.eth.compile.solidity has been deprecated, thus, we need to deploy our smart contracts outside of geth. This can be achieved by using solc. Deploying contract using solc: npm i solc Create a file for deploying: deploy_Hello_World.js const fs = require('fs'); const solc = require('solc'); const Web3 = require('web3'); const web3 = new Web3(new ...


1

Since this part doesn't return anything: .then(hash => { assert.equal(hash.valueOf(), hash_test, "Not returning the correct address"); console.log("THIS"); }) No other then is executed passed this point, and the it completes successfully. I'm assuming that you have two additional its in your test, hence the printout 3 passing. Aside from that, ...


0

Hope this helps someone. The error was in the ABI or in the Bytecode. I replaced it and it worked.


0

If you want to get financial data, and don't want to wait a block (or more) and pay GAS and then ETH fees with something like Oraclize, you can get stock, crypto, ETF, etc data from the OrFeed.org's smart contract for free and instantly from your smart contract. For realtime prices from Dexes like Kyber and Uniswap: uint price = orfeed.getExchangeRate("ETH"...


0

The idea is to separate your functionality in two functions. Here foo will fail and revert and bar which will delegatecall to foo in the same contract. contract A { uint256 public counter = 1; event DelegateCallFailed(); function foo() public { counter += 1000; // Make to always revert revert(); } function bar()...


1

No language on Ethereum is Turing complete, because the EVM isn't Turing complete. There is a maximum gas limit, which means no operation can run for unlimited time or use unlimited space. Vyper just makes that more clear than Solidity does.


0

Reply to @jazzhole answer. the repo got updated , here is the updated link


0

You can declare the oracle contract interfaces in Vyper, then call them like you would any other contract: https://vyper.readthedocs.io/en/latest/structure-of-a-contract.html#contract-interfaces


0

The question is not clear and your intent is not easily surmised from the code. I suggest rephrasing and focusing on one thing at a time. The first thing that jumps out is the effect of throw, now called revert in more current compilers. It will reverse everything that preceded the statement so it will always appear that nothing happened except gas ...


1

The value of msg.value is always the amount of Ethers sent with the (internal) transaction - if contract A calls contract B it may pass along less Ethers than msg.value and then msg.value in B is the new amount. So, yes, the whole amount will be taken from msg.sender (or, more specifically, from tx.origin - the EOA who initially started the transaction). ...


0

In the migrations directory you have to reference the deployments for any new contracts. In this case that is the file 2_deploy_contracts.js: var ProofOfExistence1 = artifacts.require('./ProofOfExistence1.sol'); var ProofOfExistence2 = artifacts.require('./ProofOfExistence2.sol'); module.exports = function(deployer) { deployer.deploy(ProofOfExistence1)...


0

To begin with, change this: deploy(Ticket, 0) To this: deploy(Ticket, "0x0000000000000000000000000000000000000000") Since 0 is not a valid address value when sent from web3.js.


2

1) Miners only choose which transactions they include in a block. They basically choose the transactions which have the highest gas price because that way they get the best rewards. They don't analyze the transaction contents in any way as that doesn't matter much for them. Nobody decides whether a smart contract is good or not. Smart contracts are ...


0

power on raspi / open terminal download geth / move geth to bin wget "https://gethstore.blob.core.windows.net/builds/geth-linux-arm7-1.9.7-a718daa6.tar.gz" tar -xvf geth-linux-arm7-1.9.7-a718daa6.tar.gz; cd geth-linux-arm7-1.9.7-a718daa6; sudo mv geth /usr/local/bin/; initialize a geth node geth --datadir privatenet init genesis.json edit the /etc/rc....


1

Keep in mind uint previousBalances = balanceOf[_from] + balanceOf[_to]; could already have been overflowed when checking the assertion later. So the transfer will fail even if its correct. But thats unlikely bcs it requires that both sender and recepient have more than uint256 tokens/eth together. Only then it fails.


0

This is a good function to know how much ether a contract has function getMyBalance() public view returns (uint) { return address(this).balance; }


0

I'm working on this as well. There is an opcode called extcodehash. It says The EXTCODEHASH of the account without code is c5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470 what is the keccack256 hash of empty data So I think there is a possibility to check isContract by using this extcodehash combined with the c5d2460186f72... function ...


0

Following my comments to your question (please read through), here is how you can fix your code: In the contract: event ExamAdded(string hash); function addExam(string memory hash) public returns (string memory examProfessorHash) { // save the exam hash and link it with the professors address professorsExam[msg.sender] = hash; emit ExamAdded(...


0

Your addExam function is not a view or pure function and it modifies the state of the contract. Therefore it returns a transaction hash and not the real function return value because the transaction needs to be mined before it can give you the result. Your test fails because you assert that the return value is the desired address when the return value is ...


1

The users who is spending tokens is the one to approve the contract. The contract cannot appoint itself to spend tokens from someone else's wallet. Hope it helps.


0

Function transfer_money takes one input parameter. So you cannot call transfer_money() without passing it.


1

You can check the length of the bytes of the value. You do this by converting the string to bytes and checking the length. If it is greater than 0, than it exists. Your new code would be as follows: if(bytes(professorsExamHash).length == 0){ return "No exam hash asociated with this professor address"; }


3

Two options: Change memory to storage, otherwise you're just creating a local Document object rather than referencing your documents mapping. Declare Document memory document at the beginning of the function, then initialize the fields of this object (as you are already doing), and finally set documents[_hash] = document at the end of the function.


1

selfdestruct requires a parameter of type address payable. What is the type of owner in your code.? If you're using the OpenZeppelin Ownable.sol, it's not payable. You could cast it, but since you've already required that _owner is equal to owner, and the former is payable you should simply be able to write selfdestruct(_owner); instead.


1

Everybody can execute run(), nobody can set started directly. Since started is public, a getter (but no setter) is automatically generated. Reinitialization of the smart contract is not possible, unless you define a specific function for this task.


0

It is possible using meta-transactions. The general idea is as follows: A user signs a transaction. This, itself, does not require gas and, strictly speaking, does not require metamask or any other "wallet". Your app can attend to it, and also issue public/private keypairs and ETH addresses for your users so that, from a user perspective, "it just works." ...


0

In Compound V2, borrow interest is paid back to the cToken contract such that all cToken holders have proportional claims to the underlying collateral at the current time. It's somewhat confusing based on the UI that Compound has provided, but basically the history of interest rates is irrelevant. Lenders "mint" cTokens (e.g. cDAI) by locking up the ...


0

yes, it possible to retrieve data from Ethereum platform. Solidity provides special function that are used to store and retrieve data from Ethereum network.


0

every contract should have a private key somewhere The private key exists in theory, but since the contract address is not generated by choosing a private key to begin with, the private key of that address remains unknown (and unlikely to be discovered under the current computation limits). it should be possible to send ether to it Only if it implements ...


0

You can't do it. It is not possible to write a contract that directly accesses the wallet of another user or the storage of another contract. So, you need a different approach. Consider users that give the contract authorization to manage a certain amount of money. That can include redistributing to other users according to the rules. Think about an ...


1

I wasn't sure which compiler you were using so I choose one at the high end of 0.4.x that supports constructor. You need to add public visibility to your id and name in anotherContract so they are visible. Contract names should be written out in CamelCase. pragma solidity 0.4.26; // be specific contract MyContract { address[] public childContracts; ...


1

Change line 4 to: address payable admin; Hope it helps.


1

Add the following functions in your contract, an then use them in your application: function getLength() public view returns (uint) { return publicData.length; } function getDataLength(uint index) public view returns (uint) { return publicData[index].length; } Usage example: const length = await datastorage.methods.getLength(); for (let i = 0; i &...


0

You are trying to connect to http://localhost:9545 while your node listens on port: 8545. Thus Web3 API connection was refused.


4

There is more to this than the question suggests so I'll just focus on the prose part of the question. Comments are not compiled into contracts, therefore there will be no record of them in the bytecode. You can, however, create a convincing record of the document contents and acceptance by the parties. Put the legal prose in a document such as a PDF and ...


1

Setting your function to external (in case it being called only through txs or other external smart contracts) can save some gas in certain scenarios. function myExternalFunction(bytes calldata mydata) external { // do some stuff } bytes will cost more than bytes32, because the length information itself is stored in a memory slot of 32 bytes. So in any ...


0

Change this: const option = await NumberConfigOptionDefinition.new( 'foo.bar.baz', accessControl, accessControl, validator ); To this: const option = await NumberConfigOptionDefinition.new( 'foo.bar.baz', accessControl.address, accessControl.address, validator.address );


0

When working with web3.js version 1.2.x, there is not .getData method. The solution I found was to estimate of gas of the .deploy() method, which effectively returns the cost of contract creation. The sequence of operations is: let contractJSON = // JSON compiled contract const contractABI = contractJSON.abi; const bytecode = contractJSON.bytecode; const ...


0

To do this in pure chai, you can use these two approaches: const expected = web3.utils.toBN('123.052'); const actual = await meta.getBalance.call(account_two); expect(actual).to.eql(expected); // compare to BigNumber or use strings: const actual = (await meta.getBalance.call(account_two)).toString(); expect(actual).to.equal('123.052'); Note that you have ...


Top 50 recent answers are included