How To Deploy A Token On NEAR96
In this guide, we will learn how to deploy a token on the NEAR Protocol. We will use the NEAR Command-Line Interface (CLI) and the NEAR Token Standards library to create and deploy a simple fungible token contract.
Prerequisites:
installed
NEAR CLI installed
A NEAR account with some NEAR tokens
1. Create a New Project
First, create a new project directory and initialize a file:```
mkdir my-token
cd my-token
npm init -y
```
2. Install Dependencies
Next, install the NEAR API, NEAR Token Standards library, and ESBuild:```
npm install @near/api @near/token-standards esbuild
```
3. Create a Contract
Create a new file named `` and paste the following code:```javascript
const { Account, Contract, JsonRpcProvider } = require("@near/api");
const {
Balance,
FungibleToken,
init,
transfer,
} = require("@near/token-standards");
const provider = new JsonRpcProvider("");
const account = new Account(provider);
const contract = new Contract(
account, // the account object that is sending the transaction
"", // contract account ID
{
// View methods are read-only and don't modify the state.
viewMethods: ["ft_balance_of"],
// Change methods can modify the state, but don't return any value.
changeMethods: ["ft_transfer", "ft_transfer_call"],
}
);
async function main() {
// Initialize the contract (you only need to do this once)
await init(contract);
// Get the balance of the account
const balance = await (contract, "alice");
("Balance:", ());
// Transfer 10 tokens from "alice" to "bob"
await transfer(contract, "bob", "10");
// Get the new balance of the account
const newBalance = await (contract, "alice");
("New balance:", ());
}
main();
```
This contract defines two methods: `ft_balance_of` and `ft_transfer`. The `ft_balance_of` method returns the balance of an account, and the `ft_transfer` method transfers a specified number of tokens from one account to another.
4. Build the Contract
Use ESBuild to build the contract:```
esbuild --outfile= --target=wasm32
```
5. Deploy the Contract
Finally, deploy the contract to the NEAR testnet:```
near deploy
```
This command will prompt you to enter your NEAR account's secret key. Once the contract is deployed, you will see a success message.
Conclusion
Congratulations! You have now successfully deployed a fungible token contract on the NEAR Protocol. You can now use your contract to create and manage tokens.
2024-11-27
Previous:Bitcoin Cash (BCH) Price Prediction: Future Prospects and Market Analysis
Next:Bitcoin (BTC): A Comprehensive Guide to the Cryptocurrency Giant

Why Did SHIB Price Surge? A Deep Dive into Shiba Inu‘s Volatility
https://cryptoswiki.com/cryptocoins/69110.html

USDT to USDC Converter: A Deep Dive into Stablecoin Swaps and Their Implications
https://cryptoswiki.com/cryptocoins/69109.html

Troubleshooting Ada (Cardano) Wallet Issues: Why Can‘t I Access My Wallet?
https://cryptoswiki.com/cryptocoins/69108.html

SHIB Closing Time: Understanding Market Dynamics and Implications for Investors
https://cryptoswiki.com/cryptocoins/69107.html

What is Bitmain Mining and Which Cryptocurrencies Does It Support?
https://cryptoswiki.com/cryptocoins/69106.html
Hot

Tether to Bitcoin Transfers: A Comprehensive Guide for Beginners and Experts
https://cryptoswiki.com/cryptocoins/68957.html

OKX Earn: A Deep Dive into its Crypto Staking and Lending Products
https://cryptoswiki.com/cryptocoins/68940.html

OKX Wallet: A Deep Dive into Security, Features, and Usability
https://cryptoswiki.com/cryptocoins/67705.html

Bitcoin Price Analysis: Navigating Volatility in the July 10th Market
https://cryptoswiki.com/cryptocoins/67691.html

Investing in China‘s Bitcoin Ecosystem: Understanding the Indirect Exposure
https://cryptoswiki.com/cryptocoins/67560.html