Comments (21)
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.
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.
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.
@collincusce I have connected to node but it is giving me above error.
from avalanchejs.
I'm looking in to this today. I'll keep you posted on what I find @AnasSaeed123. Thanks.
from avalanchejs.
@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.
Okay I'll try it and keep you updated.
from avalanchejs.
@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.
@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.
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.
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.
{
"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.
from avalanchejs.
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.
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.
{
"jsonrpc": "2.0",
"error": {
"code": -32000,
"message": "problem decoding transaction: invalid input checksum",
"data": null
},
"id": 1
}
from avalanchejs.
from avalanchejs.
Has this been resolved or have you made progress?
from avalanchejs.
from avalanchejs.
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.
hopefully you can find what you are lookig for by going through the tests for tx
and utxo
s 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)
- mnemonic.generateMnemnonic() Uncaught (in promise) TypeError: Cannot read properties of undefined (reading 'call')
- feature request: Banff Update Support
- getPreferredHRP returns incorrect prefix HOT 1
- Defaults.network[networkID].C.blockchainID returns incorrect Blockchain ID
- AvalancheCore.post request is not working with URL of format https://username:[email protected]
- How to get pending transactions HOT 1
- getAtomicTx method does not return the block height
- Pchain getBalance doesn't work
- Missing @avalabs/avalanchejs on yarn package manager
- X-Chain getting UTXO set example uses wrong variable!
- unable to parse block in js
- how to parse block in js
- getContainerByIndex problem with 3.17.0
- Decoding atomic transaction from byte data returned by `getAtomicTx` rpc call HOT 1
- Security: insecure deps are used, switch to better ones HOT 2
- Cannot use v3.18.1 for addPermissionlessValidator and addPermissionlessDelegator Transactions
- Export C-to-X example does not work HOT 3
- exec delegate.ts issue
- Add support for AddPermissionlessValidator and AddPermissionlessDelegator transactions in v3
- Support for Node18 HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from avalanchejs.