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 Bitcoin‘s Price Drops: A Deep Dive into Market Volatility
https://cryptoswiki.com/cryptocoins/101459.html

Securing Your XRP: A Comprehensive Guide to Ripple Wallet Backups and Recovery
https://cryptoswiki.com/cryptocoins/101458.html

Exploring the Diverse Cardano (ADA) Community: Size, Structure, and Influence
https://cryptoswiki.com/cryptocoins/101457.html

Understanding and Navigating the Thai Tether Market: Risks, Rewards, and Regulatory Landscape
https://cryptoswiki.com/cryptocoins/101456.html

Ripple (XRP) Price Action in 2018: A Rollercoaster Ride and Lessons Learned
https://cryptoswiki.com/cryptocoins/101455.html
Hot

How to Pay Taxes on Bitcoin Profits: A Comprehensive Guide
https://cryptoswiki.com/cryptocoins/101065.html

Where to Earn Bitcoin: A Comprehensive Guide to Legitimate Methods
https://cryptoswiki.com/cryptocoins/100950.html

Is Reporting USDT Scams Effective? A Crypto Expert‘s Analysis
https://cryptoswiki.com/cryptocoins/99947.html

Ripple in Hong Kong: Navigating the Regulatory Landscape and Market Potential
https://cryptoswiki.com/cryptocoins/99876.html

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