Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat : update to newest version #13

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"printWidth": 100,
"tabWidth": 2,
"singleQuote": true,
"semi": true,
"endOfLine": "auto",
"arrowParens": "always",
"bracketSpacing": true
}
2 changes: 1 addition & 1 deletion build.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const { exec } = require("child_process");
const fs = require("fs");

exec(`docker run -v $PWD:$PWD --rm -i ligolang/ligo:next compile-contract --michelson-format=json $PWD/contracts/Token.ligo main`, (err, stdout, stderr) => {
exec(`docker run -v $PWD:$PWD --rm -i ligolang/ligo:0.22.0 compile-contract --michelson-format=json $PWD/contracts/Token.ligo main`, (err, stdout, stderr) => {
if (err)
throw err

Expand Down
181 changes: 97 additions & 84 deletions cli.js
Original file line number Diff line number Diff line change
@@ -1,92 +1,105 @@
const fs = require("fs");
const fs = require('fs');
const program = require('commander');
const { Tezos } = require('@taquito/taquito');
const { TezosToolkit, MichelsonMap } = require('@taquito/taquito');
const { importKey } = require('@taquito/signer');
const { encodeExpr } = require('@taquito/utils');
const { HttpBackend } = require('@taquito/http-utils');
program.version('0.0.1');

const setup = async () => {
const { email, password, mnemonic, secret } = JSON.parse(fs.readFileSync('./faucet.json').toString())

Tezos.setProvider({ rpc: "https://api.tez.ie/rpc/babylonnet" })

await Tezos.importKey(email, password, mnemonic.join(" "), secret)
return Tezos;
}

program.command("deploy <total_supply>")
.action(async (total_supply, command) => {
console.log('Deploying...')
try {
const Tezos = await setup();
const op = await Tezos.contract.originate({
code: JSON.parse(fs.readFileSync("./build/Token.json").toString()),
storage: {
totalSupply: total_supply,
ledger: {
[await Tezos.signer.publicKeyHash()]: {
balance: total_supply,
allowances: {
[await Tezos.signer.publicKeyHash()]: total_supply,
},
}
}
},
})
const contract = await op.contract();
console.log('Deployed at address: ', contract.address)
} catch (ex) {
console.error(ex)
}
})

const prettyPrint = (obj) => JSON.stringify(obj, null, 2)

program.command("storage <address>")
.action(async (address, command) => {
try {
const Tezos = await setup();
const contract = await Tezos.contract.at(address)
const storage = prettyPrint(await contract.storage());
const rawStorage = prettyPrint(await Tezos.rpc.getStorage(address))
console.log(`Storage:\n${storage}`)
console.log(`Raw Storage:\n${rawStorage}`)
} catch (ex) {
console.error(ex)
}
})

program.command("account")
.action(async () => {
try {
const Tezos = await setup();
console.log(await Tezos.signer.publicKeyHash())
} catch (ex) {
console.error(ex)
}
})

program.command("bigMap <address> <key>")
.action(async (address, keyToEncode, command) => {
try {
const Tezos = await setup();
const contract = await Tezos.contract.at(address)
const storage = await contract.storage()

const bigMapID = storage.ledger.id.toString()

const { key, type } = storage.ledger.schema.EncodeBigMapKey(keyToEncode);
const { packed } = await Tezos.rpc.packData({ data: key, type });

const encodedExpr = encodeExpr(packed);

const bigMapValue = prettyPrint(await storage.ledger.get(keyToEncode))
const rawBigMapValue = prettyPrint(await Tezos.rpc.getBigMapExpr(bigMapID, encodedExpr));
console.log(`Storage:\n${bigMapValue}`)
console.log(`Raw Storage:\n${rawBigMapValue}`)
} catch (ex) {
console.error(ex)
}
})
const { email, password, mnemonic, secret } = JSON.parse(
fs.readFileSync('./faucet.json').toString()
);

var Tezos = new TezosToolkit('https://florencenet.smartpy.io');

// await importKey(Tezos, email, password, mnemonic.join(' '), secret);
await importKey(Tezos, email, password, mnemonic.join(' '), secret).catch((e) =>
console.error('\nerror :' + e)
);
return Tezos;
};

program.command('deploy <total_supply>').action(async (total_supply, command) => {
console.log('Deploying...');
try {
const Tezos = await setup();
const userAddress = await Tezos.signer.publicKeyHash();
const allowances = MichelsonMap.fromLiteral({ [userAddress]: total_supply });

const ledger = MichelsonMap.fromLiteral({
[userAddress]: {
balance: total_supply,
allowances: allowances,
},
});

const extras = MichelsonMap.fromLiteral({});
const op = await Tezos.contract.originate({
code: JSON.parse(fs.readFileSync('./build/Token.json').toString()),
storage: {
name: 'MyToken',
symbol: 'MT',
decimals: 6,
extras,
owner: userAddress,
totalSupply: total_supply,
ledger: ledger,
},
});

const contract = await op.contract();
console.log('Deployed at address: ', contract.address);
} catch (ex) {
console.error('ex');
console.error(ex);
}
});

const prettyPrint = (obj) => JSON.stringify(obj, null, 2);

program.command('storage <address>').action(async (address, command) => {
try {
const Tezos = await setup();
const contract = await Tezos.contract.at(address);
const storage = prettyPrint(await contract.storage());
const rawStorage = prettyPrint(await Tezos.rpc.getStorage(address));
console.log(`Storage:\n${storage}`);
console.log(`Raw Storage:\n${rawStorage}`);
} catch (ex) {
console.error(ex);
}
});

program.command('account').action(async () => {
try {
const Tezos = await setup();
console.log(await Tezos.signer.publicKeyHash());
} catch (ex) {
console.error(ex);
}
});

program.command('bigMap <address> <key>').action(async (address, keyToEncode, command) => {
try {
const Tezos = await setup();
const contract = await Tezos.contract.at(address);
const storage = await contract.storage();

const bigMapID = storage.ledger.id.toString();

const { key, type } = storage.ledger.schema.EncodeBigMapKey(keyToEncode);
const { packed } = await Tezos.rpc.packData({ data: key, type });

const encodedExpr = encodeExpr(packed);

const bigMapValue = prettyPrint(await storage.ledger.get(keyToEncode));
const rawBigMapValue = prettyPrint(await Tezos.rpc.getBigMapExpr(bigMapID, encodedExpr));
console.log(`Storage:\n${bigMapValue}`);
console.log(`Raw Storage:\n${rawBigMapValue}`);
} catch (ex) {
console.error(ex);
}
});

program.parse(process.argv);
Loading