Get Array of structs from custom smart contract deployed on Hedera - blockchain

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

Related

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.

What is difference between internal and private in Solidity?

In Solidity we have four types of access. Two of them are private and internal.
What is the difference if both of them can be used inside smart contract and both of them are not visible after deploying?
Access types:
public - can be used when contract was deployed, can be used in inherited contract
external can be used when contract was deployed , can NOT be used in inherited contract
internal - can NOT be used when contract was deployed , can be used in inherited contract
private - can NOT be used when contract was deployed, can NOT be used in inherited contract
internal properties can be accessed from child contracts (but not from external contracts).
private properties can't be accessed even from child contracts.
pragma solidity ^0.8;
contract Parent {
bool internal internalProperty;
bool private privateProperty;
}
contract Child is Parent {
function foo() external {
// ok
internalProperty = true;
// error, not visible
privateProperty = true;
}
}
You can find more info in the docs section Visibility and Getters.
public: anyone can access the function
private: only this smart contract can call this function
internal: only this smart contract and smart contracts that inherit from it can call this function
external: anyone can access this function unless this smart contract
Note that external uses less gas than public so if the function is not used by your contract, prefer external over public.
More explanations in this article

Contract constructor parameter which is also a contract

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.

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

Interaction solidity in Ethereum with external c++ library

I'm working on solidity smart contract for Ethereum.
I need to run some cryptographic verification algorithm before making transaction. This algorithm is implemented in C++.
How I can call this code from inside smart contract?
Let's say I have fallowing C++ code(but in practice it is much more complex)
int foo(int a, int b, int n){
if(pow(a,b)%n == 1)
return true;
else
return false;
}
And if this code return's true I need to make transaction
msg.reciever.addr.send(amount);
Is there any solution I can use in order to combine Ethereum's smart contacts and complex self-implemented cryptography which should be done inside of blockchain? How to make a bridge between blockchain and outside library.
Generally, you cannot call any external code from an Ethereum contract. To run cryptographic verification you should use ecrecover solidity function
http://solidity.readthedocs.io/en/develop/units-and-global-variables.html#mathematical-and-cryptographic-functions
https://ethereum.stackexchange.com/questions/1777/workflow-on-signing-a-string-with-private-key-followed-by-signature-verificatio