Skip to content

Instantly share code, notes, and snippets.

@anonymoussprocket
Last active June 24, 2020 04:18
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 anonymoussprocket/20d0fae1355da9f6153ee5faca6798df to your computer and use it in GitHub Desktop.
Save anonymoussprocket/20d0fae1355da9f6153ee5faca6798df to your computer and use it in GitHub Desktop.
Cryptonomic Tezos developer workshop materials

Workshop

These materials are meant to accompany the live workshops by Cryptonomic for blockchain and smart contract development. This version focuses on the Tezos chain and smart contract development with SmartPy.

Content

The code in this workship is written Typescript. We will use the ConseilJS library to interact with the Tezos Alphanet chain. It is possible to use the ConseilJS npm package with nodejs directly with JavaScript. There is also a minified deployment for use on websites. The smart contract section follows the Smart Contract Development Syllabus and uses SmartPy. The contracts covered in the syllabus are also available on Github. While this introduction coveres much of the Tezos user workflows, some things are out of scope. Please refer to the full ConseilJS Documentation for more information and to learn about additionaly functionality this library provides.

Prerequisites

This tutorial requires nodejs 8+ and npm.

Steps

Create a new directory for this workshop. Inside that directory place the rest of the files in this gist. Once that's done, from a commandline window navigate to that directory and run npm i.

Other Links

{
"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": "niierepj.numhuipy@tezos.example.org"
}
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": "niierepj.numhuipy@tezos.example.org"
}
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();
{
"name": "london-demo",
"version": "1.0.0",
"description": "London Demo",
"main": "index.ts",
"scripts": {
"build": "tsc index.ts",
"run": "node index.js"
},
"author": "",
"license": "UNLICENSED",
"bugs": {
"url": ""
},
"homepage": "",
"dependencies": {
"conseiljs": "^0.2.9",
"typescript": "^3.5.3"
}
}
@lijianl
Copy link

lijianl commented Mar 30, 2020

how to get an alphanetFaucetAccount on the main net

@lijianl
Copy link

lijianl commented Mar 30, 2020

async function sendTransaction() {
const result = await TezosNodeWriter.sendTransactionOperation(tezosNode, keystore, 'tz1aCy8b6Ls4Gz7m5SbANjtMPiH6dZr9nnS2', 500000, 1500, '');
console.log(Injected operation group id ${result.operationGroupID});
}

how could I transfer value out from "tz1aCy8b6Ls4Gz7m5SbANjtMPiH6dZr9nnS2" that is just a Mnemonic account

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment