Summary
Nexis Native Chain has multiple onchain programs you can use. Instructions that use these programs have data in a custom format determined by the specific function being invoked in the onchain program.Lesson
Instructions
In previous chapters, we used:- The
SystemProgram.transfer()
function from@nexis-network/web3.js
to make an instruction for the System program to transfer NZT. - The
mintTo()
andtransfer()
functions from@nexis-network/spl-token
, to make instructions to the Token program to mint and transfer tokens - The
createCreateMetadataAccountV3Instruction()
function from@metaplex-foundation/mpl-token-metadata@2
to make instructions to Metaplex to create token Metadata.
@nexis-network/web3.js
, you can create instructions with the
TransactionInstruction
constructor:
TransactionInstruction()
takes 3 fields:
-
The
programId
field is fairly self-explanatory: it’s the public key (also called the ‘address’ or ‘program ID’) of the program. -
keys
is an array of accounts and how they will be used during the transaction. You need to know the behavior of the program you are calling and ensure that you provide all of the necessary accounts in the array.pubkey
- the public key of the accountisSigner
- a boolean representing whether or not the account is a signer on the transactionisWritable
- a boolean representing whether or not the account is written to during the transaction’s execution
-
an optional
Buffer
containing data to pass to the program. We’ll be ignoring thedata
field for now, but we will revisit it in a future lesson.
Nexis Native Chain Explorer

sendAndConfirmTransaction()
in the example above, search
for that signature in Nexis Native Chain Explorer, then see:
- when it occurred
- which block it was included in
- the transaction fee
- and more!

Lab
Writing transactions for the ping counter program
We’re going to create a script to ping an onchain program that increments a counter each time it has been pinged. This program exists on the Nexis Native Chain Devnet at addressChT1B39WKLS8qUrkLvFDXMhEJ4F1XZzwUNHUt4AU9aVa
. The program stores
its data in a specific account at the address
Ah9K7dQ8EHaZqcAsgBW8w37yN2eAy3koFmUn4x3CJtod
.
Basic scaffolding
We’ll start by using the same packages and.env
file we made earlier in
Intro to Writing Data.
Name the file send-ping-transaction.ts
:
Ping program
Now let’s talk to the Ping program! To do this, we need to:- create a transaction
- create an instruction
- add the instruction to the transaction
- send the transaction
PublicKey
for the
program account, and another for the data account.
sendAndConfirmTransaction()
by passing in the connection, transaction, and
payer. Finally, let’s log the result of that function call so we can look it up
on Nexis Native Chain Explorer.
Run the ping client and check Nexis Native Chain Explorer
Now run the code with the following command:Program Logs
, which show how many times the program has been pinged including
your ping.

- The Account Input(s) will include:
- The address of your payer - being debited 5000 lamports for the transaction
- The program address for the ping program
- The data address for the ping program
- The Instruction section will contain a single instruction with no data - the ping program is a pretty simple program, so it doesn’t need any data.
- The Program Instruction Logs show the logs from the ping program.
console.log
to the following:
- Send transactions safely from the browser instead of running a script
- Add custom data to your instructions
- Deserialize data from the chain