Skip to content

Instantly share code, notes, and snippets.

@hackdapp
Created April 3, 2019 06:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hackdapp/b200b70b1e5d32fa9e7ae1fc082681cc to your computer and use it in GitHub Desktop.
Save hackdapp/b200b70b1e5d32fa9e7ae1fc082681cc to your computer and use it in GitHub Desktop.
const fs = require('fs')
const path = require('path')
function getDeployableFilesFromDir(dir) {
const dirCont = fs.readdirSync(dir)
const wasmFileName = dirCont.find(filePath => filePath.match(/.*\.(wasm)$/gi))
const abiFileName = dirCont.find(filePath => filePath.match(/.*\.(abi)$/gi))
if (!wasmFileName) throw new Error(`Cannot find a ".wasm file" in ${dir}`)
if (!abiFileName) throw new Error(`Cannot find an ".abi file" in ${dir}`)
return {
wasmPath: path.join(dir, wasmFileName),
abiPath: path.join(dir, abiFileName),
}
}
function deployContract(eos, { account, contractDir }) {
const { wasmPath, abiPath } = getDeployableFilesFromDir(contractDir)
const wasm = fs.readFileSync(wasmPath)
const abi = fs.readFileSync(abiPath)
const codePromise = eos.setcode(account, 0, 0, wasm)
const abiPromise = eos.setabi(account, JSON.parse(abi))
return Promise.all([codePromise, abiPromise])
}
module.exports = {deployContract}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment