Skip to content

Latest commit

 

History

History
47 lines (36 loc) · 803 Bytes

readme.md

File metadata and controls

47 lines (36 loc) · 803 Bytes

Writing a contract

mchain contains a mvm which enables users can create an execute the various programs in blockchain system.

class MyFirstContract {
  def _ctor() {
  
  }
  
  def giveMeMoney() {
    Chain.transfer(tx.sender, 1.0);
  }
}

Predefined methods

tx.sender
tx.value

Chain.transfer

Deploy a contract

var program = "BASE64_ENCODED_PROGRAM";
var ctorSignature = "ContractName::_ctor";

var tx = node.wallet.CreateDeployTransaction(program, ctorSignature);
node.SendTransaction(tx);

var contractAddress = tx.receiverAddr;

Execute

var methodSignature = "ContractName::MethodName";
var args = new object[] { 2, 3 };

var tx = node.wallet.CreateCallTransaction(contractAddress, methodSignature, args);
node.SendTransaction(tx);