diff --git a/packages/taquito-michelson-encoder/README.md b/packages/taquito-michelson-encoder/README.md index 9285d20af2..286ab1f2fc 100644 --- a/packages/taquito-michelson-encoder/README.md +++ b/packages/taquito-michelson-encoder/README.md @@ -1,66 +1,137 @@ # Taquito Michelson Encoder package +*Documentation can be found [here](https://tezostaquito.io/docs/michelson_encoder)* +*TypeDoc style documentation is available on-line [here](https://tezostaquito.io/typedoc/modules/_taquito_michelson_encoder.html)* -`@taquito/michelson-encoder` provides a JavaScript abstraction based on a Tezos Smart contracts code, parameters and storage. +`@taquito/michelson-encoder` provides a JavaScript abstraction based on a Tezos Smart contracts code, parameters, storage, and views. -See the top-level project [https://github.com/ecadlabs/taquito](https://github.com/ecadlabs/taquito) for details on reporting issues, contributing and versioning. +## General Information + +The Michelson-Encoder package aims to create an abstraction over the Michelson Language. It allows converting Michelson data into javascript-looking objects which are easier to use and reason about. + +Its integration into the main Taquito package makes it easier to write the storage when deploying a contract and the parameter when calling a contract entry-point or executing a view. It also provides an abstraction on the storage read value of the contract. + +The `Schema` class is intended to represent the contract storage, while the `ParameterSchema` represents its entry points. The `Execute` method takes a parameter in Michelson format and converts it into the JavaScript abstraction. The `Encode` method does the opposite; it takes a JavaScript object as a parameter and converts it into Michelson data. + +## Install +``` +npm i --save @taquito/michelson-encoder +``` + +## Usage ## Example -Given the following michelson smart contract data, retrieved from a Tezos Nodes RPC: +The constructor of the `Schema` class takes a Michelson type as a parameter which is retrieved from a Tezos Nodes RPC: -```json -{ - "storage": { - "prim": "Pair", - "args": [ - [], - { - "prim": "Pair", - "args": [ - { "int": "1" }, - { - "prim": "Pair", - "args": [ - { "int": "1000" }, - { - "prim": "Pair", - "args": [ - { "string": "Token B" }, - { - "prim": "Pair", - "args": [ - { "string": "B" }, - { "string": "tz1ccqAEwfPgeoipnXtjAv1iucrpQv3DFmmS" } - ] - } - ] - } +```ts +const storageType = { + prim: 'pair', + args: [ + { prim: 'nat', annots: [ '%stored_counter' ] }, + { + prim: 'pair', + args: [ + { prim: 'nat', annots: [ '%threshold' ] }, + { prim: 'list', args: [ { prim: 'key' } ], annots: [ '%keys' ] } ] - } - ] - } + } ] - } -} +}; +const storageSchema = new Schema(storageType); ``` -`@taquito/michelson-encoder` will generate an abstraction in the form of a plain old javascript object: +The `Execute` method takes a Michelson value as a parameter and generates an abstraction in the form of a plain old javascript object: + +```ts +// dataMichelson is the storage of a contract retrieved from the RPC +const dataMichelson = { + "prim": "Pair", + "args": [ + { + "int": "10" + }, + { + "prim": "Pair", + "args": [ + { + "int": "5" + }, + [ + { + "string": "edpkvS5QFv7KRGfa3b87gg9DBpxSm3NpSwnjhUjNBQrRUUR66F7C9g" + }, + { + "string": "edpkuLxx9PQD8fZ45eUzrK3BhfDZJHhBuK4Zi49DcEGANwd2rpX82t" + } + ] + ] + } + ] +}; + +const data = storageSchema.Execute(dataMichelson); +console.log(data); -```javascript +/* output: { - accounts: {}, - version: '1', - totalSupply: '1000', - name: 'Token B', - symbol: 'B', - owner: 'tz1ccqAEwfPgeoipnXtjAv1iucrpQv3DFmmS' -} + "stored_counter": "10", + "threshold": "5", + "keys": [ + "edpkvS5QFv7KRGfa3b87gg9DBpxSm3NpSwnjhUjNBQrRUUR66F7C9g", + "edpkuLxx9PQD8fZ45eUzrK3BhfDZJHhBuK4Zi49DcEGANwd2rpX82t" + ] +} +*/ ``` -## API Documentation +Note that the Michelson type annotations represent the javascript object's keys. + + +The `Encode` method takes a javascript object as a parameter and converts it into Michelson: + +```ts +const data = storageSchema.Encode({ + "stored_counter": "10", + "threshold": "5", + "keys": [ + "edpkvS5QFv7KRGfa3b87gg9DBpxSm3NpSwnjhUjNBQrRUUR66F7C9g", + "edpkuLxx9PQD8fZ45eUzrK3BhfDZJHhBuK4Zi49DcEGANwd2rpX82t" + ] +}); + +console.log(data); + +/* output: +{ + "prim": "Pair", + "args": [ + { + "int": "10" + }, + { + "prim": "Pair", + "args": [ + { + "int": "5" + }, + [ + { + "string": "edpkvS5QFv7KRGfa3b87gg9DBpxSm3NpSwnjhUjNBQrRUUR66F7C9g" + }, + { + "string": "edpkuLxx9PQD8fZ45eUzrK3BhfDZJHhBuK4Zi49DcEGANwd2rpX82t" + } + ] + ] + } + ] +} +*/ +``` +## Additional info -TypeDoc style documentation is available on-line [here](https://tezostaquito.io/typedoc/modules/_taquito_michelson_encoder.html) +See the top-level [https://github.com/ecadlabs/taquito](https://github.com/ecadlabs/taquito) file for details on reporting issues, contributing and versioning. ## Disclaimer diff --git a/packages/taquito-remote-signer/README.md b/packages/taquito-remote-signer/README.md index e228559777..6f24142b9c 100644 --- a/packages/taquito-remote-signer/README.md +++ b/packages/taquito-remote-signer/README.md @@ -1,21 +1,40 @@ # Taquito Remote Signer package +*TypeDoc style documentation is available on-line [here](https://tezostaquito.io/typedoc/modules/_taquito_remote_signer.html)* -`@taquito/remote-signer` is an npm package that provides developers with remote signing functionality for Taquito. It can be injected as follows: +`@taquito/remote-signer` is an npm package that provides developers with remote signing functionality for Taquito. + +## General Information + +If you require the server-side signing of operations on the mainnet, we recommend exploring the use of the Remote Signer package in conjunction with an HSM remote signer such as [Signatory](https://signatory.io/) or [TacoInfra's Remote Signer](https://github.com/tacoinfra/remote-signer). + +## Install + +``` +npm i --save @taquito/taquito +npm i --save @taquito/remote-signer +``` + +## Usage + +When the `RemoteSigner` is configured on the `TezosToolkit`, Taquito features that require signing support can be used. The Contract API operations will be signed using the signer. Validation of the signature will be conducted before the operation is injected. The `RemoteSigner` can be injected into the `TezosToolkit` as follows: ```ts import { TezosToolkit } from '@taquito/taquito'; import { RemoteSigner } from '@taquito/remote-signer'; const Tezos = new TezosToolkit('https://YOUR_PREFERRED_RPC_URL'); -const signer = new RemoteSigner(pkh, rootUrl, { headers: requestHeaders }); +const signer = new RemoteSigner(pkh, rootUrl); Tezos.setSignerProvider(signer); + +// Taquito will send a request to the configured Remote Signer to sign the transfer operation: +await Tezos.contract.transfer({ to: publicKeyHash, amount: 2 }); ``` -See the top-level [https://github.com/ecadlabs/taquito](https://github.com/ecadlabs/taquito) file for details on reporting issues, contributing and versioning. +The constructor of the `RemoteSigner` class requires the public key hash and the URL of the remote signer as parameters. It also takes optional headers (i.e., Authorization) and an optional `HttpBackend` to override the default one if needed. -## API Documentation +## Additional info -TypeDoc style documentation is available on-line [here](https://tezostaquito.io/typedoc/modules/_taquito_remote_signer.html) +See the top-level [https://github.com/ecadlabs/taquito](https://github.com/ecadlabs/taquito) file for details on reporting issues, contributing, and versioning. ## Disclaimer diff --git a/packages/taquito/README.md b/packages/taquito/README.md index ccfe461045..e9872297af 100644 --- a/packages/taquito/README.md +++ b/packages/taquito/README.md @@ -1,9 +1,8 @@ +# Taquito high-level functions -[![pkgsign status](https://us-central1-pkgsign.cloudfunctions.net/pkgsign-badge?name=@taquito/taquito&expectedIdentity=%40jevonearth)](https://github.com/RedpointGames/pkgsign) +*TypeDoc style documentation is available on-line [here](https://tezostaquito.io/typedoc/modules/_taquito_taquito.html)* -# Taquito high level functions - -The `@taquito/taquito` package contains higher level functionality that builds upon the other packages in the Tezos Typescript Library Suite. +The `@taquito/taquito` package contains higher-level functionality that builds upon the other packages in the Tezos Typescript Library Suite. ## CDN Bundle @@ -12,9 +11,140 @@ The `@taquito/taquito` package contains higher level functionality that builds u crossorigin="anonymous" integrity="sha384-xxD6xXwrySOXsNY/7nuDQL14yoB/rz8DYUc3lPfDpaWrICSCUFXqpG1Mp44N9BA1"> ``` -## API Documentation +## General Information + +The `TezosToolkit` is a facade class that surfaces all of the library's capability and allows its configuration through different providers. + +## Install + +``` +npm i --save @taquito/taquito +``` + + +## Minimal configuration +### TezosToolkit instantiation + +The `TezosToolkit` constructor takes at least an RPC URL as a parameter. When instantiating the toolkit with a URL, a default instance of `RpcClient` is created. The `RpcClient` class is used to interact with the Tezos network. + +```ts +import { TezosToolkit } from '@taquito/taquito'; + +const Tezos = new TezosToolkit('https://YOUR_PREFERRED_RPC_URL'); +``` + +It is also possible to instantiate the `TezosToolkit` with a class that implements the `RpcClientInterface`. See the `RpcClientCache` from the `@taquito/rpc` package as an example that provides caching functionality. + +### Choosing between the contract or the wallet APIs + +In most cases, you want to use the Wallet API when you give the users of your dapp the freedom to choose the wallet of their choice to interact with. The Contract API is more suited for back-end applications and forging/signing offline (for example, using the inMemorySigner). You would also use the Contract API to build a wallet. + +**Configure a signer to use the Contract API** + +Sending operations using the Contract API requires a signer to be configured. Taquito provides different signer implementations (e.g. see the `taquito/remote-signer`, `taquito/signer` and `taquito/legder-signer`). Here is an example using the `InMemorySigner`: + +```js +import { InMemorySigner } from '@taquito/signer'; +import { TezosToolkit } from '@taquito/taquito'; + +const Tezos = new TezosToolkit('https://YOUR_PREFERRED_RPC_URL'); + +Tezos.setProvider({ signer: await InMemorySigner.fromSecretKey('edsk...') }); + +// Using the contract API, the follwing operation is signed using the configured signer: +await Tezos.contract.transfer({ to: publicKeyHash, amount: 2 }); +``` + +**Configure a wallet to use the Wallet API** + +Sending operations using the Wallet API requires a wallet to be configured. The wallet API supports different kinds of wallets. For example, the `BeaconWallet` from the `@taquito/beacon-wallet` can be used. Use the `setWalletProvider` method of the `TezosToolkit` to set the wallet and refer to the `@taquito/beacon-wallet` for specific configuration: + +```ts +import { TezosToolkit } from '@taquito/taquito'; +import { BeaconWallet } from '@taquito/beacon-wallet'; + +const Tezos = new TezosToolkit('https://YOUR_PREFERRED_RPC_URL'); +const wallet = new BeaconWallet(options); + +await wallet.requestPermissions(network); + +Tezos.setWalletProvider(wallet); + +// Using the wallet API, the configured wallet will prepare the transaction and broadcast it +await Tezos.wallet.transfer({ to: publicKeyHash, amount: 2 }).send(); +``` + +## TezosToolkit examples of additional configuration + +The `TezosToolkit` contains different default providers that are customizable to adapt to users' needs. + +### Forger + +Replace the default `RpcForger` with an instance of `LocalForger`: + +```ts +import { localForger } from '@taquito/local-forger' +Tezos.setForgerProvider(localForger); +``` + +### Packer + +To fetch values of the big map using the local implementation to pack data, replace the default `RpcPacker` with an instance of `MichelCodecPacker`: + +```ts +import { MichelCodecPacker } from '@taquito/taquito'; +// Fetch values of the big map using local implementation to pack data +Tezos.setPackerProvider(new MichelCodecPacker()); +``` + +### Poller configuration + +Polling interval for operation confirmation can be set globally for a taquito instance. + +```js +Tezos.setProvider( + { + config: { + confirmationPollingIntervalSecond: 5, + confirmationPollingTimeoutSecond: 180 + } + } +) +``` + +## Estimation + +Use the `estimate` member to estimate fees, gas and storage of operations. + +```ts +const estimate = await Tezos.estimate.transfer(transferParams); +``` + +## Stream + +Use the `stream` member to subscribe to specific operations: + +```ts +Tezos.setProvider({ + config: { shouldObservableSubscriptionRetry: true, streamerPollingIntervalMilliseconds: 15000 } +}); + +const bakerEndorsementFilter = { + and: [{ source: 'tz2TSvNTh2epDMhZHrw73nV9piBX7kLZ9K9m' }, { kind: 'endorsement' }] +} + +const bakerDelegation = { + and: [{ destination: 'tz2TSvNTh2epDMhZHrw73nV9piBX7kLZ9K9m' }, { kind: 'delegation' }] +} + +const sub = tezos.stream.subscribeOperation({ + or: [bakerEndorsementFilter, bakerDelegation] +}) + +sub.on('data', console.log) +``` -TypeDoc style documentation is available on-line [here](https://tezostaquito.io/typedoc/modules/_taquito_taquito.html) +## Additional info See the top-level [https://github.com/ecadlabs/taquito](https://github.com/ecadlabs/taquito) file for details on reporting issues, contributing and versioning.