input-output-hk / cardano-sl

Cryptographic currency implementing Ouroboros PoS protocol
Apache License 2.0
3.77k stars 630 forks source link

How to create new address with the v0 api?v1 api doesn't work! #2844

Open lhfly5201314 opened 6 years ago

lhfly5201314 commented 6 years ago

Hi,guys!I have tried to create wallet and addresses with the v1 api,but failed! I found the returned api version is v0 when I request to the cardano node. So i switched to the v0 api.I created the wallet with following the v0 api instructions. But the part about the creating addresses is not very clear,I tried some times.all failed! Could some guys give some curl examples about creating the new addresess with v0 api?? Thanks!

lhfly5201314 commented 6 years ago

The addtional: When I run the command " curl -k -X POST https://127.0.0.1:8090/api/addresses -H "Content-Type: application/json;charset=utf-8" -d '{"CAccountId":"Ae2tdPwUPEZ18ZjTLnLVr9CEvUEUX4eW1LBHbxxxJgxdAYHrDeSCSbCxrvx@2329733709"}' " for creating an address,it only returns the error: " Error in $: expected Text, encountered Object ",

what's wrong with the curl command?

KtorZ commented 6 years ago

Hey! Could you elaborate on why or how v1 failed?

Also:

lhfly5201314 commented 6 years ago

@KtorZ Hi,friend! I followed these instructions to run a Cardano node successfully: https://github.com/input-output-hk/cardano-sl/blob/develop/docs/how-to/build-cardano-sl-and-daedalus-from-source-code.md 1 (I used Nix build mode only) https://github.com/input-output-hk/cardano-sl/blob/develop/docs/how-to/connect-to-cluster.md 2 (I used ./connect-to-mainnet to run the node)

but when I tried to run $ curl --cacert /home/shunfan/cardano-sl/scripts/tls-files/ca.crt https://localhost:8090/api/settings/sync/progress in my console,it returned the below error curl: (60) server certificate verification failed. CAfile: /home/shunfan/cardano-sl/scripts/tls-files/ca.crt CRLfile: none More details here: http://curl.haxx.se/docs/sslcerts.html

curl performs SSL certificate verification by default, using a "bundle" of Certificate Authority (CA) public keys (CA certs). If the default bundle file isn't adequate, you can specify an alternate file using the --cacert option. If this HTTPS server uses a certificate signed by a CA represented in the bundle, the certificate verification probably failed due to a problem with the certificate (it might be expired, or the name might not match the domain name in the URL). If you'd like to turn off curl's verification of the certificate, use the -k (or --insecure) option.

So,I googled it and found some other guys have met the some issue. So I add -k in the curl command to disable the tls,but the v1 creating new wallet command is still not working,so I tried the curl -k https://localhost:8090/api/info, some info was returned: {"Right":{"cabalVersion":"1.1.1","apiVersion":"v0","gitRevision":"aed0d925b06e0bd1278e26539c445274c52f4b67","softwareVersion":"cardano-sl: 0"}} It shows the apiVersion:v0 cardano-sl:0. Is there something wrong,why is the cardano-sl 0?? But when I run ./cardano-node --version the below was returned: cardano-node-1.1.1, git revision aed0d925b06e0bd1278e26539c445274c52f4b67 the cardano-node version is 1.1.1. My OS is Ubuntu16.04.Thanks!

lhfly5201314 commented 6 years ago

Could anyone paste the curl command about creating new addresses with v0 api using the link:https://cardanodocs.com/technical/wallet/api/v0/#tag/V0-(Deprecated)%2Fpaths%2F~1api~1addresses%2Fpost I tried many combinations ,all failed. The doc is so confusing!Thanks!

KtorZ commented 6 years ago

From the error above, I believe the node uses a different CA certificate chain than the one you've provided via --cacert. Depending on how you choose to start your node, certificates might have been generated on-the-fly in a state-*** folder in your cardano-sl root folder. What's in scripts/tls-files/* are development certificates and shouldn't be used whatsoever.

For manual testing and to play around with the node on your local machine, it's acceptable to stick with -k option (which doesn't disable TLS but simply doesn't check the validity of the CA chain of the server you're talking to. Data are still encrypted, but you simply have no way to ensure that the server is really who is said it is).

Note that V0 is now deprecated. The documentation from V1 is accessible via the link below and is much more provided with details and informations, alongside getting regular updates. Please rely on that for your next tries :)

https://cardanodocs.com/technical/wallet/api/v1/

lhfly5201314 commented 6 years ago

@KtorZ Hi,friend!Really appreciate your reply!Did u succeed in using the v1 api?

I launch the node using the ./connect-to-mainnet script,the script file is a link to a file in /unix/store/directory,the below is the full script:

!/nix/store/flb9ar1xdd13c606aa4my9miy3iv4vyk-bash-4.4-p12/bin/bash

if [[ "$1" == "--delete-state" ]]; then echo "Deleting state-wallet-mainnet ... " rm -Rf state-wallet-mainnet fi

echo "Keeping state in state-wallet-mainnet" mkdir -p state-wallet-mainnet/logs

echo "Launching a node connected to 'mainnet' ..." if [ ! -d state-wallet-mainnet/tls ]; then mkdir state-wallet-mainnet/tls/ /nix/store/jn350na5wcshwsixpq1wbskdp7r3x0r3-openssl-1.0.2l-bin/bin/openssl req -x509 -newkey rsa:2048 -keyout state-wallet-mainnet/tls/server.key -out state-wallet-mainnet/tls/server.cert -days 3650 -nodes -subj "/CN=localhost" fi

/nix/store/l571fjfxnqaa61a5mvdmw8dgxaylpq2h-cardano-sl-wallet-1.1.1/bin/cardano-node \ --no-ntp \ --node-id 127.0.0.1 \ --configuration-file /nix/store/39p2dbldbxzhk4278b0rkhg417bgcrzk-cardano-config/configuration.yaml \ --configuration-key mainnet_full \ --web \ --tlscert state-wallet-mainnet/tls/server.cert \ --tlskey state-wallet-mainnet/tls/server.key \ --tlsca state-wallet-mainnet/tls/server.cert \ --log-config /nix/store/39p2dbldbxzhk4278b0rkhg417bgcrzk-cardano-config/log-config-connect-to-cluster.yaml \ --topology "/nix/store/39p2dbldbxzhk4278b0rkhg417bgcrzk-cardano-config/topology.yaml" \ --logs-prefix "state-wallet-mainnet/logs" \ --db-path "state-wallet-mainnet/db" \ --wallet-db-path 'state-wallet-mainnet/wallet-db' \ --keyfile state-wallet-mainnet/secret.key \ --wallet-address 127.0.0.1:8090 \ --ekg-server 127.0.0.1:8000 --metrics +RTS -T -RTS

Sure,there is a server.cert in the cardano-sl/state-wallet-mainnet/tls directory(in cardano-sl root folder),and I replace the original ca path using this file,but nothing return,even no error log,,,the below is the curl command for creating a new adddress:

curl -X POST https://localhost:8090/api/v1/wallets -H "Content-Type: application/json;charset=utf-8" -H "Accept: application/json; charset=utf-8" --cacert ./state-wallet-mainnet/tls/server.cert -d '{ "operation": "create", "backupPhrase": ["squirrel", "material", "silly", "twice", "direct", "slush", "pistol", "razor", "become", "junk", "kingdom", "flee"], "assuranceLevel": "normal", "name":"MyFirstWallet" }'

the curl command "curl -X GET https://localhost:8090/api/v1/wallets -H "Accept: application/json; charset=utf-8" --cacert ./state-wallet-mainnet/tls/server.cert" doesn't work neither,nothing return. The path ./state-wallet-mainnet/tls-server.cert no error like ./script/tls-files/ca.cert,so the ca is ok now,but why still nothing return?

Is there something wrong in my connect-to-mainnet script???The options behind the cardano-node are incorrect???

what's more,I build the cardano-node with the nix?Is that ok??

Thanks again!

KtorZ commented 6 years ago

Could you please give me the output of the GET command with the -v option (verbose mode) turned on:

curl -v -X GET -H "Accept: application/json; charset=utf-8" --cacert ./state-wallet-mainnet/tls/server.cert https://localhost:8090/api/v1/wallets 
lhfly5201314 commented 6 years ago

Sure!The below is the full output of your command! Note: Unnecessary use of -X or --request, GET is already inferred. % Total % Received % Xferd Average Speed Time Time Time Current Dload Upload Total Spent Left Speed

0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0* Trying 127.0.0.1...

Thanks,friend!

nbrown1337 commented 6 years ago

Would like to add that I am also getting 404 errors on curl API requests. On Ubuntu 16, have daedalus wallet and cardano node running just fine. My certificates are working properly, I just get 404 error on curl. Seems like api works on daedalus wallet but not curl? I need it to work because I would like to develop a node wallet service for ADA. Thanks for future help!

Example POST newWallet: * upload completely sent off: 427 out of 427 bytes < HTTP/1.1 404 Not Found < Transfer-Encoding: chunked

Looks like the V0 API works, like GET https://localhost:8090/api/wallets instead of ../api/v1/wallets

KtorZ commented 6 years ago

This is weird and I am not even able to reproduce. As far as I can tell there's nothing wrong with cURL whatsoever.

$ curl -k https://localhost:8090/api/v1/wallets | json_pp
{
   "meta" : {
      "pagination" : {
         "perPage" : 10,
         "totalEntries" : 0,
         "page" : 1,
         "totalPages" : 1
      }
   },
   "data" : [],
   "status" : "success"
}

I am a bit clueless for I can't see any obvious defect in the examples you provided above. Perhaps @nbrown1337 can you provide a bit more context (commit ref, exact cURL command, how did you build and run your node) ?

BlueStalker commented 6 years ago

I run Daedalus (https://daedaluswallet.io/#download )by downloading it directly. And Everything in Daedalus looks good. But I think I got the almost exactly the same problem as above.

  1. the v1 is not in the api path, note the above version is version 1.1.1.952, does it still running like old version of api? And I can not see v0 too.
  2. What runs ok to me, is the /api/wallets which give me the wallet information I just created from the Daelalus app on mac.
  3. But /api/addresses gives me 405, /api/v1/wallets/{walletId}/accounts doesnt work gives me 404,

So it is really confusing me that which runs what. and /api/v0, /api/v1 and /api can the community provides some correct information, that would be helpful.

I guess, most of the people asking this, is trying to builld a delegation client on the phone to make it easy to access the wallet, I believe the idea is running the sl in some hosts, and make a delegation client on the phone to take to it, like create wallet, send/receive coins, and view the balance, stuffs like that. This is probably a temp hack until the thin client support is alive and the community can start building a real mobile version of Daedalus

Thanks.

rahilzebpay commented 6 years ago

I'm also having the same issue. After setting up the node and connecting to the mainet. The v1-wallet API returns 404. The v0 works fine. Pls help.

I have setup my node by following these instructions. https://www.youtube.com/watch?v=ep6VcpSflc0

Note. I'm not running Daedalus wallet.

wuyudian1 commented 6 years ago

https://github.com/input-output-hk/cardano-sl/tree/develop/wallet-new

you can build the wallet-new

rahilzebpay commented 6 years ago

Cool. Can this be run without connecting to the main-net in offline mode?

KtorZ commented 6 years ago

@lhfly5201314 In one of your first messages, you refer to the following account Id: "Ae2tdPwUPEZ18ZjTLnLVr9CEvUEUX4eW1LBHbxxxJgxdAYHrDeSCSbCxrvx.

Could you elaborate on how you created your wallet and how you obtain this wallet Id (mind you, without sharing your mnemonic backup phrase). Is this a test wallet you created using the example mnemonic we provide in the documentation ?


@BlueStalker

But /api/addresses gives me 405, /api/v1/wallets/{walletId}/accounts doesnt work gives me 404,

405 means that you're using a non-allowed method on the given endpoint. Also, note that the V1 is still in beta and not officially released so unless you're building from the tip of develop, Daedalus will be running an old version of the API where not all methods from V1 are available. So that's why you probably can't access the different endpoints.


@rahilzebpay

It's likely that you're running an old version of the node. Make sure to build the latest version if you want to play with V1. It is incidentally possible to run a local demo cluster on your machine using nix as follows:

$ nix-build -A demoCluster -o launch-demo
./launch-demo

Thanks all.

nsticco commented 6 years ago

It's likely that you're running an old version of the node. Make sure to build the latest version if you want to play with V1. It is incidentally possible to run a local demo cluster on your machine using nix as follows:

$ nix-build -A demoCluster -o launch-demo ./launch-demo

Hey @KtorZ , would you be able to clarify the difference between creating a demo cluster this way and using the demo-with-wallet-api.sh or demo-with-new-wallet-api.sh scripts?

KtorZ commented 6 years ago

@nsticco

The demo-with-wallet-api.sh is a pure bash-alternative to nix-build -A demoCluster. Nix is the preferred way for it is more reliable, recreating a clean and isolated environment. We use demo-with-wallet-api.sh during development to get a quicker feedback, you oughtn't need it. All-in-all, Nix is more reproducible and more convenient for people not involved in development; yet in essence, they're doing the same thing.

Anyways, don't use demo-with-new-wallet-api.sh :)

nsticco commented 6 years ago

Thanks for that clarification, @KtorZ ! Testing the script now, it seems to run alright, but I'm not getting any confirmations on my transactions. I can create wallets and then check that they exist with the API. I can also see that a transaction was created, but the confirmation count just stays at 0.

user@cardano:~/cardano-sl$ curl -X GET https://localhost:8090/api/v1/transactions?wallet_id=Ae2tdPwUPEZ5YjF9WuDoWfCZLPQ56MdQC6CZa2VKwMVRVqBBfTLPNcPvET4 \
> --cert ~/cardano-sl/state-demo/tls/client/client.pem \
> --cacert ~/cardano-sl/state-demo/tls/client/ca.crt | json_pp
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100  1453    0  1453    0     0  12486      0 --:--:-- --:--:-- --:--:-- 12525
{
   "data" : [
      {
         "creationTime" : "2018-06-20T00:07:04.513315",
         "type" : "foreign",
         "inputs" : [
            {
               "amount" : 37499999999166,
               "address" : "DdzFFzCqrhswMWoTiWaqXUDZJuYUx63qB6Aq8rbVbhFbc8NWqhpZkC7Lhn5eVA7kWf4JwKvJ9PqQF78AewMCzDZLabkzm99rFzpNDKp5"
            }
         ],
         "status" : {
            "tag" : "applying",
            "data" : {}
         },
         "outputs" : [
            {
               "address" : "DdzFFzCqrhsoioa2XbzXNgbDYxTB8NWp39RGH8UZj2wM935PZZqdrfPmfL1FFhJ6bJ7ei5Hv3b637Sb8KxK3M8g89xP1CVV8FptMen1a",
               "amount" : 37499999828173
            },
            {
               "address" : "DdzFFzCqrhsnAcBPwhuD517RVcEKWi6paSHc4Q44nytoXabLuPR2bsawVp4sGkxGK1UcRcVfsRsqzjbZwwyK1NaJCgep6FvwwgJSJHa2",
               "amount" : 55
            }
         ],
         "direction" : "outgoing",
         "id" : "120acf327c9bfb6eb1080e0bf72db19110ea21467a4a7be9b7a1814171645da8",
         "amount" : 170993,
         "confirmations" : 0
      },
      {
         "amount" : 5171070,
         "confirmations" : 0,
         "creationTime" : "2018-06-20T00:12:49.327326",
         "type" : "foreign",
         "status" : {
            "data" : {},
            "tag" : "applying"
         },
         "inputs" : [
            {
               "address" : "DdzFFzCqrhswMWoTiWaqXUDZJuYUx63qB6Aq8rbVbhFbc8NWqhpZkC7Lhn5eVA7kWf4JwKvJ9PqQF78AewMCzDZLabkzm99rFzpNDKp5",
               "amount" : 37499999999166
            }
         ],
         "id" : "5f6091ba4b89129c3a30aa2217e470dc1e89a2cec9f55f192e47063a7f443772",
         "outputs" : [
            {
               "amount" : 37499994828096,
               "address" : "DdzFFzCqrhsz7tcAmv4vMbmtu68ZV6zoGRitFpi7WP5CMQkeUFYPnJp6gAsyqoBJ6cQ1KAvuLM51HenAjVhggoDssUQRKNnJzzA8eiuh"
            },
            {
               "address" : "DdzFFzCqrhsnAcBPwhuD517RVcEKWi6paSHc4Q44nytoXabLuPR2bsawVp4sGkxGK1UcRcVfsRsqzjbZwwyK1NaJCgep6FvwwgJSJHa2",
               "amount" : 5000000
            }
         ],
         "direction" : "outgoing"
      }
   ],
   "meta" : {
      "pagination" : {
         "totalPages" : 1,
         "totalEntries" : 2,
         "perPage" : 10,
         "page" : 1
      }
   },
   "status" : "success"
}