Last active
July 25, 2019 04:33
-
-
Save pizzarob/1b524ce8ec55d9b1d9f1ec2da7b8ac3b to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Initialize cargo using the development network. This will | |
// tell Cargo to use it's contracts on the Rinkeby network. | |
const cargo = new Cargo({ | |
network: 'development', | |
}); | |
const run = async () => { | |
// This will fetch Cargo contract information | |
// so we can begin interacting with those contracts when we are ready. | |
await cargo.init(); | |
// The init and enable functions return Promises, so we are using async/await | |
// to easily handle these asynchronous functions. | |
// In order to interact with cargo contracts we will need to call the enable method. | |
// This determines if the user has a provider available that will allow us to connect | |
// to the Ethereum blockchain. | |
const isEnabled = await cargo.enable(); | |
// cargo.enable returns true or false, depending on whether or not we can interact with | |
// the Cargo smart contracts. We are passing that boolean value to the showContent function | |
// which will show content for each case. If isEnabled equals false then we can show UI | |
// that tells the user to install MetaMask, or another MetaMask type product. | |
showContent(isEnabled); | |
}; | |
run(); | |
/** | |
* UTILITY FUNCTIONS. NO NEED TO MODIFY. | |
*/ | |
function showContent(isEnabled) { | |
const el = document.querySelector( | |
`[data-id="provider-${isEnabled ? 'enabled' : 'required'}"]` | |
); | |
el.classList.remove('hide'); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment