Create tokens that can’t be transferred. Certificates, identity, ticketing and more.
non-transferrable token
enables
non-transferrable tokensnon-transferable
extension.
Token Extension Program has the non-transferable
extension which can be used
to create non-transferable mints. These mints can be burned, but they can’t be
transferred.
SystemProgram.createAccount
createInitializeNonTransferableMintInstruction
createInitializeMintInstruction
SystemProgram.createAccount
allocates space on the
blockchain for the mint account. This instruction accomplishes three things:
space
lamports
for rentgetMintLen
and
getMinimumBalanceForRentExemption
.
createInitializeNonTransferableMintInstruction
initializes the non-transferable extension.
createInitializeMintInstruction
initializes the mint.
metadata
and metadata-pointer
extensions to create soul-bound NFTs.
non-transferable-token
and
navigate to it. We’ll be initializing a brand new project. Run npm init
and
follow through the prompts.
Next, we’ll need to add our dependencies. Run the following to install the
required packages:
src
. In this directory, create a file named
index.ts
. This is where we will run checks against the rules of this
extension. Paste the following code in index.ts
:
initializeKeypair
. This main function is where we’ll
end up calling the rest of our script once we’ve written it.
Go ahead and run the script. You should see the mint
public key logged to your
terminal.
initializeKeypair
with airdropping, follow the
next step.
keypairPath
parameter to initializeKeypair
and get some devnet
NZT from Nexis Native Chain’s faucet.solana-test-validator
. This
will run the node and also log out some keys and values. The value we need to
retrieve and use in our connection is the JSON RPC URL, which in this case is
http://127.0.0.1:8899
. We then use that in the connection to specify to use
the local RPC URL.
createNonTransferableMint
in a new file
src/create-mint.ts
.
Inside the file, create the function createNonTransferableMint
with the
following arguments:
connection
: The connection objectpayer
: Payer for the transactionmintKeypair
: Keypair for new mintdecimals
: Mint decimalsgetMintLen
- to get the space needed for the mint accountgetMinimumBalanceForRentExemption
- to get the amount of lamports needed for
the mint accountcreateAccount
- Allocates space on the blockchain for the mint accountcreateInitializeNonTransferableMintInstruction
- initializes the extensioncreateInitializeMintInstruction
- initializes the mintsendAndConfirmTransaction
- sends the transaction to the blockchainsrc/index.ts
to create the non-transferable
mint:
npm start
. Let’s move on to the next step and create a source account and
mint a token to it.
src/index.ts
. Let’s create a source account and mint one
non-transferable token.
We can accomplish this in two functions:
getOrCreateAssociatedTokenAccount
: from the @nexis-network/spl-token
library,
this creates an associated token account (ATA) for the given mint and owner.mintTo
: This function will mint an amount
of tokens to the given token
account.src/index.ts
, we will create a destination account and try to transfer the
non-transferable token to this account.
We can accomplish this in two functions:
createAccount
: This will create a token account for a given mint and the
keypair of said account. So instead of using an ATA here, let’s generate a new
keypair as the token account. We’re doing this just to show different options
of accounts.transferChecked
: This will attempt to transfer the token.createAccount
function:
transferChecked
function:
Transfer is disabled for this mint
. This is indicating that the token we are
attempting to transfer is in fact non-transferable!
solution
branch of
this repository.