Created
October 25, 2018 14:15
-
-
Save nicklatkovich/d05114c75d0aba8ba99427c73f3d5d54 to your computer and use it in GitHub Desktop.
Echo deployer
This file contains 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
const { ChainStore, PrivateKey, ContractFrame } = require('echojs-lib'); | |
const { Apis } = require('echojs-ws'); | |
const wif = 'ENTER_WIF_HERE'; | |
const bytecode = 'ENTER_BYTECODE_HERE'; | |
const gasLimit = 10e6; | |
const privateKey = PrivateKey.fromWif(wif); | |
const publicKey = privateKey.toPublicKey(); | |
const contractFrame = new ContractFrame(); | |
async function deploy() { | |
const instance = Apis.instance('wss://echo-dev.io/ws', true); | |
await instance.init_promise; | |
const accountId = await ChainStore.FetchChain('getAccountRefsOfKey', publicKey.toString()) | |
.then((res) => res.toJS()[0]); | |
const [{ trx: { operation_results: [[_, resId]] } }] = await contractFrame.deployContract({ | |
accountId: accountId, | |
gas: gasLimit, | |
bytecode, | |
}, privateKey); | |
const { | |
exec_res: { new_address }, | |
} = await instance.dbApi().exec('get_contract_result', [resId]); | |
console.log(`Contract id: 1.16.${Number.parseInt(new_address.slice(8), 16)}`); | |
} | |
deploy().then(() => process.exit(0)).catch((error) => { | |
console.error(error); | |
process.exit(1); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment