Skip to content

Commit

Permalink
Added transfer USDC script and
Browse files Browse the repository at this point in the history
turned input field into type number.
  • Loading branch information
ethan-crypto committed Jan 14, 2022
1 parent a192703 commit 3c32f28
Show file tree
Hide file tree
Showing 10 changed files with 2,055 additions and 2,003 deletions.
30 changes: 30 additions & 0 deletions scripts/transferUSDC.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
const IERC20 = artifacts.require("IERC20");

const toUSDC = (num) => web3.utils.toWei(num.toString(), "mwei")
const fromUSDC = (num) => web3.utils.fromWei(num.toString(), "mwei")

module.exports = async function (callback) {
try {
const usdcAddress = "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48"
const unlockedAccount = "0xc647F8f745a59B74A26d76Da7dcCc8BadF649C32"
// Accounts given to us by ganache
const accounts = await web3.eth.getAccounts()
const usdc = new web3.eth.Contract(IERC20.abi, usdcAddress)
// Fetch unlocked account and first development account usdc balances
const balanceUnlocked = await usdc.methods.balanceOf(unlockedAccount).call()
const balanceDev = await usdc.methods.balanceOf(accounts[0]).call()
console.log(`Unlocked account usdc balance before transfer ${fromUSDC(balanceUnlocked)}`)
console.log(`First dev account usdc balance before transfer ${fromUSDC(balanceDev)}`)
// Transfer unlocked accounts usdc balance to the first development account
await usdc.methods.transfer(accounts[0], balanceUnlocked).send({from: unlockedAccount})
// Fetch new development usdc balance
const newBalanceDev = await usdc.methods.balanceOf(accounts[0]).call()
const newBalanceUnlocked = await usdc.methods.balanceOf(unlockedAccount).call()
console.log(`Unlocked account usdc balance after transfer ${fromUSDC(newBalanceUnlocked)}`)
console.log(`First dev account usdc balance after transfer ${fromUSDC(newBalanceDev)}`)
}
catch (error) {
console.log(error)
}
callback()
}
38 changes: 38 additions & 0 deletions src/App.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
.App {
text-align: center;
}

.App-logo {
height: 40vmin;
pointer-events: none;
}

@media (prefers-reduced-motion: no-preference) {
.App-logo {
animation: App-logo-spin infinite 20s linear;
}
}

.App-header {
background-color: #282c34;
min-height: 100vh;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
font-size: calc(10px + 2vmin);
color: white;
}

.App-link {
color: #61dafb;
}

@keyframes App-logo-spin {
from {
transform: rotate(0deg);
}
to {
transform: rotate(360deg);
}
}
Loading

0 comments on commit 3c32f28

Please sign in to comment.