I want to receive some USD coin, for this special wallet is required or can any ethereum address receive it?
Yes, it is possible as USDC follows the ERC20 standard, so you don't need a special wallet for it.
ERC20-tokens have an "abi", which defines the functions that ERC20-tokens use. The abi on https://etherscan.io/address/0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48#code is for a Proxy Contract and is not ERC20 compliant, as it does not define a "transfer" function.
To still be able to send USDC tokens from an address, you simply gotta define the transfer function in the abi when creating the transaction. You could even just take the minimal ERC20 abi and delete the USDC abi altogether.
Related
I wanted to ask if its possible to have a USDT tokens (like the standard smart contract's balance in Ether) inside my smart contract, and if it was possible to than swap it with the Ether inside the smart contract's balance (if possible using Uniswap; swapping both from ETH to USDT and viceversa).
Thanks.
Yes, it is entirely possible to store ERC20 token in any contract, since the balance of ERC20 token is only defined as a mapping of mapping(address => uint256) in the ERC20 contract.
However, since transferring ERC20 requires either you as the owner or you having the approval to transfer, you will need to give yourself, or the address executing transactions, allowance to transfer the ERC20 "stored" in the contract address, or otherwise, the ERC20 token will be stuck inside the contract.
For the swapping part, you can look into the interfaces of Uniswap and have your smart contract call to Uniswap for the swap.
My ultimate purpose is to swap some tokens across pancakeswap babyswap apeswap atomicly. So I build a contract(called ContractA) to run a bunch of swaps in a transaction. I transfer some USDT token into ContractA. But ContractA is not approved to transfers USDT by the USDT contract.
I known how to approve Metamask address to transfer USDT, but how to do it for a Contract?
In order to control an ERC20 token from a smart contract, first you need to create an instance of it. To do that, first you need to import ERC20 to your contract, and then just create an ERC20 type function giving it the token address you want to manage. It would be something like this:
// Some code...
import "#openzeppelin/contract/token/ERC20/ERC20.sol";
// Some more code...
contract exampleContract {
// Example of an ERC20 token instance
ERC20 USDTToken = ERC20("USDT Contract Address Here");
// Approve USDT
USDTToken.approve(address(this), _amount);
}
Then you will be able to manage the token, always following the ERC20 standard, as you want.
Hope you find this information useful :)
I have an Eth contract, called the controller, which is used to:
Generate new eth deposit addresses, one for each user, which is
an eth contract as well.
Sweep these deposit contracts when a user deposits eth or erc20 token to them. The funds end up in another central eth account.
A number of erc20 tokens seem to work perfectly, but USDT deposit transactions get reverted: https://etherscan.io/address/0x3cd5a0dc36a8f22011193f2a03910aa8260e64db
Without the original source code for these contracts (although I have the JSON ABI), it is hard to say:
Why it fails for USDT.
If these actually can support USDT, or what it would involve to do so.
If anyone can point in the right direction, it will be appreciated!
Controller contract:
0xEb818C6a48cCd60A8078aaa20997cC3CB2538C9E
Another contract involved linked to controller, called defaultSweeper:
0x8e7ABAF1316A0edB985e494F572Fdf148e8a7E93
EDIT:
It seems that USDT contract is missing some erc20 methods. Like transfer See: https://erc20-verifier.openzeppelin.com/ Why is this?
Tether contract was deployed before the ERC20 standard was finalized. Some functions don't follow the specs, for example transfer should return a boolean and it doesn't.
Recent versions of solc will check the returned data size is correct (since 0.5 I think).
My guess is that your contract was compiled with a recent version of solidity and it uses the standard ERC20 interface. And it fails because Tether returns nothing and it is expecting a bool value.
There isn't much you can do. Either Tether should upgrade its contract or the controller contract has to be modified to do not check the contract size. See SafeERC20 from OpenZepplin, they implemented a wrapper around ERC20 that allows interfacing with tokens that are not compliant with the standard.
I want to create a smart contract which people can transfer tokens without ether in their wallet.
Suppose A want to transfer ERC20 tokens to B, but he does not have ether in his wallet.
Does third party C can send the transaction for A and therefore pay the gas? Is it possible to create a function in the contract for this usgae?
I have searched online for a soloution and could not find one.
This is a key issue of Ethereum dApp development, but also of tokens. Here is a very old thread on Ethereum Stack Exchange, and also this one.
There are 2 options with their pros and cons:
Use signatures
Every function in your smart contract must have signature parameter.
People who want to interact with the smart contract must sign the function parameters with their account's private key and send it to the smart contract owner (via any communication channel).
The owner then submits the parameters along with the signature to the blockchain, paying for gas. The signature guarantees that the message was approved by the user.
Refund used gas at the end of the transaction. A modifier refundGasCost can be used for this (see below).
But (1) is really hard to apply to token transfers where you just don't know who uses the token and (2) does not really address the issue.
There is a lot happening recently, there is this blog post about How to save your Ethereum Dapp users from paying gas for transactions, and since you ask about tokens, there is an ERC that suggests to Pay transfers in tokens instead of gas, in one transaction which would be nice if you have tokens but no ETH.
I hope this helps.
Exactly this case is already defined in the ERC20 standard. Its this function:
function transferFrom(address from, address to, uint tokens) public returns (bool success);
But before party C could use it and send tokens from A to B, A would have to approve C to do this via the following function, which is also defined in the ERC20 standard:
function approve(address spender, uint tokens) public returns (bool success);
No, in a standard ERC20 token contract, the token holder must initiate at least one transaction (to call transfer() or approve()), and a transaction must always be paid for by its initiator.
As the title suggests - is it possible to send tokens from an ERC20 smart contract address, or is this unit not accessible?
Practical explanation:
A noob misunderstands some instructions and sends some tokens instead to his address to a smart contract address erc20. Is it possible for the programmers of the tokens, to recover those tokens, or are their hands "tied" and none has access to those tokens anymore?
Both contract accounts and external accounts (controlled by humans) have all the same inherent powers. Each can do what the other can.
If you send some ERC-20 token to a contract, it can in theory send it elsewhere, providing it has that functionality already built into-it.