UNPKG

@windingtree/wt-write-api

Version:

API to write data to the Winding Tree platform

58 lines (51 loc) 2.15 kB
const lib = require('zos-lib'); const Web3 = require('web3'); const { ethereumProvider } = require('../config'); const provider = new Web3.providers.HttpProvider(ethereumProvider); const web3 = new Web3(provider); const deployApp = async () => { // Setup a local copy of zos package for wt-contracts const ZWeb3 = lib.ZWeb3; ZWeb3.initialize(web3.currentProvider); const Contracts = lib.Contracts; Contracts.setArtifactsDefaults({ gas: 6721975, gasPrice: 100000000000, }); const accounts = await web3.eth.getAccounts(); // setup the project with all the proxies const project = await lib.AppProject.fetchOrDeploy('wt-contracts', '0.0.1'); const Organization = Contracts.getFromNodeModules('@windingtree/wt-contracts', 'Organization'); const Entrypoint = Contracts.getFromNodeModules('@windingtree/wt-contracts', 'WindingTreeEntrypoint'); const OrganizationFactory = Contracts.getFromNodeModules('@windingtree/wt-contracts', 'OrganizationFactory'); const SegmentDirectory = Contracts.getFromNodeModules('@windingtree/wt-contracts', 'SegmentDirectory'); await project.setImplementation(Entrypoint, 'WindingTreeEntrypoint'); await project.setImplementation(Organization, 'Organization'); await project.setImplementation(OrganizationFactory, 'OrganizationFactory'); await project.setImplementation(SegmentDirectory, 'SegmentDirectory'); // setup the factory proxy const factory = await project.createProxy(OrganizationFactory, { initFunction: 'initialize', initArgs: [accounts[1], project.getApp().address], from: accounts[1], }); // setup the entrypoint proxy const entrypoint = await project.createProxy(Entrypoint, { initFunction: 'initialize', initArgs: [accounts[1], '0xb6e225194a1c892770c43d4b529841c99b3da1d7', factory.address], from: accounts[1], }); const directory = await project.createProxy(SegmentDirectory, { initFunction: 'initialize', initArgs: [accounts[1], 'hotels', '0xb6e225194a1c892770c43d4b529841c99b3da1d7'], from: accounts[1], }); return { directory, factory, entrypoint, }; }; module.exports = { deployApp, };