Notes


  1. PublicKeyHash == address

RPC Endpoints


// a lot of this enpoint in @taquito, idk test or main
<https://ithacanet.ecadinfra.com>

// ???
const tezos = new TezosToolkit('<https://hangzhounet.api.tez.ie>');

// ???
const provider = '<https://ithacanet.ecadinfra.com/>'
const client = new RpcClient(provider);

What to consider when choosing a node


If you are aware of a public node missing from our list or our information is inaccurate, please help us by submitting an issue or pull request on our GitHub page.

Test all known nodes for availability


https://tezostaquito.io/docs/rpc_nodes_integration_test/


1. Create wallet


import { TezosToolkit } from '@taquito/taquito';
import { importKey } from '@taquito/signer';

const provider = '<https://ithacanet.ecadinfra.com/>'

async function example() {
  const tezos = new TezosToolkit(provider);
  await importKey(
    tezos,
    '[email protected]',
    'y4BX7qS1UE',
    [ 'skate', 'damp', ... ].join(' '),
    '7d4c8c3796fdbf4869edb5703758f0e5831f5081'
  );

Install


npm i --save @taquito/taquito
npm i --save @taquito/signer
npm i --save @taquito/rpc

Acc from private key


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...') });

Derivation path


44'/1729'/0'/0'

In Tezos, we generally see a slight difference in the path compared to the BIP44 specification. It is common to see path made of 4 indexes instead of 5 (default path being 44'/1729'/0'/0' instead of 44'/1729'/0'/0'/0'). For example, the default path used by tezos-client is 44'/1729'/0'/0'. Based on what is done by the Tezos-client, the default path used by Taquito in the LedgerSigner is also 44'/1729'/0'/0'. Taquito offers a template for the path called HDPathTemplate. This template uses four indexes and suggests doing the iteration on the account index.For example, you can use HDPathTemplate(0) (equivalent to 44'/1729'/0'/0') to access the first address, HDPathTemplate(1) equivalent to 44'/1729'/1'/0') to access the second address, HDPathTemplate(2) (equivalent to 44'/1729'/2'/0') to access the third address... In order to meet the needs of each user, this template is not imposed by Taquito.

We can see other implementations that use 44'/1729'/0'/0'/0', where the next address is accessed by incrementing account or address_index

Quick summary of different default paths used:

Paths

InMemorySigner


//INTERNAL METHODS OF CLASS:
static async fromSecretKey(key: string, passphrase?: string) {
    await sodium.ready;
    return new InMemorySigner(key, passphrase);
  }

async sign(bytes: string, watermark?: Uint8Array) {
async publicKey(): Promise<string> {
async publicKeyHash(): Promise<string> {
async secretKey(): Promise<string> {

Get address info


function getAddressInfo(transport, index) {
  const ledgerSigner = new LedgerSigner(
    transport,
    `44'/1729'/${index}'/0'`,
    true,
    DerivationType.ED25519
  );
  Tezos.setProvider({ signer: ledgerSigner });
  return Tezos.signer.publicKeyHash().then((pkh) => {
    Tezos.tz.getBalance(pkh).then((balance) => {
      Tezos.rpc.getManagerKey(pkh).then((getPublicKey) => {
        println(
          `The public key hash related to the derivation path having the index ${index} is ${pkh}.`
        );
        if (getPublicKey) {
          println(`The balance is ${balance.toNumber() / 1000000} ꜩ.\n`);
        } else {
          println('This account is not revealed.\n');
        }
      });
    });
  });
}

Account from mnemonic?

TransportNodeHid creates mnemonic?


import { LedgerSigner } from '@taquito/ledger-signer';
import TransportNodeHid from '@ledgerhq/hw-transport-node-hid';
import { TezosToolkit } from '@taquito/taquito';

const Tezos = new TezosToolkit('https://YOUR_PREFERRED_RPC_URL');

const transport = await TransportNodeHid.create();
const ledgerSigner = new LedgerSigner(transport);

Tezos.setProvider({ signer: ledgerSigner });

//Get the public key and the public key hash from the Ledger
const publicKey = await Tezos.signer.publicKey();
const publicKeyHash = await Tezos.signer.publicKeyHash();

Testnet


To load a faucet key (available from https://teztnets.xyz/) for working with a public testnet, use the importKey function.

import { TezosToolkit } from '@taquito/taquito';
import { importKey } from '@taquito/signer';

const Tezos = new TezosToolkit('https://YOUR_PREFERRED_TESTNET_RPC_URL');

// A key faucet, similar to what is available from <https://teztnets.xyz/>
const FAUCET_KEY = {
  mnemonic: [
    'cart',
    'will',
    'page',
    'bench',
    'notice',
    'leisure',
    'penalty',
    'medal',
    'define',
    'odor',
    'ride',
    'devote',
    'cannon',
    'setup',
    'rescue',
  ],
  secret: '35f266fbf0fca752da1342fdfc745a9c608e7b20',
  amount: '4219352756',
  pkh: 'tz1YBMFg1nLAPxBE6djnCPbMRH5PLXQWt8Mg',
  password: 'Fa26j580dQ',
  email: '[email protected]',
};

importKey(
  Tezos,
  FAUCET_KEY.email,
  FAUCET_KEY.password,
  FAUCET_KEY.mnemonic.join(' '),
  FAUCET_KEY.secret
);
// Your Tezos instance is now operably configured for signing with the faucet key.

Estimate fee?


Tezos.estimate
                .transfer({
                    to: 'tz1PgQt52JMirBUhhkq1eanX8hVd1Fsg71Lr',
                    amount: balance.toNumber() - DEFAULT_FEE.REVEAL, // Remove default reveal fee
                    mutez: true
                })

Get Balance


import { RpcClient } from '@taquito/rpc';

const client = new RpcClient('https://YOUR_PREFERRED_RPC_URL');

// Fetching the balance of an account
const balance = await client.getBalance('tz1VSUr8wwNhLAzempoch5d6hLRiTh8Cjcjb')

// ONE MORE
Tezos.tz.getBalance(address);

//one more 
await tezos.tz.getBalance('tz1NAozDvi5e7frVq9cUaC3uXQQannemB8Jw').then(balance => {
      console.log(`${balance.toNumber() / 1000000} ꜩ`)
    });

Transfer


Tezos.contract.transfer({
    to: 'tz1PgQt52JMirBUhhkq1eanX8hVd1Fsg71Lr',
    mutez: true,
    amount: maxAmount,
    fee: estimate.suggestedFeeMutez,
    gasLimit: estimate.gasLimit,
    storageLimit: 0
});

// ONE MORE TRANSFER
const amount = 0.5;
const address = 'tz1h3rQ8wBxFd8L9B3d7Jhaawu6Z568XU3xY';

console.log(`Transfering ${amount} ꜩ to ${address}...`);
Tezos.contract
  .transfer({ to: address, amount: amount })
  .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}`>))
  .catch((error) => console.log(`Error: ${error} ${JSON.stringify(error, null, 2)}`));

// WITH CONFIRMATION
const amount = 0.5;
const address = 'tz1h3rQ8wBxFd8L9B3d7Jhaawu6Z568XU3xY';

console.log(`Transfering ${amount} ꜩ to ${address}...`);
Tezos.wallet
  .transfer({ to: address, amount: amount })
  .send()
  .then((op) => {
    console.log(`Waiting for ${op.opHash} to be confirmed...`);
    return op.confirmation(1).then(() => op.opHash);
  })
  .then((hash) => console.log(`Operation injected: <https://hangzhou.tzstats.com/${hash}`>))
  .catch((error) => console.log(`Error: ${error} ${JSON.stringify(error, null, 2)}`));

Forging (Compile tx)


Forging is the act of encoding your operation shell into its binary representation. Forging can be done either remotely by the RPC node, or locally. @taquito/local-forging is an npm package that provides developers with local forging functionality.

Operations must be forged and signed before it gets injected to the blockchain.

// Example of an unforged operation:

{
  branch: 'BLzyjjHKEKMULtvkpSHxuZxx6ei6fpntH2BTkYZiLgs8zLVstvX',
    contents: [
        {
          kind: 'origination',
          counter: '1',
          source: 'tz1QZ6KY7d3BuZDT1d19dUxoQrtFPN2QJ3hn',
          fee: '10000',
          gas_limit: '10',
          storage_limit: '10',
          balance: '0',
          script: [Object]
        }
    ]
}

// A forged operation:
a99b946c97ada0f42c1bdeae0383db7893351232a832d00d0cd716eb6f66e5616d0035e993d8c7aaa42b5e3ccd86a33390ececc73abd904e010a0a000000000011020000000c0500036c0501036c0502038d00000002030b

// ...
import { TezosToolkit } from '@taquito/taquito'
import { LocalForger } from '@taquito/local-forging'

const Tezos = new TezosToolkit('https://YOUR_PREFERRED_RPC_URL');
Tezos.setProvider({ forger: localForger })

Activate – account?


import { TezosToolkit } from '@taquito/taquito'
import { InMemorySigner } from '@taquito/signer';

async function example() {
    const provider = '<https://ithacanet.ecadinfra.com/>'
    const signer: any = new InMemorySigner('edskRtmEwZxRzwd1obV9pJzAoLoxXFWTSHbgqpDBRHx1Ktzo5yVuJ37e2R4nzjLnNbxFU4UiBU1iHzAy52pK5YBRpaFwLbByca');
    const tezos = new TezosToolkit(provider);
    tezos.setSignerProvider( signer );
    try {
        const op = await tezos.tz.activate("tz1ZfrERcALBwmAqwonRXYVQBDT9BjNjBHJu", "161d907951bf5594bedb1d70bb03c938d63c22be")
        console.log('Awaiting confirmation...');
        await op.confirmation();
        console.log(op.hash, op.includedInBlock);
    } catch (ex) {
        console.log(ex)
    }
}

Await confirmation


const op = await tezos.contract.originate({
        code: tacoContractTzip16,
        storage: {
            metadata: metadataBigMAp,
            taco_shop_storage: tacoShopStorageMap
        },
    });
const contract = await op.confirmation();
const contractAddress = (await op.contract()).address;

Work with contracts


<aside> 💡 It seems that ABI loaded

</aside>

// const Tezos = new TezosToolkit('<https://hangzhounet.api.tez.ie>');

function transferImplicit(key, mutez) {
  return [
    { prim: 'DROP' },
    { prim: 'NIL', args: [{ prim: 'operation' }] },
    {
      prim: 'PUSH',
      args: [{ prim: 'key_hash' }, { string: key }],
    },
    { prim: 'IMPLICIT_ACCOUNT' },
    {
      prim: 'PUSH',
      args: [{ prim: 'mutez' }, { int: `${mutez}` }],
    },
    { prim: 'UNIT' },
    { prim: 'TRANSFER_TOKENS' },
    { prim: 'CONS' },
  ];
}

Tezos.signer
  .publicKeyHash()
  .then((address) => {
    Tezos.contract
      .originate({
        balance: '8',
        code: managerCode,
        init: { string: address },
      })
      .then((contractOrigination) => {
        println(
          `Waiting for confirmation of origination for ${contractOrigination.contractAddress}...`
        );
        return contractOrigination.contract();
      })
      .then((contract) => {
        println(`Origination completed.`);
        Tezos.tz.getBalance(contract.address).then((balance) => {
          println(`The balance of the contract is ${balance.toNumber() / 1000000} ꜩ.`);
          const estimateOp = contract.methods
            .do(transferImplicit('tz1PgQt52JMirBUhhkq1eanX8hVd1Fsg71Lr', balance.toNumber()))
            .toTransferParams({});
          println(`Waiting for the estimation of the smart contract call...`);
          Tezos.estimate
            .transfer(estimateOp)
            .then((estimate) => {
              //Will be deducted from manager's address
              println(
                `The estimated fees related to the emptying operation are ${estimate.suggestedFeeMutez} mutez.`
              );
              return contract.methods
                .do(transferImplicit('tz1PgQt52JMirBUhhkq1eanX8hVd1Fsg71Lr', balance.toNumber()))
                .send({ amount: 0 });
            })
            .then((operation) => {
              println(`Waiting for confirmation of the draining operation...`);
              return operation.confirmation(1).then(() => operation.hash);
            })
            .then((hash) => {
              println(`The account has been emptied.`);
              return Tezos.tz.getBalance(contract.address);
            })
            .then((finalBalance) => {
              println(`The balance is now ${finalBalance.toNumber() / 1000000} ꜩ.`);
            });
        });
      });
  })
  .catch((error) => println(`Error: ${JSON.stringify(error, null, 2)}`));

Is Account Active


import { LedgerSigner, DerivationType } from '@taquito/ledger-signer';
import { TezosToolkit } from '@taquito/taquito';
import TransportNodeHid from "@ledgerhq/hw-transport-node-hid";

async function example() {

    const transport = await TransportNodeHid.create();
    let index = 0;
    const tezos = new TezosToolkit('<https://hangzhounet.api.tez.ie>')
    while (index < 10) {
        const ledgerSigner = new LedgerSigner(transport, `44'/1729'/${index}'/0'`, false, DerivationType.ED25519);
        tezos.setProvider({ signer: ledgerSigner });
        const pkh = await tezos.signer.publicKeyHash();
        const balance = await tezos.tz.getBalance(pkh)
        const getPublicKey = await tezos.rpc.getManagerKey(pkh)
        console.log(`The public key hash related to the derivation path having the account ${index} is ${pkh}.`)
        if (getPublicKey) {
            console.log(`The balance is ${balance.toNumber() / 1000000} ꜩ.\n`)
        } else {
            console.log('This account is not revealed.\n')
        }
        index++
    }
}

Get something from contract (Token balance)


await tezos.contract.at('KT1UuzwkGJEoFJGY2XV21NdJeJ4tgXWmfbGE').then(async contract => {
      const contractStorage = await contract.storage();
      const bigMapKey = await (contractStorage as any).ledger.get('tz1btkXVkVFWLgXa66sbRJa8eeUSwvQFX4kP')
      console.log(bigMapKey)
    });
import { TezosToolkit } from '@taquito/taquito';
import { InMemorySigner } from '@taquito/signer';

async function example() {
    const provider = '<https://ithacanet.ecadinfra.com/>';
    const signer: any = new InMemorySigner('edskRtmEwZxRzwd1obV9pJzAoLoxXFWTSHbgqpDBRHx1Ktzo5yVuJ37e2R4nzjLnNbxFU4UiBU1iHzAy52pK5YBRpaFwLbByca');
        const tezos = new TezosToolkit(provider);
    tezos.setSignerProvider( signer );
    try {
        console.log("signer pkh:");
        console.log(await signer.publicKeyHash());
        const contract = await tezos.contract.at('KT1SyjphGj51CadmmbL8dmKwMA4VyMQdtkjB');
        console.log("Printing contract methods...");
        console.log(contract.methods);
        console.log("Showing initial storage...");
        console.log(await contract.storage())
        const op = await contract.methods.mint("tz1bwsEWCwSEXdRvnJxvegQZKeX5dj6oKEys", 100).send()
        console.log('Awaiting confirmation...');
        await op.confirmation();
        console.log(op.hash, op.includedInBlock);
        console.log("Showing final storage...");
        console.log(await contract.storage())
    } catch (ex) {
        console.log(ex)
    }
}