sendTransaction: Sends a Transaction

Sending of a transaction.

API Cloud Block Chain**

Processing Sequence

The transaction send sequence is as follows.

The difference from the constant method invocation is that the end user's signature is included as the first parameter when calling the final SomeContract.

We use this signature to verify the input values and obtain the end user's address.

Send Transaction

  • 1 AltExecCnsContract#sendTransaaction

AltExecCnsContract is called from the client side logic.

When calling, parameters are passed including the "name", "function name", "parameter", etc. of the contract to be ultimately called.

  • 1.1 API POST transaction

    The client module provided by this service signs the hash value derived from all the arguments and does a POST request to the API.

  • 1.1.1 ContractNameService#getLatestcontract

    The API server queries the CNS for the address of the latest version of the Contract.

  • 1.1.2 SomeContract#someMethod

    The API server calls the contract as instructed by the end user.
    At the time of the call, we give the signature of the end user as the first parameter.

Implementation by the service provider

  • ClientSide

    • AltExecCnsContract#sendTransaction

      var contract = new AltExecCnsContract(account, '__CNS_ADDRESS__');
      contract.sendTransaction('__PASSWORD__', 'SomeContract', 'someMethod', ['p0', 1, 'p2'], abi, function(err, res) {
          if (err) console.error(err);
          else console.log(res.join(','));
  • Contract

    • SomeContract

      contract SomeContract is VersionContract  {
          mapping(address => bool) allowUsers;
          function SomeContract(ContractNameService _cns) VersionContract(_cns, "SomeContract") {}
          function someMethod(
                  bytes _sign, 
                  bytes32 _p0, 
                  uint _p1, 
                  bytes32 _p2) {
              // create all parameters hash
              bytes32 hash = calcEnvHash('someMethod');
              hash = sha3(hash, _p0);
              hash = sha3(hash, _p1);
              hash = sha3(hash, _p2);
              // get end user's addresss
              address endUserAddr = Utils.recoverAddress(hash, _sign);
              if (!allowUsers[endUserAddr]) throw;
              // do something

      For details of the signature verification within the contract, please see here.


  • msg.sender

    The invocation of the contract transaction is done with the signature of the account for payment.

    "msg.sender" is an account designated to each service provider for payment and is not the end user.

    The signature of the end user is passed as the first argument, bytes _sign, from which we verify the signature and get the address of the end user.

  • Simplified implementation

    In the example above, we are implementing logic directly in SomeContract for clarity, but in fact it is necessary to implement it separately as in basic contract configuration.

    For details on how to implement the original Contract, refer to the following sources.

results matching ""

    No results matching ""