合约类

部署合约

Node.JS Example

var Remote = require('jingtum-lib').Remote;
var remote = new Remote({server: 'ws://ts5.jingtum.com:5020', local_sign:true});
remote.connect(function (err, result) {
        if(err) return console.log('err: ', err);
        var options = {account: 'jHb9...tyTh', amount: 10,payload:utils.stringToHex('result={}; function Init(t) result=scGetAccountBalance(t) return result end; function foo(t) result=scGetAccountBalance(t) return result end'),params: ['jHb9...tyTh']};
        var tx = remote.deployContractTx(options);
        tx.setSecret('sn37...jXUWd');

        tx.submit(function(err, result) {
                if(err) {return console.log('err:', err);}
                console.log('get the latest ledger:', result);
        });
});

C# Example

var remote = new Remote(@"ws://ts5.jingtum.com:5020", true);
remote.Connect(result =>
{
  if (result.Exception != null)
  {
  Console.Write(result.Exception.Message);
  }
  else
  {
    var tx = remote.DeployContractTx(new DeployContractTxOptions
    {
      Account = "j9FGhAW9dSzL3RjbXkyW6Z6bHGxFk8cmB1",
      Amount = 30,
      Payload = "result={}; function Init(t) result=scGetAccountInfo(t) return result end; function foo(t) a={} result=scGetAccountInfo(t) return result end;",
      Params = new string[] {"j9FGhAW9dSzL3RjbXkyW6Z6bHGxFK8cmB1"}
    });
    tx.SetSecret("ssG......dNi");
    tx.Submit(txResult => {
      Console.Write(txResult.Message);
      // get result from txResult.Result
      // 部署的合约地址在ContractState中
    });
  }
});

执行合约

Node.JS Example

var Remote = require('jingtum-lib').Remote;
var remote = new Remote({server: 'ws://ts5.jingtum.com:5020', local_sign:true});
remote.connect(function (err, result) {
        if(err) return console.log('err: ', err);
        var options = {account: 'jHb9...tyTh', destination: 'j4YVQxC...yPRnHwei', foo: 'foo',params: ['jHb9...tyTh']};
        var tx = remote.callContractTx(options);
        tx.setSecret('sn37...jxUWd');
        tx.submit(function(err, result) {
                if(err) {return console.log('err:',err);}
                console.log('get the latest ledger:', result);
        });
});

C# Example

var remote = new Remote(@"ws://ts5.jingtum.com:5020", true);
remote.Connect(result =>
{
  if (result.Exception != null)
  {
    Console.Write(result.Exception.Message);
  }
  else
  {
    var tx = remote.CallContractTx(new CallContractTxOptions
    {
      Account = "j9FGhAW9dSzL3RjbXkyW6Z6bHGxFk8cmB1",
      Destination = "jaVDaozkmFzCGwuBYL5wQ3SvhnUrySuofn",
      Foo = "foo",
      Params = new string[] {"j9FGhAW9dSzL3RjbXkyW6Z6bHGxFk8cmB1"}
    });
    tx.SetSecret("ssGkkAMnKCBkhGVQd9CNzSQv5zdNi");
    tx.Submit(txResult => {
      Console.Write(txResult.Message);
      // get result from txResult.Result
      // 执行结果在ContractState中
    });
  }
});