library ECVerify
is deployed on 0x3bbb367afe5075e0461f535d6ed2a640822edb1c on the Ropsten test net.
How do I call function ecverify(bytes32 hash, bytes sig, address signer) returns (bool) {}
in that library contract from a contract foo
.
Ethereum Stack Exchange is a question and answer site for users of Ethereum, the decentralized application platform and smart contract enabled blockchain. It only takes a minute to sign up.
Sign up to join this communitylibrary ECVerify
is deployed on 0x3bbb367afe5075e0461f535d6ed2a640822edb1c on the Ropsten test net.
How do I call function ecverify(bytes32 hash, bytes sig, address signer) returns (bool) {}
in that library contract from a contract foo
.
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);
function callEcv(bytes32 hash, bytes sig, address signer) {
bool b = ecv.ecverify(hash, sig, signer);
// handle b
}
}
The main feature of a library is that its code is executed in the context of the calling contract. library ECVerify
does not access storage so the simple code above works, but it treats and executes just like any non-library contract.
The other case is a library that accesses storage, then your Foo
contract should have the storage defined correctly: the library will be writing to your contract's storage.
Solidity docs have an example of a library Set
, which needs a mapping(uint => bool)
. This means that your contract should have this mapping. Whenever the library writes to the mapping, it writes to the mapping in your contract.
Here's:
library Set {
// We define a new struct datatype that will be used to
// hold its data in the calling contract.
struct Data { mapping(uint => bool) flags; }
...
and an example of defining the mapping in Foo:
contract Foo {
Set.Data knownValues;
Another example of linking and calling a library is given in What are the steps to compile and deploy a library in Solidity?
ecv.ecverify(hash, sig, signer)
is a library call and has to be executed as delegatecall?