From b5c6c23c6df5d26f7e1c65da5c72bfbde41b0c2e Mon Sep 17 00:00:00 2001 From: Rodrigo Quelhas Date: Mon, 31 Jan 2022 12:54:21 +0000 Subject: [PATCH] docs(taquito, conseiljs, fa2, values): Adds value documentation and usage examples --- documentation/docs/FA2.md | 99 +++++ documentation/docs/conseiljs.md | 195 ++++++++ documentation/docs/taquito.md | 133 +++++- documentation/docs/types.md | 29 ++ documentation/docs/values.md | 542 ++++++++++++++++++++++- documentation/sidebars.js | 8 + tests/e2e/__snapshots__/all.test.ts.snap | 6 +- tests/e2e/validate_michelson.ts | 2 - 8 files changed, 996 insertions(+), 18 deletions(-) create mode 100644 documentation/docs/FA2.md create mode 100644 documentation/docs/conseiljs.md diff --git a/documentation/docs/FA2.md b/documentation/docs/FA2.md new file mode 100644 index 0000000..3c669f6 --- /dev/null +++ b/documentation/docs/FA2.md @@ -0,0 +1,99 @@ +# FA2 Interface + +## Entrypoint Parameter + +### transfer + +- [Using Taquito](./taquito#transfer) +- [Using ConseilJS](./conseiljs#transfer) + +```ts +const { Record, Address, List, Nat } = require('@tezwell/michelson-sdk/literal'); + +const parameters = List( + [ + Record({ + from_: Address("tz1gTnKMA65qaKVpp6x4cgMLU2UyKF2zjHYN"), + txs: List( + [ + Record({ + to_: Address("KT1JehYdejjvFf1BqdXzTPt1QWqqSd3xS4JF"), + token_id: Nat(0), + amount: Nat(10), + }) + ] + ), + }) + ] +).toJSON(); +``` + +### balance_of + +- [Using Taquito](./taquito#balance_of) +- [Using ConseilJS](./conseiljs#balance_of) + +```ts +const { Record, Address, List, Nat } = require('@tezwell/michelson-sdk/literal'); + +const parameters = Record({ + requests: List( + [ + Record({ + owner: Address("KT1JehYdejjvFf1BqdXzTPt1QWqqSd3xS4JF"), + token_id: Nat(0) + }), + Record({ + owner: Address("tz1gTnKMA65qaKVpp6x4cgMLU2UyKF2zjHYN"), + token_id: Nat(0) + }) + ] + ), + callback: Contract("KT1SiSomCunxkq3g7vQKYpPpWBHodhH5pJkU", "receive_balances") +}).toJSON(); +``` + +### update_operators + +- [Using Taquito](./taquito#update_operators) +- [Using ConseilJS](./conseiljs#update_operators) + +```ts +const { Record, Address, List, Nat, Variant } = require('@tezwell/michelson-sdk/literal'); +const { TRecord, TAddress, TNat, TVariant } = require('@tezwell/michelson-sdk/type'); + +const VariantType = TVariant({ + add_operator: TRecord({ + owner: TAddress(), + operator: TAddress(), + token_id: TNat(), + }), + remove_operator: TRecord({ + owner: TAddress(), + operator: TAddress(), + token_id: TNat(), + }) +}); +const parameters = List( + [ + Variant( + "add_operator", + Record({ + owner: Address("tz1gTnKMA65qaKVpp6x4cgMLU2UyKF2zjHYN"), + operator: Address("KT1JehYdejjvFf1BqdXzTPt1QWqqSd3xS4JF"), + token_id: Nat(0), + }), + VariantType + ), + Variant( + "remove_operator", + Record({ + owner: Address("tz1gTnKMA65qaKVpp6x4cgMLU2UyKF2zjHYN"), + operator: Address("KT1JehYdejjvFf1BqdXzTPt1QWqqSd3xS4JF"), + token_id: Nat(0), + }), + VariantType + ) + ] +).toJSON(); +``` diff --git a/documentation/docs/conseiljs.md b/documentation/docs/conseiljs.md new file mode 100644 index 0000000..f220c63 --- /dev/null +++ b/documentation/docs/conseiljs.md @@ -0,0 +1,195 @@ +# Using with ConseilJS + +## Install dependencies + +```shell +npm install @tezwell/michelson-sdk conseiljs conseiljs-softsigner node-fetch loglevel +``` + +## Interact with an FA2 contract + +### transfer + +```ts +import fetch from 'node-fetch'; +import log from 'loglevel'; + +import { registerFetch, registerLogger, TezosMessageUtils, TezosParameterFormat, TezosNodeWriter } from 'conseiljs'; +import { KeyStoreUtils, SoftSigner } from 'conseiljs-softsigner'; +import { Record, Address, List, Nat } from '@tezwell/michelson-sdk/literal'; + +const logger = log.getLogger('conseiljs'); +logger.setLevel('debug', false); // to see only errors, set to 'error' +registerLogger(logger); +registerFetch(fetch); + +const RPC = 'https://ithacanet.visualtez.com'; +const contract = 'KT1JehYdejjvFf1BqdXzTPt1QWqqSd3xS4JF' + +const parameters = List( + [ + Record({ + from_: Address('tz1gTnKMA65qaKVpp6x4cgMLU2UyKF2zjHYN'), + txs: List( + [ + Record({ + to_: Address('KT1JehYdejjvFf1BqdXzTPt1QWqqSd3xS4JF'), + token_id: Nat(0), + amount: Nat(10), + }) + ] + ), + }) + ] +).toJSON(); + +(async () => { + const keyStore = await KeyStoreUtils.restoreIdentityFromSecretKey('edskS83aZUK3ijLrW5tTs1sDY3qLjSsMGyebKKLWP4RXSBh4LCivG2s1TezyZB5rEvvdqepXMg1MLcfBhS8VSJESN7L27hDpsX'); + const signer = await SoftSigner.createSigner(TezosMessageUtils.writeKeyWithHint(keyStore.secretKey, 'edsk'), -1); + + const result = await TezosNodeWriter.sendContractInvocationOperation( + RPC, + signer, + keyStore, + contract, + 10_000, + 100_000, + 10_000, + 100_000, + 'transfer', + JSON.stringify(parameters), + TezosParameterFormat.Micheline + ); + console.log("Injected operation: ", result.operationGroupID); +})(); +``` + +### balance_of + +```ts +import fetch from 'node-fetch'; +import log from 'loglevel'; + +import { registerFetch, registerLogger, TezosMessageUtils, TezosParameterFormat, TezosNodeWriter } from 'conseiljs'; +import { KeyStoreUtils, SoftSigner } from 'conseiljs-softsigner'; +import { Record, Address, List, Nat, Contract } from '@tezwell/michelson-sdk/literal'; + +const logger = log.getLogger('conseiljs'); +logger.setLevel('debug', false); // to see only errors, set to 'error' +registerLogger(logger); +registerFetch(fetch); + +const RPC = 'https://ithacanet.visualtez.com'; +const contract = 'KT1JehYdejjvFf1BqdXzTPt1QWqqSd3xS4JF' + +const parameters = Record({ + requests: List( + [ + Record({ + owner: Address("KT1JehYdejjvFf1BqdXzTPt1QWqqSd3xS4JF"), + token_id: Nat(0) + }), + Record({ + owner: Address("tz1gTnKMA65qaKVpp6x4cgMLU2UyKF2zjHYN"), + token_id: Nat(0) + }) + ] + ), + callback: Contract("KT1SiSomCunxkq3g7vQKYpPpWBHodhH5pJkU", "receive_balances") +}).toJSON(); + +(async () => { + const keyStore = await KeyStoreUtils.restoreIdentityFromSecretKey('edskS83aZUK3ijLrW5tTs1sDY3qLjSsMGyebKKLWP4RXSBh4LCivG2s1TezyZB5rEvvdqepXMg1MLcfBhS8VSJESN7L27hDpsX'); + const signer = await SoftSigner.createSigner(TezosMessageUtils.writeKeyWithHint(keyStore.secretKey, 'edsk'), -1); + + const result = await TezosNodeWriter.sendContractInvocationOperation( + RPC, + signer, + keyStore, + contract, + 10_000, + 100_000, + 10_000, + 100_000, + 'balance_of', + JSON.stringify(parameters), + TezosParameterFormat.Micheline + ); + console.log("Injected operation: ", result.operationGroupID); +})(); +``` + +### update_operators + +```ts +import fetch from 'node-fetch'; +import log from 'loglevel'; + +import { registerFetch, registerLogger, TezosMessageUtils, TezosParameterFormat, TezosNodeWriter } from 'conseiljs'; +import { KeyStoreUtils, SoftSigner } from 'conseiljs-softsigner'; +import { Record, Address, List, Nat, Variant } from '@tezwell/michelson-sdk/literal'; +import { TRecord, TAddress, TNat, TVariant } from '@tezwell/michelson-sdk/type'; + +const logger = log.getLogger('conseiljs'); +logger.setLevel('debug', false); // to see only errors, set to 'error' +registerLogger(logger); +registerFetch(fetch); + +const RPC = 'https://ithacanet.visualtez.com'; +const contract = 'KT1JehYdejjvFf1BqdXzTPt1QWqqSd3xS4JF' + +const VariantType = TVariant({ + add_operator: TRecord({ + owner: TAddress(), + operator: TAddress(), + token_id: TNat(), + }), + remove_operator: TRecord({ + owner: TAddress(), + operator: TAddress(), + token_id: TNat(), + }) +}); +const parameters = List( + [ + Variant( + "add_operator", + Record({ + owner: Address("tz1gTnKMA65qaKVpp6x4cgMLU2UyKF2zjHYN"), + operator: Address("KT1JehYdejjvFf1BqdXzTPt1QWqqSd3xS4JF"), + token_id: Nat(0), + }), + VariantType + ), + Variant( + "remove_operator", + Record({ + owner: Address("tz1gTnKMA65qaKVpp6x4cgMLU2UyKF2zjHYN"), + operator: Address("KT1JehYdejjvFf1BqdXzTPt1QWqqSd3xS4JF"), + token_id: Nat(0), + }), + VariantType + ) + ] +).toJSON(); + +(async () => { + const keyStore = await KeyStoreUtils.restoreIdentityFromSecretKey('edskS83aZUK3ijLrW5tTs1sDY3qLjSsMGyebKKLWP4RXSBh4LCivG2s1TezyZB5rEvvdqepXMg1MLcfBhS8VSJESN7L27hDpsX'); + const signer = await SoftSigner.createSigner(TezosMessageUtils.writeKeyWithHint(keyStore.secretKey, 'edsk'), -1); + + const result = await TezosNodeWriter.sendContractInvocationOperation( + RPC, + signer, + keyStore, + contract, + 10_000, + 100_000, + 10_000, + 100_000, + 'update_operators', + JSON.stringify(parameters), + TezosParameterFormat.Micheline + ); + console.log("Injected operation: ", result.operationGroupID); +})(); +``` diff --git a/documentation/docs/taquito.md b/documentation/docs/taquito.md index 9425b75..abd66a9 100644 --- a/documentation/docs/taquito.md +++ b/documentation/docs/taquito.md @@ -1,10 +1,19 @@ # Using with Taquito +## Install dependencies + +```shell +npm install @tezwell/michelson-sdk @taquito/taquito @taquito/signer +``` + +## Interact with an FA2 contract + +### transfer + ```ts -const { TezosToolkit } = require('@taquito/taquito'); -const { InMemorySigner } = require('@taquito/signer'); -const { Record, Address, List, Nat } = require('@tezwell/michelson-sdk/literal'); -const { TRecord, TAddress, TList, TNat } = require('@tezwell/michelson-sdk/type'); +import { TezosToolkit } from '@taquito/taquito'; +import { InMemorySigner } from '@taquito/signer'; +import { Record, Address, List, Nat } from '@tezwell/michelson-sdk/literal'; const Tezos = new TezosToolkit('https://ithacanet.visualtez.com'); @@ -12,7 +21,7 @@ Tezos.setProvider({ signer: new InMemorySigner('edskS83aZUK3ijLrW5tTs1sDY3qLjSsMGyebKKLWP4RXSBh4LCivG2s1TezyZB5rEvvdqepXMg1MLcfBhS8VSJESN7L27hDpsX') }); -const transferParameters = List( +const parameters = List( [ Record({ from_: Address("tz1gTnKMA65qaKVpp6x4cgMLU2UyKF2zjHYN"), @@ -34,13 +43,123 @@ Tezos.contract.transfer({ amount: 0, parameter: { entrypoint: "transfer", - value: transferParameters + value: parameters + }, +}) +.then((op) => { + console.log(`Waiting for ${op.hash} to be confirmed...`); + return op.confirmation(1).then(() => op.hash); +}) +.then((hash) => console.log("Operation injected: ", hash)) +.catch((error) => console.log(`Error: ${error} ${JSON.stringify(error, null, 2)}`)); +``` + +### balance_of + +```ts +import { TezosToolkit } from '@taquito/taquito'; +import { InMemorySigner } from '@taquito/signer'; +import { Record, Address, List, Nat, Contract } from '@tezwell/michelson-sdk/literal'; + +const Tezos = new TezosToolkit('https://ithacanet.visualtez.com'); + +Tezos.setProvider({ + signer: new InMemorySigner('edskS83aZUK3ijLrW5tTs1sDY3qLjSsMGyebKKLWP4RXSBh4LCivG2s1TezyZB5rEvvdqepXMg1MLcfBhS8VSJESN7L27hDpsX') +}); + +const parameters = Record({ + requests: List( + [ + Record({ + owner: Address("KT1JehYdejjvFf1BqdXzTPt1QWqqSd3xS4JF"), + token_id: Nat(0) + }), + Record({ + owner: Address("tz1gTnKMA65qaKVpp6x4cgMLU2UyKF2zjHYN"), + token_id: Nat(0) + }) + ] + ), + callback: Contract("KT1SiSomCunxkq3g7vQKYpPpWBHodhH5pJkU", "receive_balances") +}).toJSON(); + +Tezos.contract.transfer({ + to: "KT1JehYdejjvFf1BqdXzTPt1QWqqSd3xS4JF", + amount: 0, + parameter: { + entrypoint: "balance_of", + value: parameters + }, +}) +.then((op) => { + console.log(`Waiting for ${op.hash} to be confirmed...`); + return op.confirmation(1).then(() => op.hash); +}) +.then((hash) => console.log("Operation injected: ", hash)) +.catch((error) => console.log(`Error: ${error} ${JSON.stringify(error, null, 2)}`)); +``` + +### update_operators + +```ts +import { TezosToolkit } from '@taquito/taquito'; +import { InMemorySigner } from '@taquito/signer'; +import { Record, Address, List, Nat, Variant } from '@tezwell/michelson-sdk/literal'; +import { TRecord, TAddress, TNat, TVariant } from '@tezwell/michelson-sdk/type'; + +const Tezos = new TezosToolkit('https://ithacanet.visualtez.com'); + +Tezos.setProvider({ + signer: new InMemorySigner('edskS83aZUK3ijLrW5tTs1sDY3qLjSsMGyebKKLWP4RXSBh4LCivG2s1TezyZB5rEvvdqepXMg1MLcfBhS8VSJESN7L27hDpsX') +}); + +const VariantType = TVariant({ + add_operator: TRecord({ + owner: TAddress(), + operator: TAddress(), + token_id: TNat(), + }), + remove_operator: TRecord({ + owner: TAddress(), + operator: TAddress(), + token_id: TNat(), + }) +}); +const parameters = List( + [ + Variant( + "add_operator", + Record({ + owner: Address("tz1gTnKMA65qaKVpp6x4cgMLU2UyKF2zjHYN"), + operator: Address("KT1JehYdejjvFf1BqdXzTPt1QWqqSd3xS4JF"), + token_id: Nat(0), + }), + VariantType + ), + Variant( + "remove_operator", + Record({ + owner: Address("tz1gTnKMA65qaKVpp6x4cgMLU2UyKF2zjHYN"), + operator: Address("KT1JehYdejjvFf1BqdXzTPt1QWqqSd3xS4JF"), + token_id: Nat(0), + }), + VariantType + ) + ] +).toJSON(); + +Tezos.contract.transfer({ + to: "KT1JehYdejjvFf1BqdXzTPt1QWqqSd3xS4JF", + amount: 0, + parameter: { + entrypoint: "update_operators", + value: parameters }, }) .then((op) => { console.log(`Waiting for ${op.hash} to be confirmed...`); return op.confirmation(1).then(() => op.hash); }) -.then((hash) => console.log(`Operation injected: https://hangzhou.tzstats.com/${hash}`)) +.then((hash) => console.log("Operation injected: ", hash)) .catch((error) => console.log(`Error: ${error} ${JSON.stringify(error, null, 2)}`)); ``` diff --git a/documentation/docs/types.md b/documentation/docs/types.md index acb0391..8358a97 100644 --- a/documentation/docs/types.md +++ b/documentation/docs/types.md @@ -18,6 +18,7 @@ console.log(nat_type.toMicheline()); // nat // JSON console.log(nat_type.toJSON()); // { prim: 'nat' } ``` +- [Value Example](./values#nat) ### int @@ -33,6 +34,7 @@ console.log(int_type.toMicheline()); // int // JSON console.log(int_type.toJSON()); // { prim: 'int' } ``` +- [Value Example](./values#int) ### mutez @@ -48,6 +50,7 @@ console.log(mutez_type.toMicheline()); // mutez // JSON console.log(mutez_type.toJSON()); // { prim: 'mutez' } ``` +- [Value Example](./values#mutez) ### string @@ -63,6 +66,7 @@ console.log(string_type.toMicheline()); // string // JSON console.log(string_type.toJSON()); // { prim: 'string' } ``` +- [Value Example](./values#string) ### bool @@ -78,6 +82,7 @@ console.log(bool_type.toMicheline()); // bool // JSON console.log(bool_type.toJSON()); // { prim: 'bool' } ``` +- [Value Example](./values#bool) ### bytes @@ -93,6 +98,7 @@ console.log(bytes_type.toMicheline()); // bytes // JSON console.log(bytes_type.toJSON()); // { prim: 'bytes' } ``` +- [Value Example](./values#bytes) ### address @@ -121,6 +127,7 @@ console.log(address_type.toMicheline()); // address // JSON console.log(address_type.toJSON()); // { prim: 'address' } ``` +- [Value Example](./values#address) ### timestamp @@ -136,6 +143,7 @@ console.log(timestamp_type.toMicheline()); // timestamp // JSON console.log(timestamp_type.toJSON()); // { prim: 'timestamp' } ``` +- [Value Example](./values#timestamp) ### chain_id @@ -151,6 +159,7 @@ console.log(chain_id_type.toMicheline()); // chain_id // JSON console.log(chain_id_type.toJSON()); // { prim: 'chain_id' } ``` +- [Value Example](./values#chain_id) ### bls12_381_fr @@ -166,6 +175,7 @@ console.log(bls12_381_fr_type.toMicheline()); // bls12_381_fr // JSON console.log(bls12_381_fr_type.toJSON()); // { prim: 'bls12_381_fr' } ``` +- [Value Example](./values#bls12_381_fr) ### bls12_381_g1 @@ -181,6 +191,7 @@ console.log(bls12_381_g1_type.toMicheline()); // bls12_381_g1 // JSON console.log(bls12_381_g1_type.toJSON()); // { prim: 'bls12_381_g1' } ``` +- [Value Example](./values#bls12_381_g1) ### bls12_381_g2 @@ -196,6 +207,7 @@ console.log(bls12_381_g2_type.toMicheline()); // bls12_381_g2 // JSON console.log(bls12_381_g2_type.toJSON()); // { prim: 'bls12_381_g2' } ``` +- [Value Example](./values#bls12_381_g2) ### key @@ -211,6 +223,7 @@ console.log(key_type.toMicheline()); // key // JSON console.log(key_type.toJSON()); // { prim: 'key' } ``` +- [Value Example](./values#key) ### key_hash @@ -226,6 +239,7 @@ console.log(key_hash_type.toMicheline()); // key_hash // JSON console.log(key_hash_type.toJSON()); // { prim: 'key_hash' } ``` +- [Value Example](./values#key_hash) ### signature @@ -241,6 +255,7 @@ console.log(signature_type.toMicheline()); // signature // JSON console.log(signature_type.toJSON()); // { prim: 'signature' } ``` +- [Value Example](./values#signature) ### unit @@ -256,6 +271,7 @@ console.log(unit_type.toMicheline()); // unit // JSON console.log(unit_type.toJSON()); // { prim: 'unit' } ``` +- [Value Example](./values#unit) ### operation @@ -303,6 +319,7 @@ console.log(list_type.toMicheline()); // (list nat) // JSON console.log(list_type.toJSON()); // { prim: 'list', args: [ { prim: 'nat' } ] } ``` +- [Value Example](./values#list) ### set @@ -318,6 +335,7 @@ console.log(set_type.toMicheline()); // (set nat) // JSON console.log(set_type.toJSON()); // { prim: 'set', args: [ { prim: 'nat' } ] } ``` +- [Value Example](./values#set) ### option @@ -333,6 +351,8 @@ console.log(option_type.toMicheline()); // (option nat) // JSON console.log(option_type.toJSON()); // { prim: 'option', args: [ { prim: 'nat' } ] } ``` +- [Value Example (Some)](./values#some) +- [Value Example (None)](./values#none) ### pair @@ -348,6 +368,7 @@ console.log(pair_type.toMicheline()); // (pair string nat) // JSON console.log(pair_type.toJSON()); // { prim: 'pair', args: [ { prim: 'string' }, { prim: 'nat' } ] } ``` +- [Value Example](./values#pair) ### or @@ -363,6 +384,8 @@ console.log(or_type.toMicheline()); // (or string nat) // JSON console.log(or_type.toJSON()); // { prim: 'or', args: [ { prim: 'string' }, { prim: 'nat' } ] } ``` +- [Value Example (Left)](./values#left) +- [Value Example (Right)](./values#right) ### map @@ -376,6 +399,7 @@ console.log(map_type.toMicheline()); // (map string nat) // JSON console.log(map_type.toJSON()); // { prim: 'map', args: [ { prim: 'string' }, { prim: 'nat' } ] } ``` +[Value Example](./values#map) ### big_map @@ -391,6 +415,7 @@ console.log(big_map_type.toMicheline()); // (big_map string nat) // JSON console.log(big_map_type.toJSON()); // { prim: 'big_map', args: [ { prim: 'string' }, { prim: 'nat' } ] } ``` +[Value Example](./values#big_map) ### lambda @@ -406,6 +431,7 @@ console.log(lambda_type.toMicheline()); // (lambda string nat) // JSON console.log(lambda_type.toJSON()); // { prim: 'lambda', args: [ { prim: 'string' }, { prim: 'nat' } ] } ``` +[Value Example](./values#lambda) ### ticket @@ -436,6 +462,7 @@ console.log(contract_type.toMicheline()); // (contract string) // JSON console.log(contract_type.toJSON()); // { prim: 'contract', args: [ { prim: 'string' } ] } ``` +[Value Example](./values#contract) ### sapling_state @@ -512,6 +539,7 @@ console.log(record_type.toJSON()); // { // ] // } ``` +[Value Example](./values#record) ### variant @@ -556,3 +584,4 @@ console.log(variant_type.toJSON()); // { // ] // } ``` +[Value Example](./values#variant) diff --git a/documentation/docs/values.md b/documentation/docs/values.md index 5809e34..081aa09 100644 --- a/documentation/docs/values.md +++ b/documentation/docs/values.md @@ -4,7 +4,9 @@ Official [Michelson reference](https://tezos.gitlab.io/michelson-reference) ## Singletons -### nat +### Nat + +- [Type reference](./types#nat) ```ts import { Nat } from '@tezwell/michelson-sdk'; @@ -17,12 +19,14 @@ console.log(nat_value.toMicheline()); // 1 console.log(nat_value.toJSON()); // { int: '1' } ``` -### int +### Int + +- [Type reference](./types#int) ```ts import { Int } from '@tezwell/michelson-sdk'; -const int_value = Nat(1); +const int_value = Int(1); // Micheline console.log(int_value.toMicheline()); // 1 @@ -30,9 +34,271 @@ console.log(int_value.toMicheline()); // 1 console.log(int_value.toJSON()); // { int: '1' } ``` -## Containers +### Mutez + +- [Type reference](./types#mutez) + +```ts +import { Mutez } from '@tezwell/michelson-sdk'; + +const mutez_value = Mutez(1); + +// Micheline +console.log(mutez_value.toMicheline()); // 1 +// JSON +console.log(mutez_value.toJSON()); // { int: '1' } +``` + +### String + +- [Type reference](./types#string) + +```ts +import { String } from '@tezwell/michelson-sdk'; + +const string_value = String("A String"); + +// Micheline +console.log(string_value.toMicheline()); // "A String" +// JSON +console.log(string_value.toJSON()); // { string: 'A String' } +``` + +### Bool + +- [Type reference](./types#bool) + +```ts +import { Bool } from '@tezwell/michelson-sdk'; + +const bool_value = Bool(true); + +// Micheline +console.log(bool_value.toMicheline()); // True +// JSON +console.log(bool_value.toJSON()); // { prim: 'True' } +``` + +### Bytes -### list +- [Type reference](./types#bytes) + +```ts +import { Bytes } from '@tezwell/michelson-sdk'; + +const bytes_value = Bytes("0xfffF"); + +// Micheline +console.log(bytes_value.toMicheline()); // 0xffff +// JSON +console.log(bytes_value.toJSON()); // { bytes: 'ffff' } +``` + +### Address + +- [Type reference](./types#address) + +```ts +import { Address } from '@tezwell/michelson-sdk'; + +const address_value = Address("tz1gTnKMA65qaKVpp6x4cgMLU2UyKF2zjHYN"); + +// Micheline +console.log(address_value.toMicheline()); // "tz1gTnKMA65qaKVpp6x4cgMLU2UyKF2zjHYN" +// JSON +console.log(address_value.toJSON()); // { string: 'tz1gTnKMA65qaKVpp6x4cgMLU2UyKF2zjHYN' } +``` + +### Contract + +- [Type reference](./types#contract) + +```ts +import { Contract } from '@tezwell/michelson-sdk'; + +const contract_value = Contract("tz1gTnKMA65qaKVpp6x4cgMLU2UyKF2zjHYN"); + +// Micheline +console.log(contract_value.toMicheline()); // "KT1SiSomCunxkq3g7vQKYpPpWBHodhH5pJkU%entrypoint" +// JSON +console.log(contract_value.toJSON()); // { string: 'KT1SiSomCunxkq3g7vQKYpPpWBHodhH5pJkU%entrypoint' } +``` + +### Timestamp + +- [Type reference](./types#timestamp) + +```ts +import { Timestamp } from '@tezwell/michelson-sdk'; + +const timestamp_number = Timestamp(1571659294); +const timestamp_string = Timestamp("2019-09-26T10:59:51Z"); + +// Micheline +console.log(timestamp_number.toMicheline()); // 1571659294 +console.log(timestamp_string.toMicheline()); // "2019-09-26T10:59:51Z" +// JSON +console.log(timestamp_number.toJSON()); // { int: '1571659294' } +console.log(timestamp_string.toJSON()); // { string: '2019-09-26T10:59:51Z' } +``` + +### Chain_id + +- [Type reference](./types#chain_id) + +```ts +import { Chain_id } from '@tezwell/michelson-sdk'; + +const chain_id_bytes = Chain_id("0x7a06a770"); +const chain_id_string = Chain_id("NetXynUjJNZm7wi"); + +// Micheline +console.log(chain_id_bytes.toMicheline()); // 0x7a06a770 +console.log(chain_id_string.toMicheline()); // "NetXynUjJNZm7wi" +// JSON +console.log(chain_id_bytes.toJSON()); // { bytes: '7a06a770' } +console.log(chain_id_string.toJSON()); // { string: 'NetXynUjJNZm7wi' } +``` + +### Bls12_381_fr + +- [Type reference](./types#bls12_381_fr) + +```ts +import { Bls12_381_fr } from '@tezwell/michelson-sdk'; + +const bls12_381_fr_number = Bls12_381_fr(1); +const bls12_381_fr_bytes = Bls12_381_fr("0x0001"); + +// Micheline +console.log(bls12_381_fr_number.toMicheline()); // 1 +console.log(bls12_381_fr_bytes.toMicheline()); // 0x0001 +// JSON +console.log(bls12_381_fr_number.toJSON()); // { int: '1' } +console.log(bls12_381_fr_bytes.toJSON()); // { bytes: '0001' } +``` + +### Bls12_381_g1 + +- [Type reference](./types#bls12_381_g1) + +```ts +import { Bls12_381_g1 } from '@tezwell/michelson-sdk'; + +const bls12_381_g1_value = Bls12_381_g1("0x0572cbea904d67468808c8eb50a9450c9721db309128012543902d0ac358a62ae28f75bb8f1c7c42c39a8c5529bf0f4e166a9d8cabc673a322fda673779d8e3822ba3ecb8670e461f73bb9021d5fd76a4c56d9d4cd16bd1bba86881979749d28"); + +// Micheline +console.log(bls12_381_g1_value.toMicheline()); // 0x0572cbea904d67468808c8eb50a9450c9721db309128012543902d0ac358a62ae28f75bb8f1c7c42c39a8c5529bf0f4e166a9d8cabc673a322fda673779d8e3822ba3ecb8670e461f73bb9021d5fd76a4c56d9d4cd16bd1bba86881979749d28 +// JSON +console.log(bls12_381_g1_value.toJSON()); // { bytes: '0572cbea904d67468808c8eb50a9450c9721db309128012543902d0ac358a62ae28f75bb8f1c7c42c39a8c5529bf0f4e166a9d8cabc673a322fda673779d8e3822ba3ecb8670e461f73bb9021d5fd76a4c56d9d4cd16bd1bba86881979749d28' } +``` + +### Bls12_381_g2 + +- [Type reference](./types#bls12_381_g2) + +```ts +import { Bls12_381_g2 } from '@tezwell/michelson-sdk'; + +const bls12_381_g2_value = Bls12_381_g2("0x13e02b6052719f607dacd3a088274f65596bd0d09920b61ab5da61bbdc7f5049334cf11213945d57e5ac7d055d042b7e024aa2b2f08f0a91260805272dc51051c6e47ad4fa403b02b4510b647ae3d1770bac0326a805bbefd48056c8c121bdb813fa4d4a0ad8b1ce186ed5061789213d993923066dddaf1040bc3ff59f825c78df74f2d75467e25e0f55f8a00fa030ed0d1b3cc2c7027888be51d9ef691d77bcb679afda66c73f17f9ee3837a55024f78c71363275a75d75d86bab79f74782aa"); + +// Micheline +console.log(bls12_381_g2_value.toMicheline()); // 0x13e02b6052719f607dacd3a088274f65596bd0d09920b61ab5da61bbdc7f5049334cf11213945d57e5ac7d055d042b7e024aa2b2f08f0a91260805272dc51051c6e47ad4fa403b02b4510b647ae3d1770bac0326a805bbefd48056c8c121bdb813fa4d4a0ad8b1ce186ed5061789213d993923066dddaf1040bc3ff59f825c78df74f2d75467e25e0f55f8a00fa030ed0d1b3cc2c7027888be51d9ef691d77bcb679afda66c73f17f9ee3837a55024f78c71363275a75d75d86bab79f74782aa +// JSON +console.log(bls12_381_g2_value.toJSON()); // { bytes: '13e02b6052719f607dacd3a088274f65596bd0d09920b61ab5da61bbdc7f5049334cf11213945d57e5ac7d055d042b7e024aa2b2f08f0a91260805272dc51051c6e47ad4fa403b02b4510b647ae3d1770bac0326a805bbefd48056c8c121bdb813fa4d4a0ad8b1ce186ed5061789213d993923066dddaf1040bc3ff59f825c78df74f2d75467e25e0f55f8a00fa030ed0d1b3cc2c7027888be51d9ef691d77bcb679afda66c73f17f9ee3837a55024f78c71363275a75d75d86bab79f74782aa' } +``` + +### Key + +- [Type reference](./types#key) + +```ts +import { Key } from '@tezwell/michelson-sdk'; + +const key_value = Key("edpku3g7CeTEvSKhxipD4Q2B6EiEP8cR323u8PFmGFgKRVRvCneEmT"); + +// Micheline +console.log(key_value.toMicheline()); // "edpku3g7CeTEvSKhxipD4Q2B6EiEP8cR323u8PFmGFgKRVRvCneEmT" +// JSON +console.log(key_value.toJSON()); // { string: 'edpku3g7CeTEvSKhxipD4Q2B6EiEP8cR323u8PFmGFgKRVRvCneEmT' } +``` + +### Key_hash + +- [Type reference](./types#key) + +```ts +import { Key_hash } from '@tezwell/michelson-sdk'; + +const key_hash_value = Key_hash("tz1gTnKMA65qaKVpp6x4cgMLU2UyKF2zjHYN"); + +// Micheline +console.log(key_hash_value.toMicheline()); // "tz1gTnKMA65qaKVpp6x4cgMLU2UyKF2zjHYN" +// JSON +console.log(key_hash_value.toJSON()); // { string: 'tz1gTnKMA65qaKVpp6x4cgMLU2UyKF2zjHYN' } +``` + +### Signature + +- [Type reference](./types#signature) + +```ts +import { Signature } from '@tezwell/michelson-sdk'; + +const signature_value = Signature("sigsAujsNePapNNGsVotTvcKWMNNJja9B4a2FfAe8vExzFhEgEo1GTQStiif22uSA6iNxPGCGsXsRyeLHzeLbJL2y8CnYuNe"); + +// Micheline +console.log(signature_value.toMicheline()); // "sigsAujsNePapNNGsVotTvcKWMNNJja9B4a2FfAe8vExzFhEgEo1GTQStiif22uSA6iNxPGCGsXsRyeLHzeLbJL2y8CnYuNe" +// JSON +console.log(signature_value.toJSON()); // { string: 'sigsAujsNePapNNGsVotTvcKWMNNJja9B4a2FfAe8vExzFhEgEo1GTQStiif22uSA6iNxPGCGsXsRyeLHzeLbJL2y8CnYuNe' } +``` + +### Unit + +- [Type reference](./types#unit) + +```ts +import { Unit } from '@tezwell/michelson-sdk'; + +// Micheline +console.log(Unit().toMicheline()); // Unit +// JSON +console.log(Unit().toJSON()); // { prim: 'Unit' } +``` + +### Left + +- [Type reference](./types#or) + +```ts +import { Left, Nat } from '@tezwell/michelson-sdk'; + +const or_value = Left(Nat(1); + +// Micheline +console.log(or_value.toMicheline()); // Left 1 +// JSON +console.log(or_value.toJSON()); // { prim: 'Left', args: [{ int: '1' }] } +``` + +### Right + +- [Type reference](./types#or) + +```ts +import { Right, Nat } from '@tezwell/michelson-sdk'; + +const or_value = Right(Nat(1); + +// Micheline +console.log(or_value.toMicheline()); // Right 1 +// JSON +console.log(or_value.toJSON()); // { prim: 'Right', args: [{ int: '1' }] } +``` + +### List + +- [Type reference](./types#list) ```ts import { List, Nat } from '@tezwell/michelson-sdk'; @@ -45,7 +311,9 @@ console.log(list_value.toMicheline()); // { 1 ; 2 } console.log(list_value.toJSON()); // [ { int: '1' }, { int: '2' } ] ``` -### set +### Set + +- [Type reference](./types#set) ```ts import { Set, Nat } from '@tezwell/michelson-sdk'; @@ -57,3 +325,265 @@ console.log(set_value.toMicheline()); // { 1 ; 2 } // JSON console.log(set_value.toJSON()); // [ { int: '1' }, { int: '2' } ] ``` + +### Some + +- [Type reference](./types#option) + +```ts +import { Some, Nat } from '@tezwell/michelson-sdk'; + +const some_value = Some(Nat(1)); + +// Micheline +console.log(some_value.toMicheline()); // Some 1 +// JSON +console.log(some_value.toJSON()); // { prim: 'Some', args: [{ int: '1' }] } +``` + +### None + +- [Type reference](./types#option) + +```ts +import { None } from '@tezwell/michelson-sdk'; + +const none_value = None(); + +// Micheline +console.log(none_value.toMicheline()); // None +// JSON +console.log(none_value.toJSON()); // { prim: 'None' } +``` + +### Pair + +- [Type reference](./types#pair) + +```ts +import { Pair, Nat, String } from '@tezwell/michelson-sdk'; + +const pair_value = Pair(Nat(1), String("A String")); + +// Micheline +console.log(pair_value.toMicheline()); // (Pair 1 "A String") +// JSON +console.log(pair_value.toJSON()); // { prim: 'Pair', args: [{ int: '1' }, { string: 'A String' }] } +``` + +### Map + +- [Type reference](./types#map) + +```ts +import { Map, Nat, String } from '@tezwell/michelson-sdk'; + +const map_value = Map( + [ + [Nat(1), String("A String 1")], + [Nat(2), String("A String 2")], + ] +); + +// Micheline +console.log(map_value.toMicheline()); // { Elt 1 "A String 1" ; Elt 2 "A String 2" } +// JSON +console.log(map_value.toJSON()); // [ + // { + // prim: 'Elt', + // args: [ + // { + // int: '1', + // }, + // { + // string: 'A String 1', + // } + // ] + // }, + // { + // prim: 'Elt', + // args: [ + // { + // int: '2', + // }, + // { + // string: 'A String 2', + // } + // ] + // } + // ] +``` + +### Big_map + +- [Type reference](./types#big_map) + +```ts +import { Big_map, Nat, String } from '@tezwell/michelson-sdk'; + +const big_map_value = Big_map( + [ + [Nat(1), String("A String 1")], + [Nat(2), String("A String 2")], + ] +); + +// Micheline +console.log(big_map_value.toMicheline()); // { Elt 1 "A String 1" ; Elt 2 "A String 2" } +// JSON +console.log(big_map_value.toJSON()); // [ + // { + // prim: 'Elt', + // args: [ + // { + // int: '1', + // }, + // { + // string: 'A String 1', + // } + // ] + // }, + // { + // prim: 'Elt', + // args: [ + // { + // int: '2', + // }, + // { + // string: 'A String 2', + // } + // ] + // } + // ] +``` +### Lambda + +- [Type reference](./types#lambda) + +```ts +import { Lambda } from '@tezwell/michelson-sdk'; + +const lambda_value = Lambda([ + { + prim: 'IF', + args: [ + [{ prim: 'PUSH', args: [{ prim: 'string' }, { prim: 'YES' }] }], + [{ prim: 'PUSH', args: [{ prim: 'string' }, { prim: 'NO' }] }], + ], + }, +]); + +// Micheline +console.log(lambda_value.toMicheline()); // IF + // { + // PUSH string "YES"; + // } + // { + // PUSH string "NO"; + // } +// JSON +console.log(lambda_value.toJSON()); // [ + // { + // args: [ + // [ + // { + // args: [ + // { + // prim: 'string', + // }, + // { + // string: 'YES', + // }, + // ], + // prim: 'PUSH', + // }, + // ], + // [ + // { + // args: [ + // { + // prim: 'string', + // }, + // { + // string: 'NO', + // }, + // ], + // prim: 'PUSH', + // }, + // ], + // ], + // prim: 'IF', + // }, + // ] +``` + +### Record + +- [Type reference](./types#record) + +```ts +import { Record, Nat, String, Bytes } from '@tezwell/michelson-sdk'; + +const record_value = Record( + { + field1: Nat(1), + field2: String("A String"), + field3: Bytes("0x01"), + }, + [['field1', 'field2'], 'field3'], +); + +// Micheline +console.log(record_value.toMicheline()); // (Pair (Pair 1 "A String") 0x01) +// JSON +console.log(record_value.toJSON()); // { + // prim: 'Pair', + // args: [ + // { + // prim: 'Pair', + // args: [ + // { int: '1' }, + // { string: 'A String' } + // ] + // }, + // { bytes: '01' } + // ] + // } +``` + +### Variant + +- [Type reference](./types#variant) + +```ts +import { Variant, Nat, TNat, TUnit } from '@tezwell/michelson-sdk'; + +const variant_value = Variant( + "add", + Nat(1), + TVariant({ + add: TNat(), + remove: TNat(), + remove_all: TUnit(), + }), + ['add', ['remove', 'remove_all']], +); + +// Micheline +console.log(variant_value.toMicheline()); // Left 1 +// JSON +console.log(variant_value.toJSON()); // { + // prim: 'Left', + // args: [ + // { int: '1' } + // ] + // } +``` + + diff --git a/documentation/sidebars.js b/documentation/sidebars.js index c3db97f..bee4b27 100644 --- a/documentation/sidebars.js +++ b/documentation/sidebars.js @@ -28,10 +28,18 @@ const sidebars = { type: 'doc', id: 'values', }, + { + type: 'doc', + id: 'FA2', + }, { type: 'doc', id: 'taquito', }, + { + type: 'doc', + id: 'conseiljs', + }, ], }; diff --git a/tests/e2e/__snapshots__/all.test.ts.snap b/tests/e2e/__snapshots__/all.test.ts.snap index 292eeeb..8f36181 100644 --- a/tests/e2e/__snapshots__/all.test.ts.snap +++ b/tests/e2e/__snapshots__/all.test.ts.snap @@ -159,7 +159,7 @@ parameter unit; code { PUSH (lambda nat (lambda nat bool)) { DROP; - LAMBDA nat bool + LAMBDA nat bool { DROP; PUSH bool True; @@ -277,10 +277,10 @@ Array [ parameter unit; code { PUSH (lambda bool unit) { - IF + IF { PUSH unit Unit; - } + } { PUSH unit Unit; }; diff --git a/tests/e2e/validate_michelson.ts b/tests/e2e/validate_michelson.ts index 7d8f8ec..bccb929 100644 --- a/tests/e2e/validate_michelson.ts +++ b/tests/e2e/validate_michelson.ts @@ -28,7 +28,6 @@ import { Left, Right, Lambda, - Contract, } from '../../src/core/literal'; import { TAddress, @@ -39,7 +38,6 @@ import { TBool, TBytes, TChain_id, - TContract, TInt, TKey, TKey_hash,