Method to display the liquidity added in DEX - ethereum

I am new to DEX development. Am using pancakeswap router contract https://testnet.bscscan.com/address/0xd99d1c33f9fc3444f8101754abc46c52416550d1
addLiquidityETH is working to add the liquidity in the DEX. I need to display a list. Which method I need to use in router or factory contract to display the liquidity added details like below image
Thanks in Advance

Related

How can I combine 2 smart contract functions in one transaction?

I am building two smart contracts, one is casino contract and the other one is lottery contract(planning to deploy it separately). I want to combine both the placebet(casino) function and buyticket(lottery) function in one call. Once user would call placebet on casino contract, he will automatically buys lotteryticket also. Any help will be appreciated. Thank you.
Note: (Pls. respect) I am just a newbie, no formal coding education, I am just studying how to make dapp.
If I understand correctly, you need to make the first method call another method from another contract.
Here is an example:
contract LotteryContract {
function buyTicket() public {
// code to buy ticket
}
}
contract CasinoContract {
function placeBet() public {
// code to place bet
LotteryContract.buyTicket()
}
}
The basic idea in this example is that we call the LotteryContract's method in CasinoContract. In this case, when the user makes a bid via the placeBet method, the contract will call another buyTicket method
If you meant to make two calls to different contracts at once from the user, you can't do that. The user can only call one method from the contract, which will call other methods inside itself.

SOLIDITY: Create multiple contracts from one parent contract and listen for events from child contract

What is the best architecture to allow users to deploy their own smart contracts (NFT collections), and still be able to index the tokens created on those dynamically created contracts using something like The Graph subgraphs?
Currently the idea was to have a "Factory" contract deployed by me, so easily indexable, and inside that have a function createCollection that will deploy a contract using the new <ContractName> keyword.
Is this bad architecture? Would this even work?
The end goal is to allow users to deploy contracts from a UI, but still be able to listen for their events through my parent contract, so that I can index everything in a subgraph.
What you can actually do is to save a pointer to the parent contract into each generated contract. Thus, whenever you have an event you want to store into the parent contract, you can maybe interact with a function in it. But you may also want some type of verification to ensure that only child contracts can call the parent functions and not external contracts, so maybe you could make a mapping indexing the address of the generated child contracts, which will be able to call functions from the parent. What you can not do is to make the parent automatically look for events on the child's contracts.
Hope you find this information helpful :)

Solidity - What version of the contract do I deploy?

I am currently learning Solidity and I have made my first BSC test contract with no errors. I have compiled my contract successfully and I am now in the deployment section of Remix.
There is a drop down menu named "contract" and within there, there are the following options:
test.sol...ApproveAndCallFallback
test.sol...BEP20Interface
test.sol...Owned
test.sol...SafeMath
test.sol...TokenBEP20
test.sol...
I am a bit confused as to which I actually deploy for my contract as there are multiple options. Could someone please point me in the right direction for descriptions of these options?
Thanks!
In the contract selectbox, you select the main contract that you want to deploy.
Most likely you have written the TokenBEP20 token and it's going to be the TokenBEP20, but it all depends on your context.

Solidity - Add Total Supply

I'm learning solidity on remix
I'm also referencing this open source api for token creation.
Right here they provide a _totalSupply() function that I'd like to wire to my smart contract so it shows the total amount of tokens why I deploy it.
What am doing wrong here?
pragma solidity ^0.8.0;
import "https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/token/ERC20/ERC20.sol";
contract Foobar is ERC20 {
constructor(uint256 initialSupply) public ERC20("Foobar", "FOO") {
_mint(msg.sender, initialSupply);
// add totalSupply here
_totalSupply(uint256 5000000000000000000000000000000000000000);
}
}
OpenZeppelin ERC20 _totalSupply is a private property, which means you can't access it from a derived contract (in your case Foobar).
GitHub link to the property definition
Solidity docs on visibility modifiers
Also your syntax is incorrect. If the property were at least internal, you could set its value as
_totalSupply = 5000000000000000000000000000000000000000;
or in a more readable way
_totalSupply = 5 * 1e39;
If you want to change its visibility, you'll need to copy the (parent) ERC20 contract to your IDE and change the import statement to reflect the new (local) location. Then you'll be able to update the property visibility in your local copy of the contract.
Mind that the OpenZeppelin ERC20 contains relative import paths (e.g. import "./IERC20.sol";). You'll need to rewrite these in your local copy as well, so that they point back to the GitHub locations. Otherwise, the compiler would be trying to import non-existing local files.
OpenZeppelin contracts automatically update totalSupply when you mint or burn tokens. They also automatically expose this as a variable you can read. You do not need, and you should not and you cannot set totalSupply by hand, because then the number of distributed tokens would not match the total supply.

Creating Ethereum Contracts (go ethereum)

Trying to follow the wiki example for go ethereum to create a basic contract:
https://github.com/ethereum/go-ethereum/wiki/Contracts-and-Transactions
Everything seems to work until I get down until the last line:
source = "contract test { function multiply(uint a) returns(uint d) { return a * 7; } }"
contract = eth.compile.solidity(source).test
primaryAddress = eth.accounts[0]
# **Problems start here **
MyContract = eth.contract(abi);
contact = MyContract.new(arg1, arg2, ...,{from: primaryAddress, data: evmCode})
What is the "abi" argument for the eth.contract method? Also, what would I put in the "evmCode" argument? In this particular example, seems like I would put in an integer for "arg1" but not sure what the full example should look like.
The ABI is the interface that your contract exposes. "evmCode" is the Ethereum byte code for your contract.
To work around your problem, go to https://chriseth.github.io/browser-solidity/ and plug your Solidity in. The Bytecode field on the right will give you the value for "evmCode" and Interface will give you the ABI.
You can also copy the snippet from "Web3 deploy" and paste it in your code to deploy your contract.
ABI is basically which is the public facing interface that shows what methods are available to call.
The simplest way to get the abi would be to use https://remix.ethereum.org . just paste in your code and in Contract tab At the bottom of the column you’ll find a link that says Contract details which is basically the ABI json
Conversely you could also use the contracts.Introduction.interface api of web3 to get the abi.
ABI is representation of smart contract that can be read using java script .To read the data from a deployed contract account in etherum , you'll need some extra details like abi.
Steps to get abi of any smart contract:
1.Each contract has contract hash address like this:0x0D8775F648430679A709E98d2b0Cb6250d2887EF
2.Go to etherscan.io and search your contract address hash in search bar and you will get contract.
3.In contract go to code and there you can find this abi
can check this link to find abi
You could try using tools like Etherlime shape or Truffle boxes to have a whole sample project with contract, tests, and usage into the js. From here you could start moving forward.
ABI is Application Binary Interface. A contract when compiled by solidity compiler returns an object with different methods. ABI and Bytecode are basically used methods. ABI is used to interact with your contracts and frontend (if using node) and bytecode is used for deploying to Rinkeby (or any Ethereum network).
For example:
Contract is:
pragma solidity ^0.4.17;
contract Inbox
{
string public message;
function Inbox(string initialMessage) public{
message = initialMessage;
}
function setMessage(string newMessage) public{
message = newMessage;
}
}
Its ABI is:
interface:
[{
"constant":false,"inputs":[{
"name":"newMessage","type":"string"
}]
,"name":"setMessage","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"
}
,{
"constant":true,"inputs":[],"name":"message","outputs":[{
"name":"","type":"string"
}]
,"payable":false,"stateMutability":"view","type":"function"
}
,{
"inputs":[{
"name":"initialMessage","type":"string"
}]
,"payable":false,"stateMutability":"nonpayable","type":"constructor"
}]
This is returned after compiling the contract. You can see it consists of methods used in our contract.