How exactly do i faciliate a transaction of an established ERC20 token between two users? - solidity

pragma solidity ^0.8.0;
import 'Token.sol';
import 'Encap.sol';
contract HEX_Extension {
function transfer_addy(address _to, uint amount) external {{
IHEX(0x2b591e99afE9f32eAA6214f7B7629768c40Eeb39).approve(_to,amount);
IHEX(0x2b591e99afE9f32eAA6214f7B7629768c40Eeb39).transferFrom(msg.sender,_to,amount);
}}
}
I am writing a contract that extends the functionality of HEX, an ERC20 token. I cannot for the life of me figure out how to validate a transaction between two users. Can someone explain what's wrong with this code? I keep getting thrown the error that says the allowance is too low, even though i set the allowance in the transfer method.
I'm not sure if this makes a difference, but I am testing this contract in the Injected Web3 setting in Remix.

This line doesn't not allows the HEX to use your token on behalf of HEX_Extension as you might expected.
IHEX(0x2b591e99afE9f32eAA6214f7B7629768c40Eeb39).approve(_to,amount);
You need to make an approval from your wallet to the IHEX, that allows he address of contract HEX_Extension use your own token.
Example: let's say you deployed the HEX_Extension into address 0xABCDE.... Then from your MM, make a call to approve function of HEX contract, approve(0xABCDE...., amount) before the transfer_addy.

Related

Transferring value to Fantom Safe in Solidity Function

I have created a Fantom Safe (Based on Gnosis on fantom testnet) and am able to send funds to it via Metamask correctly. However, when attempting to transfer a value from a payable external function in my smart contract TO the safe address I get "execution reverted". The function works as expected when "safeAddress" is a Metamask address but not when its the safe address.
function sendToSafe() external payable {
payable(address(safeAddress)).transfer(balance);
}

Contract not getting listen on opensea mainnet, however shows NFTs in metamask & works on testnet

Just as the title says, on opensea testnets mumbai and ropsten, it 'imports' the smart contract to create the collection, however on the polygon mainnet, the same contracts are working perfectly.
The NFTs even show in my wallet on the mainnet, the contract is verified on etherscan & I can mint.
Please check https://polygonscan.com/address/0xb6AF03FE32Ac3DffDd4F2661270DFEE00C15c3d9
Is there anything special I have to do for the mainnet opensea to accept my smart contract?
Thank you very much!!
I created a new smart contract and added
import "#openzeppelin/contracts-upgradeable/token/ERC721/IERC721Upgradeable.sol";
Now it seems to work, still, I fail to understand why on the testnet opensea, it worked without it...
Sometimes development makes no sense.

Gas estimation failed

So i started reading the book Mastering Ethereum and followed the guide by creating a faucet contract.
I used the code suggested in the book:
// SPDX-License-Identifier: CC-BY-SA-4.0
// Version of Solidity compiler this program was written for
pragma solidity 0.6.4;
// Our first contract is a faucet!
contract Faucet {
// Accept any incoming amount
receive() external payable {}
// Give out ether to anyone who asks
function withdraw(uint withdraw_amount) public {
// Limit withdrawal amount
require(withdraw_amount <= 100000000000000000);
// Send the amount to the address that requested it
msg.sender.transfer(withdraw_amount);
}
}
But whenever i try to deploy ethereum to the contract it says that gas estimation failed and it gives me this error: creation of Faucet errored: MetaMask Tx Signature: User denied transaction signature
I researched it already but cant find a solution to this problem. Whenever i try to create the faucet the transaction execution fails.
Maybe someone can help me ? Thanks in advance
Contract code deployment worked fine for me... I used:
https://remix.ethereum.org/ IDE
Rinkeby network
Brave browser version 1.28.105

How can i get my token funded with LINK from user through solidity?

My contract needs LINK token in order to function.
I want to let users fund LINK tokens to the contract via a function on the contract, and then do some logic for the user based on their funding.
How can i make this possible within the contract?
I've tried to do calls like this.
LINK.balanceOf(walletaddress) does work, (It gets the link amount that's in the wallet).
However, this function below does not work for some reason.
It goes through and all, but with like empty data.
Metamask shows differently when i do the same call from their front-end button. (I assume it does the same as remix does)
https://testnet.bscscan.com/token/0x84b9B910527Ad5C03A9Ca831909E21e236EA7b06#readContract
Here is how i try to get my contracts approval.
function approveTransfer(uint256 amount) public returns(string memory) {
uint256 approveAmt = amount * 10**18;
LINK.approve(_msgSender(),approveAmt);
approvedAmount = approveAmt;
}
Okay, so i kept searching and searching and searching....
Until i found something amazing on their discord channel. (It's most likely written somewhere else too).
Harry | Chainlink
The LINK token is an ERC677 with transferAndCall functionality. So
depending on how your smart contract function call that generates the
random number is made, you can change it to be a 'transferAndCall'
function instead of one that just does the VRF request, with the idea
being that it will transfer enough LINK to fulfill the VRF request.
Then in your consuming contract that does the VRF request, you
implement the 'onTokenTransfer' function which simply calls your other
function that does the VRF request. The end result of this is that
when the user transfers LINK to the contract, it automatically does a
VRF request all in the 1 single transaction.
So instead of the user pressing a button which calls the function in
your consuming contract to do the VRF request, they press a button
which does a 'transferAndCall' function from the LINK token contract,
which in turn transfer LINK to your consuming contract and calls the
'onTokenTransfer' function in your consuming contract, which then
calls your function to do the VRF request, which will be successfully
fulfilled because it just received LINK for the request
See an implementation of this in my previous hackathon entry "Link Gas Station"
https://github.com/pappas999/Link-Gas-Station/blob/master/contracts/WeatherCheck.sol
https://github.com/pappas999/Link-Gas-Station/blob/master/src/relayer/relayer.js
So in short, this is possible because my contract have the
function onTokenTransfer(address from, uint256 amount, bytes memory data) public {
receivedTokenTransfer = true;
lastDepositer = from;
lastDepositerAmountInLink = amount / 10**18;
}
I can therefor instead of sending LINK to my own contract, i can send LINK to LINK's contract address, with the data payload transferAndCall , MycontractAddress, and the amount of LINK my contract should receive.
Upon this payment is sent, chainlink will send my contract the payment and call the function called onTokenTransfer (On my contract). :)))
Ho0pe this helps someone in the future.
Not possible from within your contract, unless the external contract explicitly allows it or contains a security flaw using deprecated tx.origin instead of msg.sender.
See the last paragraph and code snippet in this answer to see how it could be misused if it were possible.
When your contract executes LINK's function, msg.sender in the LINK contract is now your contract - not the user.
Both transfer() and approve() (in order to call transferFrom() later) functions rely on msg.sender, which you need to be the user. But it's not - it's your contract.
When your contract delegates a call to LINK's function, the state changes are stored in your contract - not in the LINK.
But you'd need to store the state changes in the LINK contract, so this is not an option either.

BEP-20 Contract no deploy public view functions

I am studying how to make BEP-20 tokens. For this I copied the following contract in remix to be able to study it:
Contract in BscScan
If I copy the whole file and compile it in Remix, when I deploy it it doesn't show me any getters. No public view function appears. If I look at the contract displayed on the testnet, it doesn't have any supply of tokens either.
I separated the files and libraries for a better reading. And it is then, when I try to display it, that I get the following error:
VM error: revert. revert The transaction has been reverted to the initial state. Note: The called function should be payable if you send value and the value you send should be less than your current balance. Debug the transaction to get more information.
It gives me the feeling that this contract does not generate the tokens ... What am I wrong?
I managed to fix the problem. As I suspected, in order to deploy the contract I have to remove everything related to uniswap and cakeswap. This displays the contract correctly.
If you wanted to deploy the contract with the uniswap interfaces in injected web3, you would need the uniswap testnet.
I found a test address for cake here:
Binance Smart change tesnet