What Does this code mean in BEP20 token writting with Solidity - blockchain

I'm trying to understand what this lines of BEP20 code mean, it is written in solidity
constructor () {
_rOwned[owner()] = _rTotal;
IUniswapV2Router02 _uniswapV2Router = IUniswapV2Router02(0x10ED43C718714eb63d5aA57B78B54704E256024E);
uniswapV2Pair = IUniswapV2Factory(_uniswapV2Router.factory())
.createPair(address(this), _uniswapV2Router.WETH());
uniswapV2Router = _uniswapV2Router;
_isExcludedFromFee[owner()] = true;
_isExcludedFromFee[address(this)] = true;
emit Transfer(address(0), owner(), _tTotal);

In the first lines, he instanciate UniswapV2Router pointing the address router to PancakeSwap. This because, he want to create a liquidity pool with his TOKEN and BNB, indeed after this instanciating operation he call createPair() that allows him to create this pair between his smart contract and the address WETH().
IMPORTANT: WETH() is a function that provider the chain native wrapped coin address where smart contract was deployed. For example: If I create a pair instanciating Uniswap router on Ethereum blockchain then WETH() will return address about WETH (Wrapping Ether) address present into Etheruem. On the contrary if I instanciate Uniswap Router with its address present into binance smart chain (and so I refers to Pancakeswap in this case), the value of WETH() will be WBNB address.
After this lines of code, I assume that he excluded from paying a fee for only transactions the owner() address (who deployed the smart contract for the first time) and smart contract itself.
Finally he emitted a Transfer event passing : address(0) (0x0000000000000000000000000000000000000000), owner() and total supply.
More information about pair on documentation.

Related

transfer token out of contract

i had a small question that i creast a contract A and there is 1 busd token in the contract A, now i want to transfer the 1 busd out of contract by owner address
how to set the contractA?
i have use this code to deploy and test
pragma solidity ^0.8;
interface IERC20 {
function transfer(address to, uint256 amount) external returns (bool);
}
contract MyContract {
address owner = 0xFAD69bCefb704c1803A9Bf8f04BC314E78838F88;
function withdrawToken(address tokenContract, uint256 amount) external {
// send `amount` of tokens
// from the balance of this contract
// to the `owner` address
IERC20(tokenContract).transfer(owner, amount);
}
}
the feedback is
This contract may be abstract, it may not implement an abstract parent's methods completely or it may not invoke an inherited contract's constructor correctly.
can someone help me? thanks in advance , i am beginner.
find a way to transfer the busd out of contract .
I recognize this code from my other answer. :)
You're trying to deploy the IERC20 interface - which throws the "This contract may be abstract" error.
You need to deploy the other contract. Depending on how you deploy the contract, there are different ways to do that.
Here's another answer that shows how to select the desired contract in Remix IDE. However, note that this code won't work on the Remix emulated network, as the BUSD contract is not available there. You'll need to deploy the code either to the mainnet or your local fork of the mainnet, where the BUSD contract is available.

Invalid type for argument in function call. Invalid implicit conversion from address to address payable requested.for msg.sender and adress 0

// create the fllow to transform the ownership of the nft
//from the item owner(seller) to the contract that will transact to the buyer
IERC721(nftcontract).transferFrom(msg.sender,address(this),tokenId);
//after the marketitem is created
//the market item creation is an event executed by this contract so we must emit it so that the details of the market item will be listned to or used
emit MarketItemcreated(
ItemId,
nftcontract,//the nft because the nft contract address means the nft created
tokenId,
msg.sender,//seller is the msg.sender // we don't do payable because we emit only the details of the cretaedmarketid (what the market id contain)
address(0),//no one yet own this nft
price,
false//not yet solde
);
}
i'am facing the problem in msg.sender and adress 0 i don't know where is the problem
I think the issue is you are not modified the function as payable. You are not showing the full code, I think the code that you posted is inside a function and this function has to be marked as payable. if this is not the case, share the full function code please. A common mistake is not to wrap msg.sender with payable(msg.sender). because since solidity 0.6.0 msg.sender is not payable any more.

VM Exception while processing transaction: revert

I have 2 Contracts. One is an ERC721 Token (NFTCollectables). The other one is a market including an auction system (NFTMarket).
An auction can be claimed after it ended and only by the highest bidder.
When claiming an auction the transfer method of the NFTCollectables contract is called to transfer the NFT from the markets address to the address of the highest bidder.
I do not exactly understand why the exception comes, but it occurs at/inside the transfer method of the NFTCollectables contract. The strange thing is that even the last line of code inside the transfer method is getting executed (tested by putting a require(false, 'test') after _transfer(msg.sender, to, nftId)). But nothing after ctr.transfer(auction.highestBid.bidder, auction.nftId) is getting executed (tested by putting a require(false, 'test') after it).
Could it have to do with the gas limit?
Any idea is appreciated, thanks!
NFTMarket
function claimAuction(uint auctionIndex) external {
require(auctionIndex < auctions.length, "no auction");
Auction memory auction = auctions[auctionIndex];
require(block.timestamp <= auction.end, "auction still active");
NFTCollectables ctr = NFTCollectables(nftCollectablesAddress);
ctr.transfer(auction.highestBid.bidder, auction.nftId);
// deleting auction from active auctions list
for (uint i; i < activeAuctionIndexes.length; i++) {
if (activeAuctionIndexes[i] == auctionIndex) {
delete activeAuctionIndexes[i];
break;
}
}
emit AuctionEnd(auction.highestBid.bidder, auction.highestBid.price, auction.nftId);
}
NFTCollectables
function transfer(address payable to, uint nftId) external payable {
require(_exists(nftId), "transfer of non existing token");
require(_isApprovedOrOwner(msg.sender, nftId), "Sender not approved nor owner");
_transfer(msg.sender, to, nftId);
}
If you have deployed the contracts on the public network, like mainnet or testnet, use https://tenderly.co or EtherScan to debug the revert reason.
If you are running the contracts using unit tests then keep modifying the contracts e.g. by removing lines to see when it starts failing. Or alternatively use a better smart contract development framework like Brownie which will give you the cause of revert right away.
We had implemented a function on our codebase that i can share with you. This function is used to transfer ownership of nft to who wins the auction.
function transferNFTtoNewOwner(NFTItem memory t,address oldOwner, address newOwner) internal {
require(newOwner != address(0), "New owner can't be address zero.");
XXXX storage r = creatureList[t.tokenAddress][t.tokenId];
IERC721 nft = IERC721(t.tokenAddress);
nft.safeTransferFrom(oldOwner, newOwner, t.tokenId);
address currOwner = nft.ownerOf(t.tokenId);
require(newOwner == currOwner, "Problem on nft transfer");
r.owner = newOwner;
}
The major differences are we used safetransferfrom here. If your contract owns the NFT then you can call safeTransfer. and after that we checked the nft owner with require statement. If you put this statement and change your transfer function to safetransfer and the transaction still revert without giving any error on etherscan then you can investigate about your nft contract.

Getting mined blocks instead of the supposed returned values

I've just deployed a Smart Contract using the ethereum wallet.
I got the Smart Contract address , I copied its ABI from remix and verified it on ethereum wallet,it was active and I could see all its methods.
Then I tried to call it from my nodejs server.I did it,I didn't get any error...
But instead of a classic response like the returned values of the methods below I got mined blocks....and this is very weird I think...
How am I supposed to get the methods output(the returns) ?
After that I tried to deploy another contract,this time a very simple one with the same methods name,smart contract name,parameters but without code inside the methods only a basic hard-coded return.When I deployed this contract as well I got the same mined smart contract address...which is weird,in my opinion...
I've been using 1.0.0-beta.46 , nodejs , expressjs
When I said eth wallet I meant...that website generated with puppeth , on /#wallet page
Here is the basic smart contract I tried to deploy second time.The result was the same as the first smart contract.
pragma solidity >= 0.4.22 < 0.6.0;
contract BasicContract {
function function1(uint16 a,uint16 b,uint16 c,uint16 d) external payable returns(uint256){
//a,b,c,d doesn't matter
return 68;
}
//buy a ticket
function function2(uint128 a,uint16 b) external payable returns(uint128){
//a,b doesn't matter
return 94;
}
function function3(uint128 a) external payable returns(bool){
//a doesn't matter
return false;
}
}
There are two ways to invoke a function in a smart contract: through a transaction sent to the network or via a local call.
Transactions don't have return values. What you get back from the library you use to make the transaction is typically the transaction hash. Any return value from the function you invoked is discarded.
A local call doesn't involve a transaction to the network and thus can't change any state. But it does give you a return value.
Which method is chosen by default for most libraries is based on whether the function is state-changing or not. If you mark your functions as view or pure, it tells the library that those functions don't change state and can then safely be just called locally to get a return value. So a simple "fix" for the above code is to make those functions pure. For functions that do change state, you'll want to switch from using return values to emitting events instead, which can be read after the transaction is mined.

Solidity basics: what "msg.sender" stands for

I just started to learn Solidity as a personal challenge. I'm not a developer so I've a loooooong way to go.
I'm following the Ethereum.org tutorial, here is what I've got doubt about: What does [msg.sender] stand for? I guess it is the wallet address of who triggered the contract, but I'm not sure.
msg.sender (address): sender of the message (current call)
msg.sender will be the person who's currently connecting with the contract.
Later on, you'll probably deal with contracts connecting with contracts. In that case, the contract that is creating the call would be the msg.sender.
Check out the documentation here: https://docs.soliditylang.org/en/develop/units-and-global-variables.html#block-and-transaction-properties
Let's make it very simple.
There are two types of accounts in the Ethereum Chain
1). Externally Owned Accounts(EOA) [Person]
2). Contracts Accounts [Contracts on Chain]
Both accounts have their addresses.
Now, look at an example.
Wallet address of personA (EOA) is
0x0cE446987406E92DF41614C46F1d6df9Cc925847.
Contract Address of Math.sol is
0x0cE446987406E92DF41614C46F1d6df9Cc753869 and
Math.sol contains ContractA
Contract Address of Addition.sol is
0x0cE446987406E92DF41614C46F1d6df9Cc357241 and
Addition.sol contains ContractB
Here, one of the functions of ContractB is called from ContractA.
So, whenever personA calls any functions of ContractA.
In this scenario, if you print or get `msg.sender` and `tx.origin` inside function of `ContractB` then the result would be like this
msg.sender = `0x0cE446987406E92DF41614C46F1d6df9Cc753869` // You will get address of `ContractA`
tx.origin = `0x0cE446987406E92DF41614C46F1d6df9Cc925847` // personA's (EOA) Wallet Address
Here,
msg.sender (address): means sender of the message (current call)
on the other hand
address owner = msg.sender;
The msg.sender is the address that has called or initiated a function or created a transaction. Now, this address could be of a contract or even a person like you and me.
That's why you may use msg.sender instead of msg.sender()