Skip to content

Commit

Permalink
Merge pull request #338 from trilitech/staging
Browse files Browse the repository at this point in the history
Update main from staging, Feb 21
  • Loading branch information
timothymcmackin authored Feb 21, 2024
2 parents a89c787 + a14e3c4 commit 526475c
Show file tree
Hide file tree
Showing 14 changed files with 246 additions and 39 deletions.
107 changes: 104 additions & 3 deletions docs/dApps/sending-transactions.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
title: Sending transactions
authors: "Tim McMackin"
last_update:
date: 7 November 2023
date: 1 February 2024
---
<!-- TODO originating contracts: https://tezostaquito.io/docs/originate -->

Expand Down Expand Up @@ -78,14 +78,115 @@ try {
console.log(`Waiting for ${op.opHash} to be confirmed...`);
await op.confirmation(2);
} catch (error) {
console.log(`Error: ${JSON.stringify(error, null, 2)}`)
console.log(`Error: ${JSON.stringify(error, null, 2)}`);
}
```

For examples of calling smart contracts, see tutorials such as [Build a simple web application](../tutorials/build-your-first-app) or [Create a contract and web app that mints NFTs](../tutorials/create-an-nft/nft-taquito).
To call an entrypoint that accepts parameters, you must encode those parameters in the format that the entrypoint requires.

To see the format for these parameters, create a Taquito object that represents the contract and extract its parameter schema, as in the following example:

```javascript
const contract = await Tezos.wallet.at(contractAddress);
const parameterSchema = contract.parameterSchema;
console.log(parameterSchema.ExtractSignatures());
```

The response shows the entrypoints in the contract and the parameters that they accept.

For example, the [FA2](../architecture/tokens/FA2) `transfer` entrypoint appears like this:

```json
[
"transfer",
{
"list": {
"from_": "address",
"txs": {
"list": {
"to_": "address",
"token_id": "nat",
"amount": "nat"
}
}
}
}
]
```

This `transfer` entrypoint accepts an array of token transfers.
Each transfer object includes the address to take the tokens from and an array of accounts to send the tokens to, as in this example:


```javascript
const transactionParams = [
{
from_: sourceAddress,
txs: [
{
to_: targetAddress1,
token_id: 7,
amount: 2,
},
{
to_: targetAddress2,
token_id: 7,
amount: 3,
},
],
},
];
```

To call the `transfer` entrypoint, pass this parameter to the Taquito entrypoint method, as in this example:

```javascript
Tezos.setWalletProvider(wallet);
const contract = await Tezos.wallet.at(contractAddress);

const transactionParams = [
{
from_: sourceAddress,
txs: [
{
to_: targetAddress1,
token_id: 7,
amount: 2,
},
{
to_: targetAddress2,
token_id: 7,
amount: 3,
},
],
},
];

const estimation = await Tezos.estimate.transfer({
to: contractAddress,
amount: 0,
parameter: contract.methods.transfer(transactionParams).toTransferParams().parameter
});

const operation = await contract.methods
.transfer(transactionParams, estimation)
.send();

console.log(`Waiting for ${operation.opHash} to be confirmed...`);

await operation.confirmation(2);

console.log(
`Operation injected: https://ghost.tzstats.com/${operation.opHash}`,
);
```

For more examples of calling smart contracts, see tutorials such as [Build a simple web application](../tutorials/build-your-first-app) or [Create a contract and web app that mints NFTs](../tutorials/create-an-nft/nft-taquito).

For more information about using Taquito, see [Smart contracts](https://tezostaquito.io/docs/smartcontracts) in the Taquito documentation.

For a video walkthrough, see [Interacting with FA2 Contracts Using Taquito](https://www.youtube.com/watch?v=xL6jyW1sqmA).

## Beacon

You can use the Beacon SDK to send transactions from JavaScript/TypeScript code.
Expand Down
16 changes: 15 additions & 1 deletion docs/developing/wallet-setup.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
title: Installing and funding a wallet
authors: Tim McMackin
last_update:
date: 27 November 2023
date: 13 February 2024
---

To work with Tezos, you need a wallet, which is an application that maintains your accounts and signs Tezos transactions on your behalf.
Expand All @@ -18,6 +18,20 @@ Browser extensions include the [Temple](https://templewallet.com/) browser exten

Desktop wallets for Tezos include [Kukai](https://wallet.kukai.app/) and [Umami](https://umamiwallet.com/).

Tezos also supports the [MetaMask wallet](https://metamask.io/), but only its browser extension, and only on Mainnet.
Follow these steps to enable Tezos in MetaMask:

1. Install the MetaMask browser extension.
1. Go to https://metamask.tezos.com.
1. Click **Connect with MetaMask**.
1. Approve the installation of the Tezos snap in MetaMask.

Now you can connect to Tezos dApps with MetaMask.
When a web application shows the Beacon window to connect your wallet, you can select MetaMask.
The page sends you to https://metamask.tezos.com to approve and manage the connection.

For more information about using MetaMask with Tezos, see [MetaMask Now Supports Tezos: An Explainer](https://spotlight.tezos.com/metamask-now-supports-tezos-an-explainer/).

## Switching the wallet to a testnet

If you're doing development work, you're probably using a testnet instead of Mainnet.
Expand Down
90 changes: 85 additions & 5 deletions docs/smart-contracts/deploying.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,14 @@
title: Deploying smart contracts
authors: 'Yuxin Li'
last_update:
date: 6 November 2023
date: 13 February 2024
---
## Introduction
In Tezos, deploying a smart contract is often referred to as “origination”. This process essentially creates a new account that holds the smart contract's script. Contracts originated in this manner have addresses that start with `KT1`, which distinguishes them from the user accounts with addresses beginning with `tz1`, `tz2`, or `tz3`.

## Prerequisites
- Compile your contract and its initial storage
- Set up an wallet account on Tezos with some tez to pay the fees
- Ensure that you have obtained the [Tezos client](../developing/octez-client/installing)

## Deploying a smart contract
Generally, there are two methods for deploying your smart contracts: either using the command line in your terminal or deploying through an online IDE.
Expand All @@ -31,12 +30,93 @@ where:
- `GAZ_FEE` is a specified maximal fee the user is willing to pay for this operation (using the --burn-cap parameter).

### Deploying via online IDE
As for deploying through your online IDE, if you are using LIGO or SmartPy programming languages, you can simply deploy your smart contracts through their respective online IDEs.
As for deploying through your online IDE, if you are using LIGO or SmartPy programming languages, you can deploy your smart contracts through their respective online IDEs.
- [SmartPy online IDE](https://smartpy.io/)
- [LIGO online IDE](https://ligolang.org/?lang=jsligo)

## Compiling the initial storage value

When you deploy a contract, you initialize its storage.
The initial value of the storage must be a Micheline value, which is the format for variables in Michelson smart contracts.
The high-level languages provide tools to compile the initial values of smart contracts into Micheline values.

### Compiling LIGO storage values

For LIGO smart contracts, you can use the `ligo compile storage` command.
For example, assume that a JsLIGO contract has a storage value that includes a list of integers, a string, and an integer:

```ligolang
type storage = [
list<int>,
string,
int,
];
```

When this contract is compiled to Michelson, the storage line of the contract looks like this:

```michelson
storage (pair (list int) string int) ;
```

To compile an initial value to this format, you can pass a JsLIGO value to the `ligo compile storage` command, as in this example:

```bash
ligo compile storage MyContract.jsligo '[list([1,2,3,4]), "start", 0]'
```

The result is the Micheline value, as in this example:

```michelson
(Pair { 1 ; 2 ; 3 ; 4 } "start" 0)
```

Then you can use this Micheline value as the initial storage value for the contract:

```bash
octez-client originate contract MyContract \
transferring 0 from my_account \
running MyContract.tz --init '(Pair { 1 ; 2 ; 3 ; 4 } "start" 0)' \
--burn-cap 1
```

### Compiling SmartPy storage values

SmartPy lets you set the initial value of the contract storage in the smart contract code in the `__init__` function.
For example, this contract defines three storage variables and sets their initial values:

```python
import smartpy as sp

@sp.module
def main():
class MyList(sp.Contract):
def __init__(self):
self.data.ListOfIntegers = [1,2,3,4]
self.data.MyString = "hello"
self.data.MyInteger = 5
```

Now you can compile and deploy the contract via the online IDE with these starting values.

If you want to deploy the contract with the Octez client, add a test to the contract and run the test with the command `python MyContract.py`.
One of the files this command creates ends in `storage.tz` and contains the Micheline value of the initial storage, as in this example:

```
(Pair {1; 2; 3; 4} (Pair 5 "hello"))
```

Then you can use this Micheline value as the initial storage value for the contract:

```bash
octez-client originate contract MyContract \
transferring 0 from my_account \
running MyContract.tz --init '(Pair { 1 ; 2 ; 3 ; 4 } "start" 0)' \
--burn-cap 1
```

## Interacting with the contract
Once you have successfully originated the smart contract and it is included in a baked block, there are two ways to interact with it: through command lines or through a block explorer.
When you have successfully originated the smart contract and it is included in a baked block, there are two ways to interact with it: through command lines or through a block explorer.

### Interacting through command lines
The first method involves interacting with the contract's entry points using command lines.
Expand Down Expand Up @@ -83,7 +163,7 @@ A blockchain explorer is an efficient and user-friendly tool that enables you to
- [Better Call Dev](https://better-call.dev/)
- [TzKT](https://tzkt.io/)

To interact with a contract, simply copy its address into one of these blockchain explorers. Below is the user interface for interacting with a contract through Better Call Dev:
To interact with a contract, copy its address into one of these blockchain explorers. Below is the user interface for interacting with a contract through Better Call Dev:

![UI for Better Call Dev](/img/tutorials/better-call.png)

Expand Down
10 changes: 9 additions & 1 deletion docs/tutorials/join-dal-baker/prepare-account.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
title: "Step 3: Set up a baker account on Weeklynet"
authors: Tezos core developers
last_update:
date: 14 February 2024
date: 19 February 2024
---

Our baker needs a user account consisting of a pair of keys and an address.
Expand All @@ -11,6 +11,14 @@ Our baker needs a user account consisting of a pair of keys and an address.
If you are using a Docker container, you can enter the container with the `docker exec` command, as in `docker exec -it my-image /bin/sh`.
To get the name of the Docker container, you run the `docker ps` command.

1. Set your installation of the Octez client to use your node instead of the public Weeklynet node:

```bash
octez-client -E http://127.0.0.1:8732 config update
```

Now that you have your own node, you can use its private RPC endpoint so your commands run quickly, instead of using the public RPC endpoint.

1. Create or import an account in the Octez client.
The simplest way to get an account that works with Weeklynet is to use the Octez client to randomly generate an account.
This command creates an account and associates it with the `my_baker` alias:
Expand Down
Loading

0 comments on commit 526475c

Please sign in to comment.