Skip to content

Instantly share code, notes, and snippets.

@Tschuck
Last active May 27, 2019 06:21
Show Gist options
  • Save Tschuck/e9c76e7005c56d7f7008f0d990799334 to your computer and use it in GitHub Desktop.
Save Tschuck/e9c76e7005c56d7f7008f0d990799334 to your computer and use it in GitHub Desktop.
evan.network - api-blockchain-core sample browserified
<html>
<head>
<script src="./node_modules/@evan.network/api-blockchain-core-browserified/dist/bcc.js"></script>
<script src="./node_modules/@evan.network/smart-contracts-core-browserified/dist/compiled.js"></script>
<script src="https://cdn.jsdelivr.net/npm/ipfs-api@26.1.2/dist/index.min.js"></script>
<script src="https://cdn.jsdelivr.net/gh/ethereum/web3.js@1.0.0-beta.33/dist/web3.min.js"></script>
</head>
<script>
// ipfs configuration for evan.network testnet storage
const ipfsConfig = {host: 'ipfs.test.evan.network', port: '443', protocol: 'https'};
// web3 provider config (currently evan.network testcore)
const web3Provider = 'wss://testcore.evan.network/ws';
async function init() {
// initialize dependencies
const provider = new Web3.providers.WebsocketProvider(
web3Provider,
{ clientConfig: { keepalive: true, keepaliveInterval: 5000 } }
);
const web3 = new Web3(provider, { transactionConfirmationBlocks: 1, protocol: [ ] });
const dfs = new bcc.Ipfs({ remoteNode: new IpfsApi(ipfsConfig), });
const formattedContracts = { };
Object.keys(smartcontracts).forEach((key) => {
const contractKey = (key.indexOf(':') !== -1) ? key.split(':')[1] : key;
formattedContracts[contractKey] = smartcontracts[key];
});
// create runtime
const runtime = await bcc.createDefaultRuntime(web3, dfs, {
mnemonic: 'leave best ship pulp hospital used damp decorate say mobile glance dilemma',
password: 'T1234567',
}, {
contracts: formattedContracts,
});
console.log(runtime)
}
init();
</script>
</html>
{
"dependencies": {
"@evan.network/api-blockchain-core-browserified": "^2.3.1",
"@evan.network/smart-contracts-core-browserified": "^2.1.2"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment