Quantcast
Channel: Recent Questions - Solana Stack Exchange
Viewing all articles
Browse latest Browse all 8063

Borsh serializing a nested object for a Solana transaction instruction

$
0
0

I have a Solidity function:

    function add(uint256 a, uint256 b) public pure returns (uint256) {        uint256 result = a + b;        return result;    }

That I've migrated over to Solana using solang. I want to call the add() function in a NodeJS script. It seems I need to serialize the call using the borsh serializer package.

The problem I have is that I can't figure out how to create the required schema for this Solana transaction instruction object:

   const num1 = 10;   const num2 = 20;   const transcationInstruction = {      add: {        num1,        num2,      },    }

For what it's worth, I am trying to follow this example from from the GitHub page. But, I can't quite grasp how to serialize a nested JSON object.

The end goal is I want to define a transaction instruction like so:

  const instruction = new TransactionInstruction({    keys: [      { pubkey: payerKeypair.publicKey, isSigner: true },      { pubkey: programAccountId, isSigner: false },    ],    programId: programAccountId,    data: encodedInstruction,  });

WHERE

encodedInstruction is the borsh serialized transaction instruction for the add(num1, num2) function in the Solana smart contract.

Thus, I reach out for help. Thanks in advance for any assistance.

I owe you one.


Viewing all articles
Browse latest Browse all 8063

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>