Deploying your first Contract
If you are running a Standalone node or are setting up a new channel the first thing you will need to do is deploy your contract. If you have not already written and compiled a contract to deploy first read the section on building a Smart Contract.
Deploying a contract just means submitting a deploy transaction with the contract payload as the data. This can be done easily by using the m8 CLI.
Using m8
m8 is a command line tool that lets you interact with Mazzaroth nodes.
Visit the repo to find latest releases or install instructions.
Configuring m8
The m8
CLI uses your local account keys to sign transactions
that are sent to Mazzaroth nodes. So to start using the CLI you
must first set up a config file that contains your account info.
You can easily get started by running the init command:
m8 init cfg
It will first access for the location to store the m8 config, defaulting to your Users directory.
It will ask you if you want to generate a key pair. If this is your
first time using Mazzaroth and you do not have an account you can have
m8 generate a private and public key for you to use at this time.
Otherwise select no
and enter your existing keys you want to use.
The last thing thing it will ask is if you want to setup a channel.
This is where you can set the address of a remote or local node along with
the channel id and a channel alias for targeting a node with transactions.
If you are testing against a local standalone node you should add a channel
with the address http://localhost:6299
and
channel id: 0000000000000000000000000000000000000000000000000000000000000000
.
Writing a Deploy Manifest
Using m8, the command to deploy a contract is:
m8 channel exec deployment --deployment-manifest deployment.yaml
Where deployment.yaml
is the path to a manifest file containing the deployment
configuration for the contract. An example deployment.yaml can be found
here.
A basic deployment yaml should look like this:
version: 0.0.1
type: deployment
channel:
version: 0.0.1
id: 0000000000000000000000000000000000000000000000000000000000000000
owner: 0000000000000000000000000000000000000000000000000000000000000000
contract-file: "samplecontract.wasm"
abi-file: "samplecontract.json"
gateway-node:
address: https://localhost:6299
deploy:
name: sample-contract
The first version is the version of the deployment file itself. There are two
types of config files that m8
accepts (test and deployment) so for
this you should specify deployment
.
The channel provides all the fields configuring your channel including:
- version - The version of the channel which should be incremented for new deployments.
- id - The id of the channel which may be all 0s for testing purposes.
- owner - The public key id of the owner of the channel.
- contract-file - The path to the compiled Wasm contract file.
- abi-file - The path to the compiled json ABI.
The gateway-node address is the url of the Mazzaroth node to target for deployment, which can be a locally running node.
The deploy section gives a name to the contract and can optionally be used to provide a list of transactions to execute following the dpeloyment. See m8 examples for and example on how this works.