Contract constructor parameter which is also a contract - blockchain

I have contract in solidity MasterChef.sol which can be seen at the link below
https://github.com/pancakeswap/pancake-farm/tree/master/contracts
I want to deploy it using truffle on the Binance smart chain and the question is that the constructor of the MasterChef.sol takes in 5 args and two of them are contracts I want to know that how to pass the other two contracts i.e CakeToken.sol and SyrupBar.sol as the first two args in the deploy_contracts.js file.

You need deploy other contracts beforehand, write down their addresses and pass addresses when MasterChef is deployed.

Related

Get Array of structs from custom smart contract deployed on Hedera

Suppose I have a solidity contract deployed at address X in Hedera testnet. I want to call a function from the contract deployed at contract X a get function that returns an array of structs...how do I decode that array of structs? (I am using ContractCallQuery function from the Hedera JS SDK library to call the get function) Ref: Link

I am not able to understand how to use IVotes contract address in GovernorVotes contract

As IVotes is a interface and cannot be deployed.
IVotes public immutable token;
constructor(IVotes tokenAddress) {
token = tokenAddress;
}
....
Error: *** Deployment Failed ***
"IVotes" is an abstract contract or an interface and cannot be deployed.
Import abstractions into the '.sol' file that uses them instead of deploying them separately.
Contracts that inherit an abstraction must implement all its method signatures exactly.
A contract that only implements part of an inherited abstraction is also considered abstract.
I want to use IVotes address passing in GovernorVotes constructor.
I tried bunch of methods but none works
The Solidity snippet, that you shared, expects a contract on the tokenAddress to implement the IVotes interface.
But it needs to be a "full" contract with all function bodies - not just the function declarations.

OpenZeppelin Context.sol smart contract is abstract, why?

I was digging into this OZ smart contract:
https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/utils/Context.sol
As you may see, it has only two functions to deal with metatxs. I can't figure out why this contract is defined as abstract, as both functions are implemented. Thanks in advance to all of you!
The Context contract was made abstract in the pull request #2229. One of the contributors links to the issue #8162 for explanation:
it seems like what the keyword does is mark the contract as non-deployable (i.e. it needs to be inherited from). Because contracts missing function implementations are always non-deployable, they require abstract.
From my understanding, their reason was just to explicitly say "This contract has no use on its own, and should not be deployable (on its own)."

How to deploy multiple solidity smart contracts that uses functions of each other?

I have three smart contracts say a.sol, b.sol and c.sol... Out of these three, first two are independent smart contracts whereas c.sol uses the functions of a.sol and b.sol and thus c.sol requires to "import" the first two smart contracts. "Import" works locally but how to deploy all of them via remix/truffle on testnet such that c.sol can still access the functions of a.sol and b.sol?
Does your contract a and b supposed to be standalone contracts that will be used regardless of contract c? ie: user store data in contract a, which will be used by contract c
If so, then you can have contract a and b as variables of contract c like this
a.sol
contract A {
function doSomething() {
...
}
}
c.sol
contract C {
A a;
function setA(address addressOfContractA) {
a = A(address);
}
function makeADoSomething() {
a.doSomething();
}
}
credit: https://zupzup.org/smart-contract-interaction/
If your project was created with Truffle, you can set up c.sol in the following way:
import "./a.sol";
import "./b.sol";
contract c is a, b {
...
}
If this is the structure of your code, you will be able to deploy your Truffle project using truffle migrate (provided your migrations are set up correctly).

Django M2M self to relate an extend version of a table

I have two tables: Project and Contract. One project result in a contract. Plus, a contract could be extended leading to another contract related to the previous one. So I think I could use something like:
contract = models.ManyToManyField('self')
Any idea?
Thanks!
It depends on your requirements. A contract can result in another contract or another contractS? That is very important questions. If we assume that a contract A can lead to another contract B (but not to other contracts) and that the new contract B can be extended only from contract A, then OneToOneField('self') would be appropriate.
If a contract A can lead to contract B, but also to contract C or maybe contract D, then the ForegnKey('self') should be used. But if contract B can be traced back not only to contract A, but also to contract E, or maybe even contract F and contract G, then you need ManyToManyField('self').
So it is very basic question first to clarify if it as a 1:1, 1:n or m:n relation. After figuring this out you'll have your right answer.
From the information you provided I can just vaguely guess what should be the right approach.
I hope my answer can help you.