vechain / connex

The mono-repo contains libraries to help build dApps for VeChain.
https://docs.vechain.org/developer-resources/sdks-and-providers/connex
GNU Lesser General Public License v3.0
86 stars 3.58k forks source link

Connex Vendor does not work properly #113

Closed davidlee-crastonic closed 2 years ago

davidlee-crastonic commented 2 years ago

I am now using connex to sign transfer with node.js, but it fails with following error.

(node:6432) UnhandledPromiseRejectionWarning: TypeError: connex.vendor.sign(...).signer(...).gas(...).link(...).comment(...).then is not a function
    at VechainLogic.<anonymous> (D:\Worksite\dvst\dvst-web3\build\chains\Vechain.js:203:42)
    at step (D:\Worksite\dvst\dvst-web3\build\chains\Vechain.js:63:23)
    at Object.next (D:\Worksite\dvst\dvst-web3\build\chains\Vechain.js:44:53)
    at fulfilled (D:\Worksite\dvst\dvst-web3\build\chains\Vechain.js:35:58)
    at processTicksAndRejections (internal/process/task_queues.js:95:5)
(Use `node --trace-warnings ...` to show where the warning was created)
(node:6432) 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(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 1)
(node:6432) [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.

I just followed this instruction: #https://docs.vechain.org/connex/api.html#transaction-signing-service Hope to know how to proceed in this case.

libotony commented 2 years ago

The example was wrong in the doc, it should be connex.vendor.sign(...).signer(...).gas(...).link(...).comment(...).request().then, I will update the doc ASAP.

davidlee-crastonic commented 2 years ago

Thank you very much

davidlee-crastonic commented 2 years ago

And the mechanism to sign transaction is not so clear in the doc. For example, how to customize transferABI aand transferMethod in the doc const transferABI = {"constant":false,"inputs":[{"name":"_to","type":"address"},

{"name":"_amount","type":"uint256"}],"name":"transfer","outputs":[{"name":"success","type":"bool"}],"payable":false,"stateMutability":"nonpayable","type":"function"}
const transferMethod = connex.thor.account('0x0000000000000000000000000000456E65726779').method(transferABI)
// Connex author's address and amount in wei
const energyClause = transferMethod.asClause('0xd3ae78222beadb038203be21ed5ce7c9b1bff602', '1000000000000000000000')

connex.vendor.sign('tx', [
    {
        to: '0xd3ae78222beadb038203be21ed5ce7c9b1bff602',
        value: '100000000000000000000',
        data: '0x',
        comment: 'Transfer 100 VET'
    },
    {
        comment: 'Transfer 1000 VeThor',
        ...energyClause
    }
])

Then how is the private key used for signing? Isn't it neccessary?

libotony commented 2 years ago

ABI is given by the solidity compiler.

libotony commented 2 years ago

Private key management is done by simple wallet from connex-driver in your environment

davidlee-crastonic commented 2 years ago

got it But the document for creating and sending transaction is not changed yet. When will it be ready for use?

davidlee-crastonic commented 2 years ago

Or could you please leave here some simple instruction how to create and sign transfer?

libotony commented 2 years ago

Doc is updated, for your case add .request() before .then.

davidlee-crastonic commented 2 years ago

ok, I will try it. Would you please tell me what is the address in this part? const transferMethod = connex.thor.account('0x0000000000000000000000000000456E65726779').method(transferABI)

libotony commented 2 years ago

https://docs.vechain.org/connex/api.html#account-visitor, documented here the address in account(address) is the contract's address, here I used VTHO contract for example.

davidlee-crastonic commented 2 years ago

So you mean if I want to transfer VET, I have to use another address?

libotony commented 2 years ago

No, transfer VET just needs add a clause {to: <address>, value: <value>}

libotony commented 2 years ago
connex.vendor.sign('tx', [
    {
        to: '0xd3ae78222beadb038203be21ed5ce7c9b1bff602',
        value: '100000000000000000000',
        data: '0x',
        comment: 'Transfer 100 VET'
    }
])
davidlee-crastonic commented 2 years ago

Thanks Then How can I export private key from Sync2 wallet? I can not find it anywhere

libotony commented 2 years ago

Sync2 does not support exporting the private key, but you can do it with thor-devkit with your mnemonic words.

davidlee-crastonic commented 2 years ago

Thank you very much.