0.45.0 • Published 6 months ago

@taqueria/plugin-contract-types v0.45.0

Weekly downloads
-
License
ISC
Repository
-
Last release
6 months ago

This plugin will generate typescript types for a contract.

In the simple case, it reads the artifacts folder for any *.tz Michelson files and will generate a types file with the matching filename for each.

Requirements

This is using a unmerged taquito PR:

Examples

Example Usage (based on an nft auction contract from open minter sdk)

export const exampleContractMethods1 = async () => {

    const Tezos = new TezosToolkit(`https://YOUR_PREFERRED_RPC_URL`)

    const contract = await Tezos.contract.at<TestContract>(`tz123`);

    contract.methods.bid(tas.nat(0));
    contract.methods.configure(
        /*opening_price:*/ tas.mutez(10),
        /*min_raise_percent:*/ tas.nat(10),
        /*min_raise:*/ tas.mutez(10),
        /*round_time:*/ tas.nat(10),
        /*extend_time:*/ tas.nat(10),
        /*asset:*/ [{
            fa2_address: tas.address(`tz123`),
            fa2_batch: [{
                amount: tas.nat(100),
                token_id: tas.nat(`100000000000000`),
            }],
        }],
        /*start_time:*/ tas.timestamp(new Date()),
        /*end_time:*/ tas.timestamp(`2020-01-01`),
    );

    // methodsObject
    contract.methodsObject.bid(tas.nat(0));
    contract.methodsObject.configure({
        asset: [{
            fa2_address: tas.address(`tz123`),
            fa2_batch: [{
                amount: tas.nat(100),
                token_id: tas.nat(`100000000000000`),
            }],
        }],
        start_time: tas.timestamp(new Date()),
        end_time: tas.timestamp(`2020-01-01`),
        extend_time: tas.nat(10),
        min_raise: tas.mutez(10),
        min_raise_percent: tas.nat(10),
        opening_price: tas.mutez(10),
        round_time: tas.nat(10),
    });

};

Example typegen task

$ taqueria typegen --typescriptDir ./types
generateTypes
{
  "typescriptDir": "./types"
}
Generating Types: /home/rick/projects/crypto/taqueria/example/artifacts => /home/rick/projects/crypto/taqueria/example/types
Contracts Found:
        - /home/rick/projects/crypto/taqueria/example/artifacts/example-contract-1.tz
Processing /example-contract-1.tz...example-contract-1.tz: Types generated

Example type output

type Storage = {
    pauseable_admin?: {
        admin: address;
        paused: boolean;
        pending_admin?: address;
    };
    current_id: nat;
    max_auction_time: nat;
    max_config_to_start_time: nat;
    auctions: BigMap<nat, {
        seller: address;
        current_bid: mutez;
        start_time: timestamp;
        last_bid_time: timestamp;
        round_time: int;
        extend_time: int;
        asset: Array<{
            fa2_address: address;
            fa2_batch: Array<{
                token_id: nat;
                amount: nat;
            }>;
        }>;
        min_raise_percent: nat;
        min_raise: mutez;
        end_time: timestamp;
        highest_bidder: address;
    }>;
};

type Methods = {
    confirm_admin: () => Promise<void>;
    pause: (param: boolean) => Promise<void>;
    set_admin: (param: address) => Promise<void>;
    bid: (param: nat) => Promise<void>;
    cancel: (param: nat) => Promise<void>;
    configure: (
        opening_price: mutez,
        min_raise_percent: nat,
        min_raise: mutez,
        round_time: nat,
        extend_time: nat,
        asset: Array<{
            fa2_address: address;
            fa2_batch: Array<{
                token_id: nat;
                amount: nat;
            }>;
        }>,
        start_time: timestamp,
        end_time: timestamp,
    ) => Promise<void>;
    resolve: (param: nat) => Promise<void>;
};

Taquito library changes

See example-usage.ts for full example

Before

Using taquito with the generated contract types:

The at method can be called providing a type with a utility method that can be provided:

const contract = await Tezos.contract.at(`tz123`, contractAbstractionComposer<TestContractType>());

// methods can now use typed parameters
// methodsObject will be able to use type parameters

This can work the same with a wallet

const contract = await Tezos.wallet.at(`tz123`, walletAbstractionComposer<TestContractType>());

Alternatively, this can be done with a cast:

const contract = await Tezos.contract.at(`tz123`) as ContractProviderFromContractType<TestContractType>;

The originate contract does not have any way to provide a type, so this requires a cast:

const originationResult = await Tezos.contract.originate({...});
const contract = await originationResult.contract(5) as ContractProviderFromContractType<TestContractType2>;

For accessing storage, there is no way to pass the type through the contract class, so it requires providing the type again:

const contract = await Tezos.contract.at(`tz123`) as ContractProviderFromContractType<TestContractType>;
const storage = await contract.storage<StorageFromContractType<TestContractType>>();

After

Extending ContractAbstraction with additional generic types:

The at method can be called with the contract type provided:

const contract = await Tezos.contract.at<TestContract>(`tz123`);

// methods can now use typed parameters
// methodsObject will be able to use type parameters
// storage will be able to use type parameters

This can work the same with a wallet

const contract = await Tezos.wallet.at<TestWalletContract>(`tz123`);

The originate contract now accepts a type:

const originationResult = await Tezos.contract.originate({...});
const contract = await originationResult.contract<TestContract2>(5);

The contract type now also provides the default storage type:

const contract = await Tezos.contract.at<TestContract>(`tz123`);
const storage = await contract.storage();
0.39.13

8 months ago

0.39.16

8 months ago

0.39.12

8 months ago

0.39.17

8 months ago

0.39.18

8 months ago

0.39.19

8 months ago

0.44.6

6 months ago

0.44.7

6 months ago

0.44.4

6 months ago

0.44.5

6 months ago

0.44.2

6 months ago

0.44.3

6 months ago

0.44.0

6 months ago

0.44.8

6 months ago

0.37.50

8 months ago

0.33.1

10 months ago

0.37.45

9 months ago

0.37.44

9 months ago

0.37.46

9 months ago

0.37.49

9 months ago

0.37.48

9 months ago

0.42.8

6 months ago

0.40.31

7 months ago

0.42.9

6 months ago

0.40.32

7 months ago

0.42.6

6 months ago

0.42.7

6 months ago

0.42.5

6 months ago

0.42.2

6 months ago

0.40.33

7 months ago

0.42.3

6 months ago

0.40.34

7 months ago

0.39.31

8 months ago

0.42.0

7 months ago

0.42.1

7 months ago

0.39.30

8 months ago

0.40.20

7 months ago

0.40.24

7 months ago

0.40.25

7 months ago

0.40.23

7 months ago

0.39.24

8 months ago

0.39.20

8 months ago

0.39.23

8 months ago

0.31.1

10 months ago

0.40.13

7 months ago

0.40.14

7 months ago

0.40.17

7 months ago

0.40.18

7 months ago

0.40.15

7 months ago

0.40.16

7 months ago

0.39.28

8 months ago

0.40.19

7 months ago

0.37.2

9 months ago

0.37.0

10 months ago

0.37.34

9 months ago

0.37.36

9 months ago

0.37.31

9 months ago

0.37.37

9 months ago

0.37.21

9 months ago

0.37.20

9 months ago

0.37.12

9 months ago

0.37.14

9 months ago

0.37.13

9 months ago

0.37.10

9 months ago

0.35.1

10 months ago

0.37.16

9 months ago

0.39.1

8 months ago

0.39.0

8 months ago

0.39.4

8 months ago

0.41.21

7 months ago

0.41.9

7 months ago

0.41.5

7 months ago

0.41.6

7 months ago

0.41.23

7 months ago

0.41.24

7 months ago

0.41.4

7 months ago

0.43.0

6 months ago

0.32.1

10 months ago

0.45.1

6 months ago

0.45.2

6 months ago

0.45.0

6 months ago

0.41.0

7 months ago

0.41.10

7 months ago

0.41.11

7 months ago

0.41.18

7 months ago

0.41.19

7 months ago

0.30.1

10 months ago

0.28.23

10 months ago

0.28.22

10 months ago

0.28.26

10 months ago

0.28.18

10 months ago

0.28.17

10 months ago

0.43.5

6 months ago

0.43.3

6 months ago

0.43.4

6 months ago

0.43.1

6 months ago

0.43.2

6 months ago

0.36.4

10 months ago

0.36.0

10 months ago

0.36.9

10 months ago

0.36.8

10 months ago

0.36.7

10 months ago

0.36.6

10 months ago

0.36.5

10 months ago

0.36.12

10 months ago

0.36.11

10 months ago

0.34.1

10 months ago

0.38.2

8 months ago

0.38.1

8 months ago

0.38.0

8 months ago

0.42.12

6 months ago

0.40.8

7 months ago

0.42.11

6 months ago

0.40.6

7 months ago

0.42.13

6 months ago

0.40.7

7 months ago

0.40.4

7 months ago

0.40.2

7 months ago

0.40.0

8 months ago

0.28.6

1 year ago

0.28.5

1 year ago

0.28.4

1 year ago

0.28.3

1 year ago

0.28.2

1 year ago

0.28.1

1 year ago

0.27.1-rc

1 year ago

0.27.16-rc

1 year ago

0.26.28-rc

1 year ago

0.27.1-alpha

1 year ago

0.27.12-rc

1 year ago

0.27.8-rc

1 year ago

0.25.3-alpha

1 year ago

0.25.16-rc

1 year ago

0.27.6-rc

1 year ago

0.25.19-rc

1 year ago

0.25.30-rc

1 year ago

0.25.29-rc

1 year ago

0.28.0

1 year ago

0.27.2-alpha

1 year ago

0.25.22-rc

1 year ago

0.25.4-alpha

1 year ago

0.27.4-rc

1 year ago

0.27.0-rc

1 year ago

0.26.27-rc

1 year ago

0.27.2-rc

1 year ago

0.27.15-rc

1 year ago

0.25.17-rc

1 year ago

0.25.13-rc

1 year ago

0.27.9-rc

1 year ago

0.27.5-rc

1 year ago

0.25.31-rc

1 year ago

0.27.10-rc

1 year ago

0.25.11-rc

1 year ago

0.27.7-rc

1 year ago

0.27.3-rc

1 year ago

0.25.23-rc

1 year ago

0.25.6-alpha

1 year ago

0.27.17-rc

1 year ago

0.27.0-alpha

1 year ago

0.25.21-rc

1 year ago

0.23.16-rc

1 year ago

0.23.5-rc.1

1 year ago

0.25.0-alpha

1 year ago

0.22.2

2 years ago

0.23.14-rc

1 year ago

0.23.8-rc.1

1 year ago

0.23.18-rc

1 year ago

0.24.2

1 year ago

0.24.1

1 year ago

0.24.0

1 year ago

0.23.21-rc

1 year ago

0.21.30

2 years ago

0.23.4-rc.1

1 year ago

0.21.29

2 years ago

0.21.23

2 years ago

0.23.6-rc.1

1 year ago

0.21.14

2 years ago

0.21.12

2 years ago

0.21.13

2 years ago

0.21.11

2 years ago

0.23.11-rc

1 year ago

0.23.23-rc

1 year ago

0.21.7

2 years ago

0.21.5

2 years ago

0.23.15-rc

1 year ago

0.21.0

2 years ago

0.23.3-rc.1

1 year ago

0.23.0-rc.2

2 years ago

0.23.0-rc.1

2 years ago

0.23.19-rc

1 year ago

0.23.1-rc.1

1 year ago

0.23.24-rc

1 year ago

0.23.2-rc.1

1 year ago

0.20.1

2 years ago

0.20.0

2 years ago

0.20.2

2 years ago

0.13.16

2 years ago

0.19.2

2 years ago

0.19.3

2 years ago

0.19.4

2 years ago

0.19.5

2 years ago

0.19.6

2 years ago

0.19.7

2 years ago

0.14.2

2 years ago

0.14.3

2 years ago

0.14.4

2 years ago

0.12.0

2 years ago

0.18.0

2 years ago

0.16.0

2 years ago

0.5.6-rc1

2 years ago

0.7.6-rc5

2 years ago

0.5.8-rc1

2 years ago

0.7.2-rc2

2 years ago

0.5.9-rc1

2 years ago

0.7.5-rc4

2 years ago

0.8.4

2 years ago

0.10.0

2 years ago

0.8.1

2 years ago

0.8.0

2 years ago

0.8.3

2 years ago

0.8.2

2 years ago

0.6.2

2 years ago

0.6.5

2 years ago

0.6.4

2 years ago

0.5.0-rc1

2 years ago

0.7.0-rc1

2 years ago

0.5.2-rc1

2 years ago

0.5.3-rc1

2 years ago

0.5.4-rc1

2 years ago

0.3.0

2 years ago

0.3.1

2 years ago

0.4.0-rc3

2 years ago

0.4.0-rc2

2 years ago

0.4.0-rc1

2 years ago

0.4.0

2 years ago

0.4.2

2 years ago

0.2.1

2 years ago

0.2.0

2 years ago

0.1.2

2 years ago

0.1.1

2 years ago