Published
Edited
Jun 23, 2020
Insert cell
Insert cell
Insert cell
rpcUrl = "http://127.0.0.1:2000" // Ensure this matches your local RPC url
Insert cell
Insert cell
Insert cell
Insert cell
maker = {
testchainFound; // wait for the testchain
return Maker.create('http', {
plugins: [daiMcd.McdPlugin],
provider: {
url: rpcUrl,
type: 'HTTP'
}
});
}
Insert cell
Insert cell
Insert cell
Insert cell
currentBlock = Generators.observe(next => {
next(maker.service('web3').blockNumber());
maker.service('web3').onNewBlock(block => {
next(block);
});
})
Insert cell
maker.on
Insert cell
Insert cell
(await maker.getToken(daiMcd.ETH).balance()).toString()
Insert cell
(await maker.getToken(daiMcd.BAT).balance()).toString()
Insert cell
(await maker.getToken(daiMcd.USDC).balance()).toString()
Insert cell
Insert cell
Insert cell
TestAccountProvider = (await require("https://unpkg.com/@makerdao/test-helpers"))
.TestAccountProvider
Insert cell
Insert cell
viewof addWalletBtn = {
async function addWallet() {
await maker.service('accounts').addAccount(randomPhrase(), {
//
type: 'privateKey',
key: TestAccountProvider.nextAccount().key // grab the next private key from the te
});
}
return html`<button onclick=${() => addWallet()}>add a wallet</>`;
}
Insert cell
Insert cell
(addWalletBtn, table(maker.listAccounts(), { pageSize: 5 })) // rerun on btn click
Insert cell
Insert cell
viewof walletSelector = (addWalletBtn,
html`<select onchange=${event => maker.useAccount(event.target.value)}>
${maker
.listAccounts()
.map(
({ name }) =>
html`<option value=${name} selected=${maker.currentAccount()
.name === name}>${name}</>`
)}
</select>`)
Insert cell
Insert cell
currentAccount = Generators.observe(next => {
next(maker.currentAccount());
maker.on('accounts/CHANGE', ({ payload }) => {
next(payload.account);
});
})
Insert cell
Insert cell
Insert cell
html`<button onclick=${() => {
const tx = maker
.getToken('MKR')
.transfer("0x0000000000000000000000000000000000000000", 0.5); // send 0.5 MKR to the zero address
track(tx);
}}>Send MKR`
Insert cell
Insert cell
Insert cell
function track(txObject) {
maker.service('transactionManager').listen(txObject, {
pending: tx => {
mutable sendMkrTxState = { status: "pending", hash: tx.hash };
},
mined: tx => {
mutable sendMkrTxState = { status: "mined", hash: tx.hash };
}
});
}
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
md`Before that, though, let's see what vault types are available to dai.js by default. \n \n
**Vault Types**
${maker.service('mcd:cdpType').cdpTypes.map(
type => `* ${type.ilk}
* Debt Ceiling: ${type.debtCeiling}
* Liquidation Ratio: ${type.liquidationRatio}
* Collateral Price ${type.price} \n`
)}`
Insert cell
Insert cell
// maker.service('mcd:cdpManager').openLockAndDraw("ETH-A", daiMcd.ETH(2), 100)
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell

One platform to build and deploy the best data apps

Experiment and prototype by building visualizations in live JavaScript notebooks. Collaborate with your team and decide which concepts to build out.
Use Observable Framework to build data apps locally. Use data loaders to build in any language or library, including Python, SQL, and R.
Seamlessly deploy to Observable. Test before you ship, use automatic deploy-on-commit, and ensure your projects are always up-to-date.
Learn more