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
New
How Long Does It Take for Bitcoin to Mature?
https://cryptoswiki.com/cryptocoins/18799.html
Shiba Inu: The Dog-Themed Cryptocurrency That Took the World by Storm
https://cryptoswiki.com/cryptocoins/18798.html
How to Make Money Buying Tether
https://cryptoswiki.com/cryptocoins/18797.html
What Bitcoin‘s Trading Volume Tells Us
https://cryptoswiki.com/cryptocoins/18796.html
[83eth]: Unlocking the Value of an Undervalued Crypto Asset
https://cryptoswiki.com/cryptocoins/18795.html
Hot
Profiting from TRON: A Comprehensive Guide to Investing in TRX
https://cryptoswiki.com/cryptocoins/18214.html
How to Store Your Cryptocurrency Funds Safely
https://cryptoswiki.com/cryptocoins/16455.html
OKB vs OKX: Understanding the Differences and Similarities
https://cryptoswiki.com/cryptocoins/16120.html
What is Bitcoin? An In-Depth Look at the First Cryptocurrency
https://cryptoswiki.com/cryptocoins/16028.html
Where to Trade CapCoin
https://cryptoswiki.com/cryptocoins/15770.html