Skip to content

Instantly share code, notes, and snippets.

@alexroan
Created June 18, 2020 09:51
Show Gist options
  • Save alexroan/69cfca435c5cfdc92f5e870955fe5e1c to your computer and use it in GitHub Desktop.
Save alexroan/69cfca435c5cfdc92f5e870955fe5e1c to your computer and use it in GitHub Desktop.
exchange-script.js
// Contracts
const Exchange = artifacts.require("Exchange")
// Utils
const ether = (n) => {
return new web3.utils.BN(
web3.utils.toWei(n.toString(), 'ether')
)
}
module.exports = async function(callback) {
try {
// Fetch accounts from wallet - these are unlocked
const accounts = await web3.eth.getAccounts()
// Fetch the deployed exchange
const exchange = await Exchange.deployed()
console.log('Exchange fetched', exchange.address)
// Set up exchange users
const user1 = accounts[0]
// User 1 Deposits Ether
amount = 2
await exchange.depositEther({ from: user1, value: ether(amount) })
console.log(`Deposited ${amount} Ether from ${user1}`)
//...
}
catch(error) {
console.log(error)
}
callback()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment