I want to copy a struct from Contract A into a struct in Contract B using Contract C. Is it possible in solidity ??
We can do it for single variables.
You can unpack a struct and return multiple return variables from a call:
contract Foo {
/**
* Define pricing schedule using milestones.
*/
struct Milestone {
// UNIX timestamp when this milestone kicks in
uint time;
// How many tokens per satoshi you will get after this milestone has been passed
uint price;
}
Milestone[] milestones;
function getMilestone(uint n) public constant returns (uint, uint ) {
return (milestones[n].time, milestones[n].price);
}
}
For the underlying issue, as far as I know struct data storage is internal to a contract and not portable between contracts.
Mikko is correct about struct data not being portable between contracts.
A struct is an example of a dynamically sized type that can only be passed around internally. I've seen some discussion among the devs about possibly removing this limitation. For now, the interface can only consist only of arguments with fixed size.
As long as the struct is public you can call it from another contract. You just import the original contract and then define its address and make calls to it to fetch struct data.
import "./example1.sol";
contract example2 is example1 {
address public example1Address = 0xc3c695f67520a07b7745a7e6fb7b560f77d6154b;
function setOriginContract(address _example1Address) public onlyOwner returns(bool) {
example1Address = _example1Address;
return true;
}
//to use the remote contract
function exampleFunction()public returns(uint){
example1Contract example1 = example1Contract[example1Address];
return example1.Example1Function();
}