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

Usage with Bittensor TAO #402

Open
TheTrunk opened this issue Sep 3, 2024 · 4 comments
Open

Usage with Bittensor TAO #402

TheTrunk opened this issue Sep 3, 2024 · 4 comments
Labels
Support Support Issue

Comments

@TheTrunk
Copy link

TheTrunk commented Sep 3, 2024

For Polkadot, Kusama we can use @substrate/txwrapper-polkadot and follow https://github.com/paritytech/txwrapper-core/blob/main/packages/txwrapper-examples/polkadot/src/polkadot.ts

Since Bittensor TAO is based on Substrate, I thought that transactions would follow the same with changing to Bittensor parameters. However we obtain a following error:

"Transaction has a bad signature" error while submitting the extrinsic.

Thank you for your advice

@bee344 bee344 added the Support Support Issue label Sep 12, 2024
@bee344
Copy link
Collaborator

bee344 commented Sep 18, 2024

Hi @TheTrunk , sorry for the delay, could you share some more details of your script?

@TheTrunk
Copy link
Author

Hi @TheTrunk , sorry for the delay, could you share some more details of your script?

Hi sure!

  const blocksData = { id: Math.floor(Math.random() * (1000000)) + 1, jsonrpc: "2.0", method: "chain_getHeader" };
  const runtimeData = { id: Math.floor(Math.random() * (1000000)) + 1, jsonrpc: "2.0", method: "state_getRuntimeVersion" };
  const metadataData = { id: Math.floor(Math.random() * (1000000)) + 1, jsonrpc: "2.0", method: "state_getMetadata" };
  const nonceData = {
    id: Math.floor(Math.random() * (1000000)) + 1, jsonrpc: "2.0", method: "account_nextIndex", params: [senderAddress],
  };

  const responseRuntime = await self.$http.post(nodeEndpoint, runtimeData, axiosConfig);
  const responseMetadata = await self.$http.post(nodeEndpoint, metadataData, axiosConfig);
  const responseBlocks = await self.$http.post(nodeEndpoint, blocksData, axiosConfig);
  const responseNonce = await self.$http.post(nodeEndpoint, nonceData, axiosConfig);

  const metadataRpc = responseMetadata.data.result;
  const {
    specVersion, transactionVersion, specName, implName,
  } = responseRuntime.data.result;
  const blockNumberHex = responseBlocks.data.result.number;
  const lastBlockHash = responseBlocks.data.result.parentHash;
  const lastBlockNumber = Number.parseInt(blockNumberHex, 16);
  const nonce = responseNonce.data.result;

  const registry = substrateTxWrappergetRegistry({
    specName,
    chainName: implName,
    specVersion,
    metadataRpc,
    // properties: {
    //   ss58Format: 42,
    //   tokenDecimals: 9,
    //   tokenSymbol: "TAO",
    // },
  });
  console.log(registry);

  const unsigned = substrateTxWrappermethods.balances.transferKeepAlive(
    {
      value,
      dest: address,
    },
    {
      address: senderAddress,
      blockHash: lastBlockHash,
      blockNumber: Number(lastBlockNumber),
      eraPeriod: 88, // valid for 88 blocks
      genesisHash,
      metadataRpc,
      nonce,
      specVersion,
      tip,
      transactionVersion,
    },
    {
      metadataRpc,
      registry,
    },
  );
  console.log(unsigned);

  // Construct the signing payload from an unsigned transaction.
  const signingPayload = substrateTxWrapperconstruct.signingPayload(unsigned, { registry });
  console.log(signingPayload);

  const importedKeyring = substrateTxWrapperimportPrivateKey(pk, ss58prefix);
  const EXTRINSIC_VERSION = 4;
  const { signature } = registry
    .createType("ExtrinsicPayload", signingPayload, {
      version: EXTRINSIC_VERSION,
    })
    .sign(importedKeyring);

  console.log(`\nSignature: ${signature}`);

  // Serialize a signed transaction.
  const tx = substrateTxWrapperconstruct.signedTx(unsigned, signature, { metadataRpc, registry });
  console.log(`\nTransaction to Submit: ${tx}`);

  // Derive the tx hash of a signed transaction offline.
  const expectedTxHash = substrateTxWrapperconstruct.txHash(tx);
  console.log(`\nExpected Tx Hash: ${expectedTxHash}`);

  const txData = {
    id: Math.floor(Math.random() * (1000000)) + 1, jsonrpc: "2.0", method: "author_submitExtrinsic", params: [tx],
  };
  const submitTx = await self.$http.post(nodeEndpoint, txData, axiosConfig);
  if (submitTx.data.error) {
    throw submitTx.data.error;
  }
  const txid = submitTx.data.result;`

Thank you for reviewing it!

@bee344
Copy link
Collaborator

bee344 commented Sep 18, 2024

@TheTrunk I'd need some more info to work with:

  • What packages are you using and what are their versions?
  • Do you have a public endpoint against which I could test this?

@TheTrunk
Copy link
Author

@TheTrunk I'd need some more info to work with:

  • What packages are you using and what are their versions?
  • Do you have a public endpoint against which I could test this?

Hi, I am using
"@substrate/txwrapper-polkadot": "~7.5.1"

For the endpoint its possible to use bittensor-finney.api.onfinality.io (https://onfinality.io/networks/bittensor-finney)

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

No branches or pull requests

2 participants