Hot answers tagged

28

First, let's save both of those files in the same directory and run solc --optimize --bin MetaCoin.sol. The output is: ======= MetaCoin ======= Binary: ...


27

Here is a snippet of D using delegatecall on E from Difference between CALL, CALLCODE and DELEGATECALL contract D { uint public n; address public sender; function delegatecallSetN(address _e, uint _n) { _e.delegatecall(bytes4(keccak256("setN(uint256)")), _n); // D's storage is set, E is not modified } } contract E { uint public n; address ...


14

To add, it's possible to manually link contracts (if you wish to deploy both library and contract together.) The simplest way is just to replace all occurrences of the placeholders with the address. An example, taken from my own (modified) code: var linkedMetaCoinCode = metaCoinBytecode.replace( /_+TestLib_+/g, testLib.address.replace("0x", "") ); ...


14

You can try Nethereum, it's available on Github. It is currently in alpha stage, and provides an RPC client API similar to Web3. Including: JSON RPC methods Contract deployment Function call / transaction sending (encoding / decoding parameters) Event filtering creation (encoding of parameters / decoding of topics) Linux / OSX support as it is developed ...


10

Browser-solidity is able to import library code from GitHub (importing from Swarm is on the way). E.g. you can write: pragma solidity ^0.4.0; import "github.com/ethereum/dapp-bin/library/stringUtils.sol"; contract test { function foo() returns (bool){ string memory a = "hello"; string memory b = "world"; return StringUtils....


9

A library is similar to a contract and you can use an abstract contract to declare its interface and then invoke (like Calling function from deployed contract). contract ECVerify { function ecverify(bytes32 hash, bytes sig, address signer) returns (bool); } contract Foo { ECVerify ecv = ECVerify(0x3bbb367afe5075e0461f535d6ed2a640822edb1c); ...


9

There isn't a way to change the ABI, since it is directly compiled in the source code. However, you can call functions manually if you don't mind breaking the type security of your contract. For example, if your contract named foo is calling the bar method of another contract bazz, and you are concerned about the method name changing, you can implement ...


8

Currently the standard library isn't fully set up yet, but in this case what you would do would be to link your contracts to your library's address (and hopefully map it to a named registration in that case). That will be implemented in the future and it will be much easier when that time comes. Until then however, you will have to do it manually, ie the ...


6

You want to use link.call.get() Also, a better way to do it is just to mark the get function constant. Then it will do a call by default. This does a simulated transaction call and returns the value. Otherwise, you're doing an actual transaction, and getting the return value. Dealing with strings can be tricky; they aren't value types, like bytes32, but ...


6

Ok I've figured out what is happening. In a library the use of the internal accessor to a function will inline that function into the calling contract's bytecode. In my contract, all my library functions were modified as internal so there was actually nothing left to compile and no ABI to export. This can be illustrated in Remix with the following example:...


6

Here's a sketch of a way to do it, but be warned this isn't for the faint of heart. Create a base contract with a global variable that will point to the current library. Create the contract (the host) inheriting from the base contract. Also create the first real library for it. Create a library (the proxy) inheriting from the base contract. (This will ...


6

In the first instance your contract is inheriting from the TestLibrary contract, and therefore you can perform the operation with increment(_base) or super.increment(_base). Additionally, if the function is public (which it will be by default), then that function is viewable and usable on your contract when it is deployed. In the second instance, you are ...


5

Have your code changed as below function inc(Data storage self) internal{ self.a[0]=+1; } Note the storage part of it. Please understand the concepts of Internal Types for variables and In memory types


5

Summary To deploy your library and contract code using geth, you will have to: Deploy your LinkedList library code and note the address it is deployed to. Replace the __LinkedList___...___ text in your Array code with the LinkedLibrary deployment address and deploy the code. Some other alternatives: Create an SSH tunnel between your remote server and ...


5

SafeMath's functions are all declared as internal. That means that the library doesn't actually have to be deployed, as the functions are 'inlined' by the compiler: their code is just copied from the library code to the calling function. An inheritance relationship like contract A is B, A is a B. In case of SafeMath, that does not hold if I just want to ...


5

Since the error message is saying there are 5 results coming from the right-hand side of the assignment, that implies that the function hashToMarket() is not returning a Market object, but it's actually returning the five pieces of a Market object together (a, b, c, d, and e). EDIT: That function is the default getter for a public mapping, which does indeed ...


4

Found the issue. Do not use underscore characters when naming a solidity library as the solidity linker cannot process this character correctly during deployment.


4

So it turns out there is an issue in the current release...they have been notified. The work around is to use the full path. I also didn't realize that the full path is case sensitive.


4

You can't import Truffle libraries to any contract in Mix. The thing is that Truffle use your imports to build an only .sol file, so the compiler doesn't import anything. If you want to debug your imports in Mix you should copy your libraries code in the same file than your other contracts.


4

There are some guys who are running geth on Android and iOS. you could find the libs and the apk project. But seriously, you need to wait the light protocol client because it is a bit insane to use a full client (Many Go of storage + so many writes that it will use battery and storage longevity). Look this: Android Ethereum on Android: https://www.reddit....


4

You are indeed correct. Plugging this code into Remix, and looking at the disassembly gives: .code PUSH 60 contract Consumer {\n functi... PUSH 40 contract Consumer {\n functi... MSTORE contract Consumer {\n functi... CALLVALUE contract Consumer {\n functi... ISZERO contract Consumer {\...


4

Deploying duplicate code is wasteful, and what you want is completely reasonable. At the moment, there is realistically no way to achieve this. You could compare the bytecode of all deployed contracts on the chain to discern if it is already deployed but this is probably more 'expensive' (at least from a time investment POV) than simply redeploying. You ...


4

See the Solidity Natural Specification (NatSpec) format github for details Solidity contracts can have a special form of comments that form the basis of the Ethereum Natural Specification Format. For a usage example please check here.


4

It seems that Remix does this automatically. Library code: pragma solidity ^0.5.10; library Foo { struct F { uint256 x; } function foo (F storage f) external { f.x = 123456789; } } Main contract code: pragma solidity ^0.5.10; import './Foo.sol'; contract Bar { Foo.F public f; function bar () public { ...


3

If you think about it, the library can not know the variable names of the calling contract. The compiler must fail. What you can do is pass the variable through the interface. In the background, no transaction calls need to be done and the param can be passed by-reference instead of by-value...


3

Microsoft came up with plugin for smart contract development using Solidity in Visual Studio. https://visualstudiogallery.msdn.microsoft.com/96221853-33c4-4531-bdd5-d2ea5acc4799/ You can develop Ethereum smart contracts using Solidity and deploy to Testing network of Ethereum Blockchain, where you will get around 1000 dumy ETH to test your application.


3

This is a pretty general question for this site, so it might get voted down. It's clear you've done some homework and you're considering how all the parts of an upgradable system of contracts would fit together. Yes. It's a name resolver that could be used to resolve a contract address. That affords developers with the option of appointing new user-...


3

Try pragma solidity ^0.4.7; library lib { bytes1 public constant flag = 0x01; function g() constant returns (bytes1){ return flag; } } contract test { bytes1 x = lib.g(); }


3

Libraries don't have storage. Their methods are invoked with the delegatecall opcode, which means that they are run in the context of the caller. In a library, this points to the calling contract. If you want to work around this, create a storage contract with the globals and pass it to every library method you want to use the globals in.


3

Library may define and use modifiers, but it cannot export them. Modifiers are compile-time feature, kind of macros. Modifier code is substituted by compiler to every method that uses this modifier. For complex modifiers this may be a problem, but you may always move modifier's logic into a function (library function, probably), and then refer to this ...


Only top voted, non community-wiki answers of a minimum length are eligible