|
import { TezosWalletUtil, TezosNodeWriter, StoreType, setLogLevel, TezosParameterFormat } from 'conseiljs'; |
|
|
|
setLogLevel('debug'); |
|
|
|
const tezosNode = '<tezos-node-url>'; |
|
const conseilServer = { url: '<conseil-indexer-url>', apiKey: '<API key from nautilus.cloud>' }; |
|
|
|
let keystore = { |
|
publicKey: 'edpktm42BxqEUNkEed5F1aYH6BmLpvTkWVi8pLr5tXPaRAJwYt5CqS', |
|
privateKey: 'edskRdS3MWFjjAQkZ9sFmdDxDG5mxLGzHMiitn55Dfym18qm248o9tpHLoyd53YVFdfCe38KdFuW6AJ3XkhHhybdHYA9MXHXZ6', |
|
publicKeyHash: 'tz1SEfZcPTmC12uPQyCcLn12Ui3P1p9htbPb', |
|
seed: '', |
|
storeType: StoreType.Fundraiser |
|
}; |
|
|
|
const alphanetFaucetAccount = { |
|
"mnemonic": [ "remember", "horse", "deer", "rival", "anxiety", "parrot", "web", "dutch", "broccoli", "onion", "raise", "shine", "bean", "alpha", "argue" ], |
|
"secret": "9ded7f76716a97a31492b4481558cc2d87e213a5", |
|
"amount": "31303101857", |
|
"pkh": "tz1SEfZcPTmC12uPQyCcLn12Ui3P1p9htbPb", |
|
"password": "Gn6NqSb4Ku", |
|
"email": "[email protected]" |
|
} |
|
|
|
async function initAccount() { |
|
keystore = await TezosWalletUtil.unlockFundraiserIdentity(alphanetFaucetAccount.mnemonic.join(' '), alphanetFaucetAccount.email, alphanetFaucetAccount.password, alphanetFaucetAccount.pkh); |
|
console.log(`public key: ${keystore.publicKey}`); |
|
console.log(`secret key: ${keystore.privateKey}`); |
|
console.log(`account hash: ${keystore.publicKeyHash}`); |
|
} |
|
|
|
async function activateAccount() { |
|
const result = await TezosNodeWriter.sendIdentityActivationOperation(tezosNode, keystore, alphanetFaucetAccount.secret, ''); |
|
console.log(`Injected operation group id ${result.operationGroupID}`) |
|
} |
|
|
|
async function revealAccount() { |
|
const result = await TezosNodeWriter.sendKeyRevealOperation(tezosNode, keystore); |
|
console.log(`Injected operation group id ${result.operationGroupID}`); |
|
} |
|
|
|
async function sendTransaction() { |
|
const result = await TezosNodeWriter.sendTransactionOperation(tezosNode, keystore, 'tz1aCy8b6Ls4Gz7m5SbANjtMPiH6dZr9nnS2', 500000, 1500, ''); |
|
console.log(`Injected operation group id ${result.operationGroupID}`); |
|
} |
|
|
|
async function originateAccount() { |
|
const result = await TezosNodeWriter.sendAccountOriginationOperation(tezosNode, keystore, 100000000, 'tz3gN8NTLNLJg5KRsUU47NHNVHbdhcFXjjaB', true, true, 10000, ''); |
|
console.log(`Injected operation group id ${result.operationGroupID}`); |
|
} |
|
|
|
async function deployContract() { |
|
const contract = `[ |
|
{ |
|
"prim":"parameter", |
|
"args":[ { "prim":"string" } ] |
|
}, |
|
{ |
|
"prim":"storage", |
|
"args":[ { "prim":"string" } ] |
|
}, |
|
{ |
|
"prim":"code", |
|
"args":[ |
|
[ |
|
{ "prim":"CAR" }, |
|
{ "prim":"NIL", "args":[ { "prim":"operation" } ] }, |
|
{ "prim":"PAIR" } |
|
] |
|
] |
|
} |
|
]`; |
|
const storage = '{"string": "Sample"}'; |
|
|
|
const nodeResult = await TezosNodeWriter.sendContractOriginationOperation(tezosNode, keystore, 0, undefined, false, true, 100000, '', 1000, 100000, contract, storage, TezosParameterFormat.Micheline); |
|
const groupid = nodeResult['operationGroupID'].replace(/\"/g, '').replace(/\n/, ''); // clean up RPC output |
|
console.log(`Injected operation group id ${groupid}`); |
|
const conseilResult = await TezosConseilClient.awaitOperationConfirmation(conseilServer, 'alphanet', groupid, 5); |
|
console.log(`Originated contract at ${conseilResult[0].originated_accounts}`); |
|
} |
|
|
|
async function deployMichelsonContract() { |
|
const contract = `parameter string; |
|
storage string; |
|
code { DUP; |
|
DIP { CDR ; NIL string ; SWAP ; CONS } ; |
|
CAR ; CONS ; |
|
CONCAT; |
|
NIL operation; PAIR}`; |
|
const storage = '"Sample"'; |
|
|
|
const result = await TezosNodeWriter.sendContractOriginationOperation(tezosNode, keystore, 0, undefined, false, true, 100000, '', 1000, 100000, contract, storage, TezosParameterFormat.Michelson); |
|
console.log(`Injected operation group id ${result.operationGroupID}`); |
|
} |
|
|
|
async function invokeContract() { |
|
const contractAddress = 'KT1MtZ2GJp8qxAhrjq5ppgmyFBTRRWZPodJa'; |
|
const result = await TezosNodeWriter.sendContractInvocationOperation(tezosNode, keystore, contractAddress, 10000, 1000000, '', 1000, 100000, '"Cryptonomicon"', TezosParameterFormat.Michelson); |
|
console.log(`Injected operation group id ${result.operationGroupID}`); |
|
} |
|
|
|
|
|
async function deploySmartPyContract() { |
|
const contract = ` |
|
parameter string; |
|
|
|
storage string; |
|
|
|
code |
|
{ |
|
# Entry point: setPhrase # pair(params, storage) |
|
# self.data.phrase = params.newPhrase # pair(params, storage) |
|
DUP; # pair(params, storage).pair(params, storage) |
|
CAR; # params.pair(params, storage) |
|
SWAP; # pair(params, storage).storage |
|
DROP; # storage |
|
NIL operation; # operations.storage |
|
PAIR; # pair(operations, storage) |
|
} # pair(operations, storage);`; |
|
const storage = '"Hello World"'; |
|
|
|
const result = await TezosNodeWriter.sendContractOriginationOperation(tezosNode, keystore, 0, undefined, false, true, 100000, '', 1000, 100000, contract, storage, TezosParameterFormat.Michelson); |
|
console.log(`Injected operation group id ${result.operationGroupID}`); |
|
} |
|
|
|
async function run() { |
|
//await initAccount(); |
|
//await activateAccount(); |
|
//await revealAccount(); |
|
//await sendTransaction(); |
|
//await originateAccount(); |
|
//await deployContract(); |
|
//await deployMichelsonContract(); |
|
await deploySmartPyContract(); |
|
//await invokeContract(); |
|
} |
|
|
|
run(); |
how to get an
alphanetFaucetAccount
on the main net