Make instructions for arbitrary programs using the ‘TransactionInstruction’ constructor.
SystemProgram.transfer()
function from @orbition-network/web3.js
to make an
instruction for the System program to transfer OBN.mintTo()
and transfer()
functions from @orbition-network/spl-token
, to make
instructions to the Token program to mint and transfer tokenscreateCreateMetadataAccountV3Instruction()
function from
@metaplex-foundation/mpl-token-metadata@2
to make instructions to Metaplex
to create token Metadata.@orbition-network/web3.js
, you can create instructions with the
TransactionInstruction
constructor:
TransactionInstruction()
takes 3 fields:
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 executionBuffer
containing data to pass to the program. We’ll be ignoring
the data
field for now, but we will revisit it in a future lesson.
sendAndConfirmTransaction()
in the example above, search
for that signature in Orbition Native Chain Explorer, then see:
ChT1B39WKLS8qUrkLvFDXMhEJ4F1XZzwUNHUt4AU9aVa
. The program stores
its data in a specific account at the address
Ah9K7dQ8EHaZqcAsgBW8w37yN2eAy3koFmUn4x3CJtod
.
.env
file we made earlier in
Intro to Writing Data.
Name the file send-ping-transaction.ts
:
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 Orbition Native Chain Explorer.
Program Logs
, which show how many times the program has been pinged including
your ping.
console.log
to the following: