New answers tagged

0

do you have an example of this finished product on github?


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 ...


1

NFTs are auctioned in various ways on various platforms. An auctions could theoretically be completely centralized - an owner says they're taking bids until a certain time, potentially even off-chain, and at the end of the time, the bidder informs the winner they have won, accepts their payment, and sends the NFT. There wouldn't be much you could do with a ...


1

By default, a contract without a payable function can't receive Ether. However, there are some exceptions, or tricks, on how it's possible: https://ethereum.stackexchange.com/a/63988/31933 But for normal usage, you need a receive payable (https://docs.soliditylang.org/en/v0.8.0/contracts.html#receive-ether-function) function in the contract. So the minimum ...


1

You can do this: constructor() { foo(); } function foo() public { ... but you cannot do this: constructor() { this.foo(); // external call to non-existant function } function foo() external { foo() is indeed available as an external function from functions but the constructor doesn't "write" the code until the end, so foo() does not exist ...


2

Here are the key topics and keywords to search for: Generally: "Whitelist" the tokens you DO accept. Use the "approve and transferFrom" pattern. Decide if your token list will be static or changeable and consider the "Ownable" pattern to control access to the maintenance function if the latter. Otherwise, consider populating ...


1

IMHO, it's not a terrific example for teaching. Hash functions are very useful for validating information and they are used to prove things with Smart Contracts as well as on the blockchain itself. For example, block transactions are hashed which is a sort of fingerprint for authentic blocks. Previous blockhashes are part of that functions, so it forms a ...


1

I'm not sure why it's written that way in the docs. If you have the contract source code (as is the case here), you can freely create new instances of it. It's just a matter of whether you want to do that (or whether you should do that). My guess is that the doc is trying to say that "don't accidentally create a new instance of it when you just wanted ...


0

I have found an answer to my question. Thanks to this question and its comments. Before the major versioning gets to 1 i.e 0.x.x the caret ^ and the tilde ~ act in the same way. Visit this site, npm semver calculator, to experiment and learn more.


2

Yes, it is possible. Moreover that technique was already used against MakerDao, read https://forum.makerdao.com/t/urgent-flash-loans-and-securing-the-maker-protocol/4901. It can be fixed by requiring funds to be locked for a period of time longer than a block.


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 { // ... } } ...


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

You cannot specify a data location for number types. Simply replace this bit: uint memory _age with uint _age and this line: studentfiles(studentCount) = studentFile(studentCount, _studentName, _age); with studentfiles[studentCount] = studentFile(studentCount, _studentName, _age); and your contract will compile. As the error mentions, you can only ...


1

Depends on the exchange, but I doubt a trade is a new contract in any dex (decentralized exchange). A trade is typically a call to a certain function in a contract. That function executes the trade by calling some background contract functionality to calculate ratios and so on. If you wish to trade token A for token B, the trade looks typically something ...


1

Any guesses as to what in the hell type of a contract is paying out 40+ Ether at a time upon request A contract that is selling NFTs. If you look at the top (internal) transaction in that list (this one), you'll see a series of transfers. If you look at the Input Data field, you'll see the called function: Function: acceptBid(address _originContract, ...


1

Yes. In fact that’s how the Chainlink nodes operate. When calling buildChainlinkRequest and sendChainlinkRequestTo In the any API call feature you are actually emitting events that chainlink nodes look for. You can modify this to have a node looo for your specific event, but you need to use a node that uses an ethLog initiator instead of runLog. Check out ...


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; ...


1

You could have a contract which stores the addresses of each of your deployed contracts. Perhaps with mapping(bytes32 => address) public contract_addresses; It could have a function exposed for adding new records to that mapping, which you could make a call to in the constructor of each contract. Just remember to make sure the deploying address is ...


1

It does not work because as you said A and B addresses are not stored in B and A. The exemple you linked his about compilation and importing, and cannot works in test (infinite loop and no setup for a and b values). Something like that should do the trick for the setup but be aware that the infinite loop is still present contract InterfaceOfA { ...


0

i think i've found my answer but i ddnt test it yet. ...using interface and make an object from it and point it to the deployed contract's address. should be something like: interface deployedContract { function a() external returns(uint); } contract myContract { deployedContract dContract = deployedContract(0x000...00); uint ...


3

Yup, it does cache the numbers, even without the optimizer enabled! When passing 65535 (max uint16) as the parameter x, it costs 1003 gas to run either foo or bar. I ran this test with Solidity v0.8.3 on Remix. contract PowersOfTwo { uint256 internal constant TWO_POW_1 = 2**1; uint256 internal constant TWO_POW_2 = 2**2; uint256 internal constant ...


1

Deep down, an array is a mapping with range-bound keys. The most expensive aspect is the SSTORE operations and SLOAD operations which are the same in both cases. An array has additional steps (operations, so gas) to check that row is not out of range. A dynamic array is significantly more expensive because each push overwrites the length and range checks ...


1

If I understand correctly, you want that Bob proves that he is Bob, the owner of the NFT, when he makes a request to your server. The server wants to be sure that the request was sent from Bob and not someone else pretending to be Bob. The answer is yes, you can do this. To prove that he is indeed Bob, Bob should send a transaction to a smart contract that ...


1

In a recent post by Vitalik Buterin on Reddit he mentions several proposals that were considered in the protocol design but didn't make the cut. One of the proposals called delayed calls would introduce an opcode ALARM that allow a contract to execute in a future block. The proposal has several use cases but it was discarded due to time constraints.


0

It looks to me like it's returning the result just fine. If you're just wondering why the 0 is there, that's just the index of the return. If you were to return two objects like the example: function foo() external returns(uint, uint){ return(7,12) } Then the output would look like: decoded output: { "0": "uint: 7", "1": &...


1

It is unlikely anybody is willing to invest unless you have what takes it to execute it before the ICO. Because it is unlikely you do not know what you are doing and you fail and people lose their money. Even better you first build a working minimal viable product, then raise money.


2

You can include in your contract a key that only your app know, but... the Ethereum net make public the smart contracts code, then I dont know how you can avoid decrypting the communication between the app and the contract. Maybe if you dont verify the contract the code of it stay hidden. Other solution I can think is to create 2 contracts, where the second ...


0

Contracts evaluate signed transactions from users. They don't evaluate how the user composed the transaction or signed it. From a human perspective, it is helpful if a UI guides the user, composes the transaction and offers it for signing but, typically, this is of no concern to the contract. Contracts need to guard their internal integrity regardless of ...


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 }


0

Just to add to Rob's answer, I have found a library for a linked list in Solidity, though it comes with the disclaimer that I have not audited the code, nor have I yet had the opportunity to check how gassy it is: https://vittominacori.github.io/solidity-linked-list/


2

I think the question is too general in nature so the only possible answer is "it depends." The right way to structure the contract depends on what the contract is supposed to do. Deployment is a specific step in the lifecycle of the contract. What needs to happen at that stage? For example, it might be unacceptable to have an instance of the ...


2

Nothing like that exists because the obvious solution would involve considerable, variable gas cost to reorganize data at rest. There are patterns that combine mappings and arrays to create iteratable sets with random access. If it is to be sorted or organized in any particular order then one needs to code for that as well. Have a look over here for some ...


Top 50 recent answers are included