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.

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.

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.

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.

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.

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.

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.


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.

var server = '';

var block = await Dartez.getBlock(server);

Get Contract Storage

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

var server = '';

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

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

Last updated