How to use @taquito/taquito - 10 common examples

To help you get started, we’ve selected a few @taquito/taquito examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github ecadlabs / taquito / integration-tests / manager-contract-scenario.spec.ts View on Github external
// A regular transfer operation is made. No smart contract calls required for this scenario.
      const opTransferToContract = await Tezos.contract.transfer({ to: contract.address, amount: 1 })
      await opTransferToContract.confirmation();
      expect(op.status).toEqual('applied')
      // Transfer from contract (kt1_alice) to implicit account (tz1)
      // We pass a lambda function to the kt1_alice contracts `do` entrypoint. The lambda code causes the contract to transfer
      // the specified number (50) of mutez to the target address.
      const opTransfer = await contract.methods.do(MANAGER_LAMBDA.transferImplicit("tz1eY5Aqa1kXDFoiebL28emyXFoneAoVg1zh", 50)).send({ amount: 0 })
      await opTransfer.confirmation();
      expect(opTransfer.status).toEqual('applied')
      // Set delegate on contract kt1_alice by passing a lambda function to kt1_alice's `do` entrypoint
      const opSetDelegate = await contract.methods.do(MANAGER_LAMBDA.setDelegate("tz1eY5Aqa1kXDFoiebL28emyXFoneAoVg1zh")).send({ amount: 0 })
      await opSetDelegate.confirmation();
      expect(opSetDelegate.status).toEqual('applied')
      // Remove delegate on contract kt1_alice by passing a lambda function to kt1_alice's `do` entrypoint
      const removeDelegateOp = await contract.methods.do(MANAGER_LAMBDA.removeDelegate()).send({ amount: 0 })
      await removeDelegateOp.confirmation();
      expect(removeDelegateOp.status).toEqual('applied')
      // Transfer from contract (kt1_alice) to contract (kt1 bob)
      // Notice that we are instructing the kt1_alice contract to send 1 token to kt1_bob. The transfer value is passed to the
      // lambda helper function. The transfer amount in the actual transfer operation is 0. We are not transferring the token
      // in the transfer operation, we are instructing the contract to transfer the token using the `do` entrypoint of the kt1_alice
      // contract.
      const transferToContractOp = await contract.methods.do(MANAGER_LAMBDA.transferToContract("KT1EM2LvxxFGB3Svh9p9HCP2jEEYyHjABMbK", 1)).send({ amount: 0 })
      await transferToContractOp.confirmation();
      expect(transferToContractOp.status).toEqual('applied')
      done();
    })
  })
github ecadlabs / taquito / integration-tests / manager-contract-scenario.spec.ts View on Github external
})
      const contract = await op.contract();
      expect(op.status).toEqual('applied')
      // Transfer from implicit account (tz1) to contract (kt1_alice)
      // A regular transfer operation is made. No smart contract calls required for this scenario.
      const opTransferToContract = await Tezos.contract.transfer({ to: contract.address, amount: 1 })
      await opTransferToContract.confirmation();
      expect(op.status).toEqual('applied')
      // Transfer from contract (kt1_alice) to implicit account (tz1)
      // We pass a lambda function to the kt1_alice contracts `do` entrypoint. The lambda code causes the contract to transfer
      // the specified number (50) of mutez to the target address.
      const opTransfer = await contract.methods.do(MANAGER_LAMBDA.transferImplicit("tz1eY5Aqa1kXDFoiebL28emyXFoneAoVg1zh", 50)).send({ amount: 0 })
      await opTransfer.confirmation();
      expect(opTransfer.status).toEqual('applied')
      // Set delegate on contract kt1_alice by passing a lambda function to kt1_alice's `do` entrypoint
      const opSetDelegate = await contract.methods.do(MANAGER_LAMBDA.setDelegate("tz1eY5Aqa1kXDFoiebL28emyXFoneAoVg1zh")).send({ amount: 0 })
      await opSetDelegate.confirmation();
      expect(opSetDelegate.status).toEqual('applied')
      // Remove delegate on contract kt1_alice by passing a lambda function to kt1_alice's `do` entrypoint
      const removeDelegateOp = await contract.methods.do(MANAGER_LAMBDA.removeDelegate()).send({ amount: 0 })
      await removeDelegateOp.confirmation();
      expect(removeDelegateOp.status).toEqual('applied')
      // Transfer from contract (kt1_alice) to contract (kt1 bob)
      // Notice that we are instructing the kt1_alice contract to send 1 token to kt1_bob. The transfer value is passed to the
      // lambda helper function. The transfer amount in the actual transfer operation is 0. We are not transferring the token
      // in the transfer operation, we are instructing the contract to transfer the token using the `do` entrypoint of the kt1_alice
      // contract.
      const transferToContractOp = await contract.methods.do(MANAGER_LAMBDA.transferToContract("KT1EM2LvxxFGB3Svh9p9HCP2jEEYyHjABMbK", 1)).send({ amount: 0 })
      await transferToContractOp.confirmation();
      expect(transferToContractOp.status).toEqual('applied')
      done();
    })
github ecadlabs / taquito / integration-tests / manager-contract-scenario.spec.ts View on Github external
const op = await Tezos.contract.originate({
        balance: "1",
        code: managerCode,
        init: { "string": await Tezos.signer.publicKeyHash() },
      })
      const contract = await op.contract();
      expect(op.status).toEqual('applied')
      // Transfer from implicit account (tz1) to contract (kt1_alice)
      // A regular transfer operation is made. No smart contract calls required for this scenario.
      const opTransferToContract = await Tezos.contract.transfer({ to: contract.address, amount: 1 })
      await opTransferToContract.confirmation();
      expect(op.status).toEqual('applied')
      // Transfer from contract (kt1_alice) to implicit account (tz1)
      // We pass a lambda function to the kt1_alice contracts `do` entrypoint. The lambda code causes the contract to transfer
      // the specified number (50) of mutez to the target address.
      const opTransfer = await contract.methods.do(MANAGER_LAMBDA.transferImplicit("tz1eY5Aqa1kXDFoiebL28emyXFoneAoVg1zh", 50)).send({ amount: 0 })
      await opTransfer.confirmation();
      expect(opTransfer.status).toEqual('applied')
      // Set delegate on contract kt1_alice by passing a lambda function to kt1_alice's `do` entrypoint
      const opSetDelegate = await contract.methods.do(MANAGER_LAMBDA.setDelegate("tz1eY5Aqa1kXDFoiebL28emyXFoneAoVg1zh")).send({ amount: 0 })
      await opSetDelegate.confirmation();
      expect(opSetDelegate.status).toEqual('applied')
      // Remove delegate on contract kt1_alice by passing a lambda function to kt1_alice's `do` entrypoint
      const removeDelegateOp = await contract.methods.do(MANAGER_LAMBDA.removeDelegate()).send({ amount: 0 })
      await removeDelegateOp.confirmation();
      expect(removeDelegateOp.status).toEqual('applied')
      // Transfer from contract (kt1_alice) to contract (kt1 bob)
      // Notice that we are instructing the kt1_alice contract to send 1 token to kt1_bob. The transfer value is passed to the
      // lambda helper function. The transfer amount in the actual transfer operation is 0. We are not transferring the token
      // in the transfer operation, we are instructing the contract to transfer the token using the `do` entrypoint of the kt1_alice
      // contract.
      const transferToContractOp = await contract.methods.do(MANAGER_LAMBDA.transferToContract("KT1EM2LvxxFGB3Svh9p9HCP2jEEYyHjABMbK", 1)).send({ amount: 0 })
github ecadlabs / taquito / integration-tests / manager-contract-scenario.spec.ts View on Github external
await opTransfer.confirmation();
      expect(opTransfer.status).toEqual('applied')
      // Set delegate on contract kt1_alice by passing a lambda function to kt1_alice's `do` entrypoint
      const opSetDelegate = await contract.methods.do(MANAGER_LAMBDA.setDelegate("tz1eY5Aqa1kXDFoiebL28emyXFoneAoVg1zh")).send({ amount: 0 })
      await opSetDelegate.confirmation();
      expect(opSetDelegate.status).toEqual('applied')
      // Remove delegate on contract kt1_alice by passing a lambda function to kt1_alice's `do` entrypoint
      const removeDelegateOp = await contract.methods.do(MANAGER_LAMBDA.removeDelegate()).send({ amount: 0 })
      await removeDelegateOp.confirmation();
      expect(removeDelegateOp.status).toEqual('applied')
      // Transfer from contract (kt1_alice) to contract (kt1 bob)
      // Notice that we are instructing the kt1_alice contract to send 1 token to kt1_bob. The transfer value is passed to the
      // lambda helper function. The transfer amount in the actual transfer operation is 0. We are not transferring the token
      // in the transfer operation, we are instructing the contract to transfer the token using the `do` entrypoint of the kt1_alice
      // contract.
      const transferToContractOp = await contract.methods.do(MANAGER_LAMBDA.transferToContract("KT1EM2LvxxFGB3Svh9p9HCP2jEEYyHjABMbK", 1)).send({ amount: 0 })
      await transferToContractOp.confirmation();
      expect(transferToContractOp.status).toEqual('applied')
      done();
    })
  })
github ecadlabs / taquito / integration-tests / config.ts View on Github external
export const CONFIGS = providers.map((provider) => {
  const Tezos = new TezosToolkit();
  Tezos.setProvider({ rpc: provider })
  return {
    rpc: provider, lib: Tezos, setup: async () => {
      let faucetKey = {
        email: "peqjckge.qkrrajzs@tezos.example.org",
        password: "y4BX7qS1UE", mnemonic: [
          "skate",
          "damp",
          "faculty",
          "morning",
          "bring",
          "ridge",
          "traffic",
          "initial",
          "piece",
          "annual",
github ecadlabs / taquito / integration-tests / contract-api-scenario.spec.ts View on Github external
it('Simple set delegate', async (done) => {
      const delegate = 'tz1PirboZKFVqkfE45hVLpkpXaZtLk3mqC17'
      const op = await Tezos.contract.setDelegate({
        delegate,
        source: await Tezos.signer.publicKeyHash(),
        fee: DEFAULT_FEE.DELEGATION,
        gasLimit: DEFAULT_GAS_LIMIT.DELEGATION
      })
      await op.confirmation()
      expect(op.hash).toBeDefined();
      expect(op.includedInBlock).toBeLessThan(Number.POSITIVE_INFINITY)

      const account = await Tezos.rpc.getDelegate(await Tezos.signer.publicKeyHash())
      expect(account).toEqual(delegate)
      done();
    });
github ecadlabs / taquito / integration-tests / contract-api-scenario.spec.ts View on Github external
it('Simple set delegate', async (done) => {
      const delegate = 'tz1PirboZKFVqkfE45hVLpkpXaZtLk3mqC17'
      const op = await Tezos.contract.setDelegate({
        delegate,
        source: await Tezos.signer.publicKeyHash(),
        fee: DEFAULT_FEE.DELEGATION,
        gasLimit: DEFAULT_GAS_LIMIT.DELEGATION
      })
      await op.confirmation()
      expect(op.hash).toBeDefined();
      expect(op.includedInBlock).toBeLessThan(Number.POSITIVE_INFINITY)

      const account = await Tezos.rpc.getDelegate(await Tezos.signer.publicKeyHash())
      expect(account).toEqual(delegate)
      done();
    });
github ecadlabs / taquito / example / contract-schema.ts View on Github external
async function example() {
    const provider = 'https://alphanet-node.tzscan.io';
    const signer: any = new InMemorySigner('edsk3xkqabYfWWpcEKTWk75cRQv2bgHA3EHuuHSFH3ejqzKPx69Zh9');
    Tezos.setProvider({ rpc: provider, signer });
    try {
        const contract = await Tezos.contract.at('KT1SawqvsVdAbDzqc4KwPpaS1S1veuFgF9AN');
        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("tz1QZ6KY7d3BuZDT1d19dUxoQrtFPN2QJ3hn", 100).send({ fee: 30000, gasLimit: 200000 })
        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)
    }
}
github ecadlabs / taquito / example / example-activate.ts View on Github external
async function example() {
    const provider = 'https://alphanet-node.tzscan.io';
    Tezos.setProvider({ rpc: provider });
    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)
    }
}
github ecadlabs / taquito / example / contract-origination2.ts View on Github external
"bring",
        "ridge",
        "traffic",
        "initial",
        "piece",
        "annual",
        "give",
        "say",
        "wrestle",
        "rare",
        "ability"
    ].join(" "), "7d4c8c3796fdbf4869edb5703758f0e5831f5081")

    try {
        console.log('Deploying Ligo simple contract...')
        const op = await Tezos.contract.originate({
            balance: "1",
            code: ligoSample,
            init: { int: "0" },
            fee: 30000,
            storageLimit: 2000,
            gasLimit: 90000,
        })
        console.log('Awaiting confirmation...')
        const contract = await op.contract()
        console.log('Storage', await contract.storage())
        console.log("Operation hash:", op.hash, "Included in block level:", op.includedInBlock)
    } catch (ex) {
        console.error(ex)
    }
}