> For the complete documentation index, see [llms.txt](https://docs.dartez.io/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.dartez.io/dartez/contracts.md).

# Contracts

### Deploy A Contract

Using contract deployment function a user can directly write smart contracts in Michelson language and deploy it on Tezos chain using this method, in return you'll get an operation group id of the deployed contract that can be use to track the contract on chain.

```dart
var server = '';

var contract = """parameter string;
    storage string;
    code { DUP;
        DIP { CDR ; NIL string ; SWAP ; CONS } ;
        CAR ; CONS ;
        CONCAT;
        NIL operation; PAIR}""";

var storage = '"Sample"';

var keyStore = KeyStoreModel(
      publicKey: 'edpk.....rrj',
      secretKey: 'edsk.....yHH',
      publicKeyHash: 'tz1.....hxy',
    );

var signer = await Dartez.createSigner(
        Dartez.writeKeyWithHint(keyStore.secretKey, 'edsk'));

var result = await Dartez.sendContractOriginationOperation(
      server,
      signer,
      keyStore,
      0,
      '',
      100000,
      1000,
      100000,
      contract,
      storage,
      codeFormat: TezosParameterFormat.Michelson,
    );

print("Operation groupID ===> $result['operationGroupID']");

```

Check [example](https://github.com/Tezsure/Dartez/blob/95027464a44eb65fd0f51d978a18570dafc9b3b2/example/lib/main.dart#L199).

### Call A Contract

To invoke a deployed contract use this method, in return you'll get an operation group id of the invoked contract which can be used to track the contracts on chain.

```dart
var server = '';

var keyStore = KeyStoreModel(
      publicKey: 'edpk.....rrj',
      secretKey: 'edsk.....yHH',
      publicKeyHash: 'tz1.....hxy',
    );

var signer = await Dartez.createSigner(
        Dartez.writeKeyWithHint(keyStore.secretKey, 'edsk'));

var contractAddress = ['KT1.....xMY'];

var resultInvoke = await Dartez.sendContractInvocationOperation(
        server,
        signer,
        keyStore,
        contractAddress,
        [10000],
        100000,
        1000,
        100000,
        [''],
        ["Cryptonomicon"],  
        codeFormat: TezosParameterFormat.Michelson);

print("Operation groupID ===> $resultInvoke['operationGroupID']");

```

### Pre Apply Contract Invocation Operation

Before injecting an operation to the blockchain, the operation needs to be validated to check for any errors.

```dart
var server = '';

var keyStore = KeyStoreModel(
      publicKeyHash: 'tz1U.....W5MHgi',
      secretKey: 'edskRp......bL2B6g',
      publicKey: 'edpktt.....U1gYJu2',
    );

var signer = await Dartez.createSigner(
        Dartez.writeKeyWithHint(keyStore.secretKey, 'edsk'));

var contract = ["KT1...fgH"];

var parameters = ["parameters"];


var opPair = Dartez.preapplyContractInvocationOperation(server, signer, keyStore, contract, [0], 120000, 1000, 100000, ['transfer'], parameters);
```

### Inject Operation

This method inject the operation on to the blockchain and returns the operation group id which can be used to track the operation status on chain.

```dart
var server = '';

var keyStore = KeyStoreModel(
      publicKeyHash: 'tz1U.....W5MHgi',
      secretKey: 'edskRp......bL2B6g',
      publicKey: 'edpktt.....U1gYJu2',
    );

var signer = await Dartez.createSigner(
        Dartez.writeKeyWithHint(keyStore.secretKey, 'edsk'));

var contract = ["KT1...fgH"];

var parameters = ["parameters"];

var opPair = Dartez.preapplyContractInvocationOperation(server, signer, keyStore, contract, [0], 120000, 1000, 100000, ['transfer'], parameters);

var opHash = await Dartez.injectOperation(server, opPair);
```

### Get Operation Status

Get's the current status of an operation on the blockchain.

```dart
var server = '';
var opHash = '';

var status = await Dartez.getOperationStatus(server, opHash);
```

### Sign Payload

This function is sued for signing a byte formatted payload and returns base58 signature signed payload using account secret key.

```dart

var signer = Dartez.createSigner(Dartez.writeKeyWithHint('$secretKey', 'edsk'));

var payload = "03...";

String base58signature = Dartez.signPayload(signer: signer, payload: payload);
```

### Get Block

This function will return the current block of tezos blockchain.

```dart
var server = '';

var block = await Dartez.getBlock(server);
```

### Get Contract Storage&#x20;

This function is used for reading a contract storage and returns the micheline json storage.

```dart
var server = '';

var accountHash = 'KT1.....F221';

var storage = await Dartez.getContractStorage(server, accountHash);
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.dartez.io/dartez/contracts.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
