Giter Club home page Giter Club logo

Comments (21)

cgcardona avatar cgcardona commented on July 24, 2024 1

Glad to hear that you're getting the proper UTXO data. Try signing your tx like this:

let unsignedTx = await xchain.buildBaseTx(utxos.utxos, sendAmount, assetid, [friendsAddress], addresscheck, addresscheck);
let tx = unsignedTx.sign(xchain.keyChain());

from avalanchejs.

collincusce avatar collincusce commented on July 24, 2024

I don't think this is a getUTXOs problem, but you're not connecting to the node itself. @cgcardona can you reach out and assist?

from avalanchejs.

AnasSaeed123 avatar AnasSaeed123 commented on July 24, 2024

const avalanche = require("avalanchejs");
let myNetworkID = 5; //default is 3, we want to override that for our local network
let myBlockchainID = "X"; // The X-Chain blockchainID on this network
let ava = new avalanche.Avalanche("localhost", 9650, "http", myNetworkID, myBlockchainID);
let xchain = ava.XChain();

let addresscheck = ['X-fuji1gkw5z7qw0fn49xn875uyfd9hhcw9fctddvkdru']
getUTXOs(addresscheck);

async function getUTXOs(addresscheck)
{

let utxos = await xchain.getUTXOs(addresscheck);
console.log("Checking utxos: ", utxos);
let sendAmount = new avalanche.BN(100);

let assetid = "U8iRqJoiJm8xZHAacmvYyZVwqQx6uDNtQeP3CQ6fcgQk3JqnK"; //avaSerialized string
let friendsAddress = "X-fuji1acx2e6drpwkyuy5dtfqxt65vygtxd4xse60lwk";
let unsignedTx = await xchain.buildBaseTx(utxos, sendAmount, [friendsAddress], addresscheck, addresscheck, assetid);

}
It is giving me this error:

"(node:6028) UnhandledPromiseRejectionWarning: Error: Request failed with status code 503
at createError (/home/alphabet-01/Desktop/anas/javascript/node_modules/avalanchejs/node_modules/axios/lib/core/createError.js:16:15)
at settle (/home/alphabet-01/Desktop/anas/javascript/node_modules/avalanchejs/node_modules/axios/lib/core/settle.js:17:12)
at IncomingMessage.handleStreamEnd (/home/alphabet-01/Desktop/anas/javascript/node_modules/avalanchejs/node_modules/axios/lib/adapters/http.js:236:11)
at IncomingMessage.emit (events.js:327:22)
at endReadableNT (_stream_readable.js:1220:12)
at processTicksAndRejections (internal/process/task_queues.js:84:21)
(node:6028) 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: 2)
(node:6028) [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."

from avalanchejs.

AnasSaeed123 avatar AnasSaeed123 commented on July 24, 2024

@collincusce I have connected to node but it is giving me above error.

from avalanchejs.

cgcardona avatar cgcardona commented on July 24, 2024

I'm looking in to this today. I'll keep you posted on what I find @AnasSaeed123. Thanks.

from avalanchejs.

cgcardona avatar cgcardona commented on July 24, 2024

@AnasSaeed123 the syntax has changed recently. I'll make sure to get the docs updated. Can you try this script? It works for me.

import { Avalanche} from "avalanche"
let myNetworkID = 5; 
let myBlockchainID = "X"; 
const avalanche: Avalanche = new Avalanche("localhost", 9650, "http", myNetworkID, myBlockchainID)
let xchain = avalanche.XChain();

let addresscheck = ['X-fuji1gkw5z7qw0fn49xn875uyfd9hhcw9fctddvkdru']
getUTXOs(addresscheck);

async function getUTXOs(addresscheck: string[])
{
  let u = await xchain.getUTXOs(addresscheck);
  let utxos = u.utxos;
  console.log("Checking utxos: ", utxos);
  let sendAmount = new BN(100);

  let assetid = "U8iRqJoiJm8xZHAacmvYyZVwqQx6uDNtQeP3CQ6fcgQk3JqnK"; //avaSerialized string
  let friendsAddress = "X-fuji1acx2e6drpwkyuy5dtfqxt65vygtxd4xse60lwk";
  let unsignedTx = await xchain.buildBaseTx(utxos, sendAmount, assetid, [friendsAddress], addresscheck, addresscheck);
}

from avalanchejs.

AnasSaeed123 avatar AnasSaeed123 commented on July 24, 2024

Okay I'll try it and keep you updated.

from avalanchejs.

AnasSaeed123 avatar AnasSaeed123 commented on July 24, 2024

@cgcardona Can it work for this code also: "const avalanche: Avalanche = new Avalanche("api.avax-test.network", 443, "https", myNetworkID, myBlockchainID)" . Guide me in this case also.

from avalanchejs.

AnasSaeed123 avatar AnasSaeed123 commented on July 24, 2024

@cgcardona This API is giving me desired data of utxos. Also unsignedTx is done using above API but it is giving me this error when signing the transaction:

" (node:1589) UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'sign' of undefined
at BaseTx.sign (/home/alphabet-01/Desktop/anas/javascript/node_modules/avalanchejs/dist/apis/avm/basetx.js:129:41)
at UnsignedTx.sign (/home/alphabet-01/Desktop/anas/javascript/node_modules/avalanchejs/dist/apis/avm/tx.js:87:39)
at AVMAPI.signTx (/home/alphabet-01/Desktop/anas/javascript/node_modules/avalanchejs/dist/apis/avm/api.js:962:36)
at getUTXOs (/home/alphabet-01/Desktop/anas/javascript/test_avalanche.js:85:23)
at processTicksAndRejections (internal/process/task_queues.js:97:5)
(node:1589) 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:1589) [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 am followiing this code because localhost is not working for me correctly: "
const avalanche = require("avalanchejs");
let myNetworkID = 5; //default is 3, we want to override that for our local network
let myBlockchainID = "X"; // The X-Chain blockchainID on this network
let ava = new avalanche.Avalanche("api.avax-test.network", 443, "https", myNetworkID, myBlockchainID);
let xchain = ava.XChain();

let addresscheck = ['X-fuji1acx2e6drpwkyuy5dtfqxt65vygtxd4xse60lwk']
getUTXOs(addresscheck);

async function getUTXOs(addresscheck)
{

let utxos = await xchain.getUTXOs(addresscheck);

console.log("Checking data: ", utxos.utxos);

let sendAmount = new avalanche.BN(1);
let assetid = "U8iRqJoiJm8xZHAacmvYyZVwqQx6uDNtQeP3CQ6fcgQk3JqnK"; //avaSerialized string
let friendsAddress = "X-fuji1gkw5z7qw0fn49xn875uyfd9hhcw9fctddvkdru";
let unsignedTx = await xchain.buildBaseTx(utxos.utxos, sendAmount, assetid, [friendsAddress], addresscheck, addresscheck);
//console.log("Checking data: ", unsignedTx.transaction);
let signedTx = xchain.signTx(unsignedTx);
}

from avalanchejs.

AnasSaeed123 avatar AnasSaeed123 commented on July 24, 2024

Glad to hear that you're getting the proper UTXO data. Try signing your tx like this:

let unsignedTx = await xchain.buildBaseTx(utxos.utxos, sendAmount, assetid, [friendsAddress], addresscheck, addresscheck);
let tx = unsignedTx.sign(xchain.keyChain());

Not getting the desired result by using above code.

from avalanchejs.

AnasSaeed123 avatar AnasSaeed123 commented on July 24, 2024

After taking sha256 of serialized transaction data I have generated signature in C language(Because I am integrating Avalanche in OPOLO Cosmos Hardware wallet in C language) . After that I followed documentation : "https://docs.avax.network/v1.0/en/references/avm-transaction-serialization/#what-signed-transaction-contains" I concatenated unsignedTx and credentials. Is there any API which can issueTx in hex form.

from avalanchejs.

AnasSaeed123 avatar AnasSaeed123 commented on July 24, 2024

{
"jsonrpc": "2.0",
"error": {
"code": -32000,
"message": "problem decoding transaction: invalid input checksum",
"data": null
},
"id": 15
}

Giving this error when sending transcation.

from avalanchejs.

AnasSaeed123 avatar AnasSaeed123 commented on July 24, 2024

@cgcardona

from avalanchejs.

cgcardona avatar cgcardona commented on July 24, 2024

You can call avm.issueTx and have the 2nd optional parameter be encoding. More info

curl -X POST --data '{
    "jsonrpc":"2.0",
    "id"     : 1,
    "method" :"avm.issueTx",
    "params" :{
        "tx":"6sTENqXfk3gahxkJbEPsmX9eJTEFZRSRw83cRJqoHWBiaeAhVbz9QV4i6SLd6Dek4eLsojeR8FbT3arFtsGz9ycpHFaWHLX69edJPEmj2tPApsEqsFd7wDVp7fFxkG6HmySR",
        "encoding": "hex"
    }
}' -H 'content-type:application/json;' 127.0.0.1:9650/ext/bc/X

Does that work for you?

from avalanchejs.

AnasSaeed123 avatar AnasSaeed123 commented on July 24, 2024

Having problem in signing transaction. Please guide me in this matter.

This is error: "(node:7197) UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'sign' of undefined
at BaseTx.sign (/home/alphabet-01/Desktop/anas/javascript/node_modules/avalanche/dist/apis/avm/basetx.js:129:41)
at UnsignedTx.sign (/home/alphabet-01/Desktop/anas/javascript/node_modules/avalanche/dist/apis/avm/tx.js:87:39)
at getUTXOs (/home/alphabet-01/Desktop/anas/javascript/test_avalanche.js:75:27)
at processTicksAndRejections (internal/process/task_queues.js:97:5)"

Code given below:
"const avalanche = require("avalanche");

let myNetworkID = 5; //default is 3, we want to override that for our local network
let myBlockchainID = "X"; // The X-Chain blockchainID on this network
let ava = new avalanche.Avalanche("api.avax-test.network", 443, "https", myNetworkID, myBlockchainID);
let xchain = ava.XChain();

let addresscheck = ['X-fuji1acx2e6drpwkyuy5dtfqxt65vygtxd4xse60lwk']

getUTXOs(addresscheck);

async function getUTXOs(addresscheck)
{
let myKeychain = xchain.keyChain();
let newAddress1 = myKeychain.makeKey();
console.log("Checking data: ", myKeychain);
let utxos = await xchain.getUTXOs(addresscheck);

let sendAmount = new avalanche.BN(1);
let assetid = "U8iRqJoiJm8xZHAacmvYyZVwqQx6uDNtQeP3CQ6fcgQk3JqnK"; //avaSerialized string
let friendsAddress = "X-fuji1gkw5z7qw0fn49xn875uyfd9hhcw9fctddvkdru";
let unsignedTx = await xchain.buildBaseTx(utxos.utxos, sendAmount, assetid, [friendsAddress], addresscheck, addresscheck);
console.log("Checking unsignedTx: ", unsignedTx);
console.log("Checking unsignedTx.transaction: ", unsignedTx.transaction);

console.log("Checking : ", xchain.keyChain());
//let signedTx = unsignedTx.sign(myKeychain);
let signedTx = unsignedTx.sign(xchain.keyChain());

}"

from avalanchejs.

AnasSaeed123 avatar AnasSaeed123 commented on July 24, 2024

{
"jsonrpc": "2.0",
"error": {
"code": -32000,
"message": "problem decoding transaction: invalid input checksum",
"data": null
},
"id": 1
}

from avalanchejs.

AnasSaeed123 avatar AnasSaeed123 commented on July 24, 2024

from avalanchejs.

cgcardona avatar cgcardona commented on July 24, 2024

Has this been resolved or have you made progress?

from avalanchejs.

AnasSaeed123 avatar AnasSaeed123 commented on July 24, 2024

from avalanchejs.

collincusce avatar collincusce commented on July 24, 2024

Have you looked at the examples to see if there's any hints what's going on?

https://github.com/ava-labs/avalanchejs/tree/master/examples

from avalanchejs.

paOol avatar paOol commented on July 24, 2024

hopefully you can find what you are lookig for by going through the tests for tx and utxos below.

https://github.com/ava-labs/avalanchejs/blob/master/tests/apis/avm/tx.test.ts
https://github.com/ava-labs/avalanchejs/blob/master/tests/apis/avm/utxos.test.ts

closing due to age.

from avalanchejs.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.