Skip to content

Instantly share code, notes, and snippets.

@Olanetsoft
Created October 18, 2022 16:07
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Olanetsoft/8c3a275c388a623cc42da110af0d4a1b to your computer and use it in GitHub Desktop.
Save Olanetsoft/8c3a275c388a623cc42da110af0d4a1b to your computer and use it in GitHub Desktop.
Created using remix-ide: Realtime Ethereum Contract Compiler and Runtime. Load this file by pasting this gists URL or ID at https://remix.ethereum.org/#version=soljson-v0.8.7+commit.e28d00a7.js&optimize=false&runs=200&gist=
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.4;
// Abstract
interface USDC {
function balanceOf(address account) external view returns (uint256);
function allowance(address owner, address spender) external view returns (uint256);
function transfer(address recipient, uint256 amount) external returns (bool);
function approve(address spender, uint256 amount) external returns (bool);
function transferFrom(address sender, address recipient, uint256 amount) external returns (bool);
}
// Contract
contract UsdcDemo{
USDC public USDc;
// Contract Owner
address payable public owner;
constructor(address usdcContractAddress) {
USDc = USDC(usdcContractAddress);
// USDc = USDC(0x07865c6E87B9F70255377e024ace6630C1Eaa37F);
// user who is calling this function address
owner = payable(msg.sender);
}
function Fund(uint $USDC) public payable {
// Transfer USDC to this contract from the sender account
USDc.transferFrom(msg.sender, address(this), $USDC * 10 ** 6);
// Transfer to the owner
USDc.transfer(owner, $USDC * 10 ** 6);
}
receive() payable external {
// Send the fund to the owner of the contract.
owner.transfer(address(this).balance);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment