Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can you give me more examples such as V3 #894

Open
godlovericea opened this issue Oct 31, 2024 · 4 comments
Open

Can you give me more examples such as V3 #894

godlovericea opened this issue Oct 31, 2024 · 4 comments

Comments

@godlovericea
Copy link

I want to generate address, and make Tx on mainnet
please give me more examples such as V3
thanks

@godlovericea
Copy link
Author

I have installed current version, but my terminal console have many error tips:

`
Process exited with code 1
C:\Program Files\nodejs\node.exe .\app.js
bigint: Failed to load bindings, pure JS will be used (try npm run rebuild?)
Could not read source map for file:///D:/cvs_git/kerying_node/node_modules/%40avalabs/avalanchejs/node_modules/%40noble/curves/esm/abstract/utils.js: ENOENT: no such file or directory, open 'd:\cvs_git\kerying_node\node_modules@avalabs\avalanchejs\node_modules@noble\curves\esm\abstract\utils.js.map'
Could not read source map for file:///D:/cvs_git/kerying_node/node_modules/%40avalabs/avalanchejs/node_modules/%40noble/curves/esm/abstract/modular.js: ENOENT: no such file or directory, open 'd:\cvs_git\kerying_node\node_modules@avalabs\avalanchejs\node_modules@noble\curves\esm\abstract\modular.js.map'
Could not read source map for file:///D:/cvs_git/kerying_node/node_modules/%40avalabs/avalanchejs/node_modules/%40noble/curves/esm/abstract/curve.js: ENOENT: no such file or directory, open 'd:\cvs_git\kerying_node\node_modules@avalabs\avalanchejs\node_modules@noble\curves\esm\abstract\curve.js.map'
Could not read source map for file:///D:/cvs_git/kerying_node/node_modules/%40avalabs/avalanchejs/node_modules/%40noble/curves/esm/abstract/weierstrass.js: ENOENT: no such file or directory, open 'd:\cvs_git\kerying_node\node_modules@avalabs\avalanchejs\node_modules@noble\curves\esm\abstract\weierstrass.js.map'
Could not read source map for file:///D:/cvs_git/kerying_node/node_modules/%40avalabs/avalanchejs/node_modules/%40noble/curves/esm/abstract/hash-to-curve.js: ENOENT: no such file or directory, open 'd:\cvs_git\kerying_node\node_modules@avalabs\avalanchejs\node_modules@noble\curves\esm\abstract\hash-to-curve.js.map'
Could not read source map for file:///D:/cvs_git/kerying_node/node_modules/%40avalabs/avalanchejs/node_modules/%40noble/curves/esm/_shortw_utils.js: ENOENT: no such file or directory, open 'd:\cvs_git\kerying_node\node_modules@avalabs\avalanchejs\node_modules@noble\curves\esm_shortw_utils.js.map'
Could not read source map for file:///D:/cvs_git/kerying_node/node_modules/%40avalabs/avalanchejs/node_modules/%40noble/curves/esm/secp256k1.js: ENOENT: no such file or directory, open 'd:\cvs_git\kerying_node\node_modules@avalabs\avalanchejs\node_modules@noble\curves\esm\secp256k1.js.map'
Could not read source map for file:///D:/cvs_git/kerying_node/node_modules/%40avalabs/avalanchejs/node_modules/%40ethereumjs/rlp/dist/esm/index.js: ENOENT: no such file or directory, open 'd:\cvs_git\kerying_node\node_modules@avalabs\avalanchejs\node_modules@ethereumjs\rlp\dist\esm\index.js.map'
Could not read source map for file:///D:/cvs_git/kerying_node/node_modules/%40avalabs/avalanchejs/node_modules/%40noble/curves/esm/abstract/bls.js: ENOENT: no such file or directory, open 'd:\cvs_git\kerying_node\node_modules@avalabs\avalanchejs\node_modules@noble\curves\esm\abstract\bls.js.map'
Could not read source map for file:///D:/cvs_git/kerying_node/node_modules/%40avalabs/avalanchejs/node_modules/%40noble/curves/esm/bls12-381.js: ENOENT: no such file or directory, open 'd:\cvs_git\kerying_node\node_modules@avalabs\avalanchejs\node_modules@noble\curves\esm\bls12-381.js.map'
WHITE_ORIGIN: https://www.biyapay.com
Server is running on http://localhost:3001
avmapi: Ti {path: '/ext/bc/X', base: 'avm', fetchOptions: undefined, rpcProvider: yi, getMethodName: ƒ, …}
context: {xBlockchainID: '2oYMBNV4eNHyqk2fjjV5nVQLDbtmNJzq5s3qs3Lo6ftnC6FByM', pBlockchainID: '11111111111111111111111111111111LpoYY', cBlockchainID: '2q9e4r6Mu3U68nU1fYjgbR6JvwrRx36CohpAX5UQxse55x1Q5', avaxAssetID: 'FvwEAhmxKfeiG8SnEvq42hc6whRyY3EFYAvebMqDNDGCgxN5Z', baseTxFee: 1000000n, …}

Error: radix2.encode input should be Uint8Array
at Object.encode [as toWords] (D:\cvs_git\kerying_node\node_modules@avalabs\avalanchejs\node_modules@scure\base\lib\index.js:253:23)
at p (D:\cvs_git\kerying_node\node_modules@avalabs\avalanchejs\dist\index.cjs:1:939)
at ve.toString (D:\cvs_git\kerying_node\node_modules@avalabs\avalanchejs\dist\index.cjs:11:4215)
at Uint8Array.map ()
at Br (D:\cvs_git\kerying_node\node_modules@avalabs\avalanchejs\dist\index.cjs:11:10358)
at xr.fromNative (D:\cvs_git\kerying_node\node_modules@avalabs\avalanchejs\dist\index.cjs:11:12195)
at Create_TX_AVAX (D:\cvs_git\kerying_node\controllers\avax.js:20:26)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
at async bodyParser (D:\cvs_git\kerying_node\node_modules\koa-bodyparser\index.js:78:5)
at async cors (D:\cvs_git\kerying_node\node_modules@koa\cors\index.js:109:16)

`

@erictaylor
Copy link
Member

Please provide a more detailed description of your issue.

What "address" are you referring to?

Please have a look at the code in the examples directory.

Does https://github.com/ava-labs/avalanchejs/blob/master/examples/generate-keys.ts help?

@godlovericea
Copy link
Author

godlovericea commented Nov 11, 2024


const { avm, utils, TransferableOutput, secp256k1,TransferOutput, BigIntPr, OutputOwners, Context, Id } = require("@avalabs/avalanchejs")
const MAINNET_PUBLIC_API_BASE_URL = 'https://api.avax.network';

const Create_TX_AVAX = async () => {
    const avmapi = new avm.AVMApi(MAINNET_PUBLIC_API_BASE_URL)
    console.log("avmapi:", avmapi)
    const context = await Context.getContextFromURI(MAINNET_PUBLIC_API_BASE_URL);
    console.log("context:", context)
    
    const { utxos } = await avmapi.getUTXOs({
        addresses: ["X-avax16ccsra0jmtjfe9e3hmmeekzr7qdpazfw02wuhk"],
    });
    const fromAddressesBytes = utils.bech32ToBytes("X-avax16ccsra0jmtjfe9e3hmmeekzr7qdpazfw02wuhk") 
    const toAddressesBytes = utils.bech32ToBytes("X-avax13num8mnt43pm9y0dvwqql40u4tfn76rtzemdk5")
    const now = Date.now()
    const outputs = new TransferableOutput(
        Id.fromString(context.avaxAssetID),
        new OutputOwners()
    )
    console.log("outputs:", outputs)
    console.log("avaxAssetID:", context.avaxAssetID) 
    const tx = avm.newBaseTx(
        context,
        fromAddressesBytes,
        utxos,
        outputs
    )
    await avm.addTxSignatures({
        unsignedTx: tx,
        privateKeys: [utils.hexToBuffer("<private key>")],
    });
    const txHash = avmapi.issueSignedTx(tx.getSignedTx())
    console.log("txHash:", txHash)
}


module.exports = {
    Create_TX_AVAX
}

it does not work

@erictaylor
Copy link
Member

Seems based on the error posted that you are having issues with underlying dependencies on Windows.

bigint: Failed to load bindings, pure JS will be used (try npm run rebuild?)

&

Error: radix2.encode input should be Uint8Array
at Object.encode [as toWords] (D:\cvs_git\kerying_node\node_modules@avalabs\avalanchejs\node_modules@scure\base\lib\index.js:253:23)
at p (D:\cvs_git\kerying_node\node_modules@avalabs\avalanchejs\dist\index.cjs:1:939)
at ve.toString (D:\cvs_git\kerying_node\node_modules@avalabs\avalanchejs\dist\index.cjs:11:4215)
at Uint8Array.map ()
at Br (D:\cvs_git\kerying_node\node_modules@avalabs\avalanchejs\dist\index.cjs:11:10358)
at xr.fromNative (D:\cvs_git\kerying_node\node_modules@avalabs\avalanchejs\dist\index.cjs:11:12195)
at Create_TX_AVAX (D:\cvs_git\kerying_node\controllers\avax.js:20:26)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
at async bodyParser (D:\cvs_git\kerying_node\node_modules\koa-bodyparser\index.js:78:5)
at async cors (D:\cvs_git\kerying_node\node_modules@koa\cors\index.js:109:16)

Try running your code on another platform and see if the error persists.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants