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

Dogecoin vs. Ripple: A Comparative Analysis of Two Cryptocurrencies
https://cryptoswiki.com/cryptocoins/99708.html

Troubleshooting Your Bitcoin Miner: Common Issues and Solutions
https://cryptoswiki.com/mining/99707.html

USDT Purchase Limits: A Comprehensive Guide for Individual Investors
https://cryptoswiki.com/cryptocoins/99706.html

Understanding Tether (USDT): A Deep Dive into the Controversial Stablecoin
https://cryptoswiki.com/cryptocoins/99705.html

Bitcoin Private Keys and Transactions: A Comprehensive Guide
https://cryptoswiki.com/cryptocoins/99704.html
Hot

Exchanging Ethereum (ETH): A Comprehensive Guide to Altcoin Swaps and DeFi Protocols
https://cryptoswiki.com/cryptocoins/99519.html

What is Ethereum (ETH)? A Deep Dive into the World‘s Second-Largest Cryptocurrency
https://cryptoswiki.com/cryptocoins/99028.html

Litecoin Maintenance: Understanding Updates, Upgrades, and Network Stability
https://cryptoswiki.com/cryptocoins/98593.html

How to Acquire Ethereum Classic (ETC) Using Cardano (ADA)
https://cryptoswiki.com/cryptocoins/98277.html

OK Bitcoin Human-Powered Services: Navigating the Complexities of Cryptocurrency
https://cryptoswiki.com/cryptocoins/97970.html