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

Profiting from Bitcoin‘s Appreciation: Strategies and Considerations
https://cryptoswiki.com/cryptocoins/104374.html

Luna Price on Binance: A Comprehensive Analysis of LUNA‘s Volatility and Future Prospects
https://cryptoswiki.com/cryptocoins/104373.html

Is Polkadot Wallet a Tron Wallet? Understanding the Difference
https://cryptoswiki.com/cryptocoins/104372.html

Why Bitcoin Exists: A Deep Dive into its Origins and Purpose
https://cryptoswiki.com/cryptocoins/104371.html

Driving Traffic to Bitcoin: A Comprehensive Guide to Effective Marketing Strategies
https://cryptoswiki.com/cryptocoins/104370.html
Hot

Bitcoin‘s Dip: Which Stocks Benefit From a Crypto Correction?
https://cryptoswiki.com/cryptocoins/104249.html

Shiba Inu Price Lottery: A Deep Dive into SHIB‘s Volatility and Potential for Explosive Growth
https://cryptoswiki.com/cryptocoins/104157.html

What Does Forex BTC Mean? Understanding Bitcoin‘s Role in the Foreign Exchange Market
https://cryptoswiki.com/cryptocoins/103979.html

Who‘s Using OKB? Unpacking the OKEx Ecosystem and OKB‘s User Base
https://cryptoswiki.com/cryptocoins/103724.html

Withdraw TRON (TRX) to Chinese Yuan (CNY): A Comprehensive Guide
https://cryptoswiki.com/cryptocoins/102440.html