1

I've been looking for up to date examples of deploying a smart contract on a tezos sandbox for a while now. Does anyone know of any good references? I'm using python/pytezos.

1 Answer 1

1

Once did something like that

import os
import sys
import time

import click
from dotenv import load_dotenv
from pytezos import ContractInterface, pytezos

load_dotenv()

key = os.environ.get("PRIVATE_KEY")
network = os.environ.get("NETWORK")

contract = ContractInterface.from_file("./my_contract.tz")
ci = contract.using(shell=network, key=key)


def waitForBaking(opHash):
    while 1:
        try:
            res = ci.shell.blocks[-5:].find_operation(opHash)
            return res
        except StopIteration:
            continue
        except pytezos.rpc.node.RpcError:
            time.sleep(5)
            continue
        except Exception as e:
            print(e)


try:
    if click.confirm(
        "Do you really want to deploy the contract on %s?" % network.upper(),
        default=False,
    ):
        op = ci.originate().autofill().sign().inject(_async=False)
        bakingRes = waitForBaking(op["hash"])
        addr = bakingRes["contents"][0]["metadata"]["operation_result"][
            "originated_contracts"
        ][0]
        print(addr)
    else:
       print("Aborted.\n")
except Exception as e:
    print(e)

half stolen from chinstrap https://github.com/ant4g0nist/chinstrap

Also the Pytezos Documentation is updated now and should help https://pytezos.org/contents.html

From Slack Discussion

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.