Closed ifavo closed 5 days ago
Hello @ifavo ,
With node_compat
enabled, are you able to run the worker?
No it won't.
🥳 reading works, signing fails with:
✘ [ERROR] Error: crypto.getRandomValues must be defined
I've used the following example:
const clauses = [
clauseBuilder.transferVET(
'0x7567d83b7b8d80addcb281a71d54fc7b3364ffed', 0
)
];
// 2 - Calculate intrinsic gas of clauses
const gas = TransactionUtils.intrinsicGas(clauses);
// 3 - Body of transaction
const body = {
chainTag: networkInfo.mainnet.chainTag,
blockRef: '0x0000000000000000',
expiration: 0,
clauses,
gasPriceCoef: 128,
gas,
dependsOn: null,
nonce: 12345678
};
// Create private key
const privateKey = secp256k1.generatePrivateKey();
// 4 - Sign transaction
const signedTransaction = TransactionHandler.sign(
body,
Buffer.from(privateKey)
);
// 5 - Encode transaction
const encodedRaw = signedTransaction.encoded;
// 6 - Decode transaction
const decodedTx = TransactionHandler.decode(encodedRaw, true);
return new Response(JSON.stringify(decodedTx))
could you enable this too?
I've opened a new issue: https://github.com/vechain/vechain-sdk-js/issues/1095
From my perspective we can close this issue, because it did not contain the signing as requirement.
Summary
My personal setup involves CloudFlare Workers a lot to create APIs or Vechain interaction with a very low effort. To enable transaction building with connex I have a stripped version of the
thor-devkit
that runs innode_compat
(NodeJS compatibility) mode.I would like to use the SDK within CloudFlare Workers in compatibility mode as well without creating a stripped version to:
Ideas to create the compatibility are:
events
on demand insteadBasic Example
npx wrangler generate sdk-cf
@vechain/sdk-network
to it usingnpm install --save @vechain/sdk-network @vechain/sdk-core
ThorClient.fromUrl('https://testnet.vechain.org')
wrangler dev
or if you have a CloudFlare account usewrangler deploy
node_compat = true
to thewrangler.toml
to enable NodeJS compatibilitywrangler dev
or if you have a CloudFlare account usewrangler deploy
Using this simplified
index.ts
: