1

I tested both signing payment and signature verification that is implemented by JavaScript and EthereumJS here:

And both of them (signing and verification) properly work, meaning that I am sure the signature is verified successfully in off-chain part by EthereumJS. I signed the payment as follows:

signPayment('0x5A375e7eb3763261BfB74bc53c49B754887b0dc2', 10, function(err, something) {}); 
//signature= 0x0fd0ceca10baada793b3103bcc7ba7523ec8fc79aa070bc8fe9301fc72c0c8424804b3064095a201af464a35483ce55c4aee1fe56aebf0f99bb31b682679b21a1c

Then, I deployed the Solidity contract as follows:

const thisContract = new web3.eth.Contract(abi);

    thisContract.deploy({  

            data: bytecode,

            arguments: [ "0x84f0c8fC2F6bc8394EB77BaAAe89cB6e12C048C2", 2592000]

        }).send({

           from: "0x3455D7167A2EE2d660EE85F8e90C6b3B1cCB7163",

           gas: 5000000 ,

           gasPrice: '3000000000',

           value: 5000 

        },

        function(error, transactionHash) {

            console.log(error);

            console.log(transactionHash);

            console.log('function exec');

        }).then(function(newContractInstance) {

        console.log('Contract Instance:' + newContractInstance.options.address);

    });

And the result is as follows:

> web3.eth.personal.unlockAccount('0x3455D7167A2EE2d660EE85F8e90C6b3B1cCB7163', 'logic')
Promise {
  <pending>,
  domain: 
   Domain {
     domain: null,
     _events: 
      { removeListener: [Function: updateExceptionCapture],
        newListener: [Function: updateExceptionCapture],
        error: [Function: debugDomainError] },
     _eventsCount: 3,
     _maxListeners: undefined,
     members: [] } }
> 
> const thisContract = new web3.eth.Contract(abi);
undefined
> 
> thisContract.deploy({  
... 
...         data: bytecode,
... 
...         arguments: [ "0x84f0c8fC2F6bc8394EB77BaAAe89cB6e12C048C2", 2592000]
... 
...     }).send({
... 
...        from: "0x3455D7167A2EE2d660EE85F8e90C6b3B1cCB7163",
... 
...        gas: 5000000 ,
... 
...        gasPrice: '3000000000',
... 
...        value: 5000 
... 
...     },
... 
...     function(error, transactionHash) {
... 
...         console.log(error);
... 
...         console.log(transactionHash);
... 
...         console.log('function exec');
... 
...     }).then(function(newContractInstance) {
... 
...     console.log('Contract Instance:' + newContractInstance.options.address);
... 
... });
Promise {
  <pending>,
  domain: 
   Domain {
     domain: null,
     _events: 
      { removeListener: [Function: updateExceptionCapture],
        newListener: [Function: updateExceptionCapture],
        error: [Function: debugDomainError] },
     _eventsCount: 3,
     _maxListeners: undefined,
     members: [] } }
> null
0x31ae8f166914576293258855f248926e60f7d5b75f1bc6514b1cc6375f9e0071
function exec
Contract Instance:0x5A375e7eb3763261BfB74bc53c49B754887b0dc2

So, the payer address is 0x3455D7167A2EE2d660EE85F8e90C6b3B1cCB7163 and its balance is 19994680471999980000 as follows:

> web3.eth.getBalance('0x3455D7167A2EE2d660EE85F8e90C6b3B1cCB7163').then(console.log)
Promise {
  <pending>,
  domain: 
   Domain {
     domain: null,
     _events: 
      { removeListener: [Function: updateExceptionCapture],
        newListener: [Function: updateExceptionCapture],
        error: [Function: debugDomainError] },
     _eventsCount: 3,
     _maxListeners: undefined,
     members: [] } }
> 19994680471999980000

And the contract address is 0x5A375e7eb3763261BfB74bc53c49B754887b0dc2. And when I get contract balance, it is = 5000 wei as follows :

> web3.eth.getBalance('0x5A375e7eb3763261BfB74bc53c49B754887b0dc2').then(console.log)
Promise {
  <pending>,
  domain: 
   Domain {
     domain: null,
     _events: 
      { removeListener: [Function: updateExceptionCapture],
        newListener: [Function: updateExceptionCapture],
        error: [Function: debugDomainError] },
     _eventsCount: 3,
     _maxListeners: undefined,
     members: [] } }
> 5000

Also the recipient address is 0x84f0c8fC2F6bc8394EB77BaAAe89cB6e12C048C2 and its balance is zero as follows:

> web3.eth.getBalance('0x84f0c8fC2F6bc8394EB77BaAAe89cB6e12C048C2').then(console.log)
Promise {
  <pending>,
  domain: 
   Domain {
     domain: null,
     _events: 
      { removeListener: [Function: updateExceptionCapture],
        newListener: [Function: updateExceptionCapture],
        error: [Function: debugDomainError] },
     _eventsCount: 3,
     _maxListeners: undefined,
     members: [] } }
> 0

Till now, everything is OK. Now, I expect when I close the channel by recipient address (0x84f0c8fC2F6bc8394EB77BaAAe89cB6e12C048C2), its balance changes from 0 to 10 wei.

However, when I invoke the function close, apparently it is done as follows:

> var contractInstance = new web3.eth.Contract(abi, '0x3455D7167A2EE2d660EE85F8e90C6b3B1cCB7163');
undefined

> contractInstance.methods.close(10, "0x0fd0ceca10baada793b3103bcc7ba7523ec8fc79aa070bc8fe9301fc72c0c8424804b3064095a201af464a35483ce55c4aee1fe56aebf0f99bb31b682679b21a1c").send({ from: '0x84f0c8fC2F6bc8394EB77BaAAe89cB6e12C048C2' }, function(error, result) {
... 
...     console.log(error);
... 
...     console.log(result)
... 
... });
Promise {
  <pending>,
  domain: 
   Domain {
     domain: null,
     _events: 
      { removeListener: [Function: updateExceptionCapture],
        newListener: [Function: updateExceptionCapture],
        error: [Function: debugDomainError] },
     _eventsCount: 3,
     _maxListeners: undefined,
     members: [] },
  _events: undefined,
  emit: [Function: emit],
  on: [Function: on],
  once: [Function: once],
  off: [Function: removeListener],
  listeners: [Function: listeners],
  addListener: [Function: on],
  removeListener: [Function: removeListener],
  removeAllListeners: [Function: removeAllListeners] }
> null
0x233a560fc4553ddb2155e9f7fba9830353530f86d5146efff417739703700525
(node:4688) UnhandledPromiseRejectionWarning: Error: Transaction ran out of gas. Please provide more gas:
{
  "blockHash": "0xb170db055aba65c0b3756bac19f4c29684e6d654575295beeba5de77649b064e",
  "blockNumber": 5523048,
  "contractAddress": null,
  "cumulativeGasUsed": 51428,
  "gasUsed": 26392,
  "logsBloom": "0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
  "root": null,
  "status": false,
  "transactionHash": "0x233a560fc4553ddb2155e9f7fba9830353530f86d5146efff417739703700525",
  "transactionIndex": 1,
  "events": {}
}
    at /home/s/node_modules/web3-core-method/src/index.js:370:33
    at <anonymous>
    at process._tickCallback (internal/process/next_tick.js:182:7)
(node:4688) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1)
(node:4688) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

And here is the transaction information in Tobalaba Etherscan :

https://tobalaba.etherscan.com/tx/0x233a560fc4553ddb2155e9f7fba9830353530f86d5146efff417739703700525

However, when I get the recipient balance, it is still zero :

> web3.eth.getBalance('0x84f0c8fC2F6bc8394EB77BaAAe89cB6e12C048C2').then(console.log)
Promise {
  <pending>,
  domain: 
   Domain {
     domain: null,
     _events: 
      { removeListener: [Function: updateExceptionCapture],
        newListener: [Function: updateExceptionCapture],
        error: [Function: debugDomainError] },
     _eventsCount: 3,
     _maxListeners: undefined,
     members: [] } }
> 0

What is missing to make a "successful" payment between "payer" and "recipient" ?

Note: As you can see in the output of the transaction, it is written that

(node:4688) UnhandledPromiseRejectionWarning: Error: Transaction ran out of gas. Please provide more gas:

Can it cause this problem ? And if so, how can I increase the gas at the time of invoking contractInstance.methods.close ?

Also, I am not sure about this line:

var contractInstance = new web3.eth.Contract(abi, '0x3455D7167A2EE2d660EE85F8e90C6b3B1cCB7163');

that it must be :

var contractInstance = new web3.eth.Contract(abi, '<contract deployer address  = payer address>');

Or:

var contractInstance = new web3.eth.Contract(abi, '<contract address>');

Which one is correct ?

And also it's not because using Tobalaba blockchain ? (that is base on Ethereum)

Note: Also I tested it by a version in which function close does not verify the signature, however the result is the same.

And alternatively, is there other test blockchain like Tobalaba blockchain based on Ethereum (and also free) to test this contract ? since maybe the problem is related to this Ethereum based blockchain. I am not sure.

  • 1
    It should be new web3.eth.Contract(abi, '<contract address>');. – user19510 Jul 12 '18 at 15:33
  • 1
    Ropsten, Rinkeby, and Kovan are the standard Ethereum test networks. You can also test locally with ganache. – user19510 Jul 12 '18 at 15:33
  • @smarx Thank you, Do you mean testRPC = ganache ? If so do you mean I need to deploy contract using remix ? Thanks – Questioner Jul 12 '18 at 15:36
  • 1
    Yes, ganache is the new name for what used to be called testrpc. Whether you deploy with Remix or code (as you've done here) has nothing to do with whether you're using Ropsten, ganache, or anything else. – user19510 Jul 12 '18 at 15:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.