Quick Start
This guide will introduce you to the core concepts for building on the AIN blockchain. By the end of this guide, you'll learn how to build a blockchain app that chats with a bot and earn 100 AIN!
All examples are in this GitHub repo—clone and try them out!
Step 1. Install SDK
To interact with the blockchain in server-side JavaScript environments like Node.js, you can use the official blockchain SDK for JavaScript. Install the SDK with npm or your preferred package manager. Make sure to install version 1.10.0 or later for full compatibility:
Step 2. Connect to blockchain
Public RPC endpoints
The AI Network provides public RPC endpoints for blockchain interaction on both testnet and mainnet. Use testnet to debug and test performance before deploying to mainnet. To use the SDK on mainnet, set the Chain ID to 1.
Testnet
https://testnet-api.ainetwork.ai
wss://testnet-event.ainetwork.ai
0
Mainnet
https://mainnet-api.ainetwork.ai
wss://mainnet-event.ainetwork.ai
1
Step 3. Create your wallet
You can create multiple accounts and set a default account. However, it’s crucial to back up your private key and store it securely. Losing your private key may result in losing access to your account permanently. Take extra precautions to prevent unauthorized access!
Step 4. Get AIN (for free!)
Testnet: Free AIN via Faucet
You can receive 100 AIN daily for free on the Testnet through our faucet.
Go to the faucet site.
Enter the address created in Step 3.
Click "Request for testing" to get your AIN.
You can view transaction details by copying the transaction hash (starting with 0x…) and searching it on the AI Network Testnet block explorer.
Mainnet: Native AIN via AIN DAO Bot
To convert ERC-20 AIN from Ethereum to Native AIN on the AI Network, follow these steps:
Step 1: Import $AIN Tokens into MetaMask
Open MetaMask and go to “Assets”.
Click “Import Token” → “Custom Token”.
Use this contract address:
0x3a810ff7211b40c4fa76205a14efe161615d0385
Click “Add Custom Token” to view your $AIN balance.
Step 2: Deposit $AIN to AIN DAO Discord
In Discord, type
/ain deposit
to receive your unique deposit address (start with0x...
).Copy the deposit address.
Open your ETH wallet and locate the $AIN token.
Click “Send,” paste the deposit address, and input the amount to deposit (minimum: 500 AIN).
Confirm the transaction.
In Discord, type
/ain balance
to confirm your balance.
Step 3: Withdraw AIN Credits to Native AIN
Use the
/ain withdraw
command in Discord.Enter your AI Network wallet address.
Specify the withdrawal amount (minimum: 500 AIN).
Confirm the transaction.
Step 5. Create your app
You need at least 5 AIN to create an app. See Step 4 to get AIN.
You can create your own app by setting a value to /manage_app/${appName}/create/${key}
path. The value must contain an admin config, which is an object of { [address]: true }
. The addresses in the admin config will get the owner and write permissions to the /apps/${appName}
path.
Setting a value at the path /manage_app/${appName}/create/${key}
triggers the native function _createApp
, automatically setting the owner
and rule
permissions.
You can use the getOwner
function to check app's owner permissions and confirm the app was created successfully.
Step 6. Stake AIN to your app
On the mainnet, a free tier is available for staking, so this step is optional. However, if you want to write more data, you need to stake AIN.
Staking is important for securing the capacity needed to write data to the blockchain. The amount of data you can record is proportional to the amount of AIN you have staked. Below is a simple code example on how to set up staking.
Step 7. Make your app public
To allow others (e.g., an echo bot) to write to your app’s paths, you need to modify the rules. By default, the write rule is:
This means only your account can write data.
To make the app public (allowing anyone to write data), change the write rule to true
. Use the setRule
function to update it.
Now, anyone can use your app! You can check the rule with getRule
function.
Advanced settings ✨
If you’re concerned about security (which you should be), you can define more specific paths and rules.
For example, you can restrict access to /apps/my_app/restricted/area/for/0xabcd...1234
so that only the holder of the private key for 0xabcd...1234
can write to it. Notice the use of wildcards for flexibility!
Step 8. Set up event listener
You can register an event listener by setting a function config to a specific path.
Once registered, a POST request will be sent to the function_url
, whenever a value is written to /apps/my_bot/messages/$user_addr/$timestamp/user
path. Since my-bot-trigger
is just a placeholder, customize it with your own trigger name.
You can check the function was set successfully using the getFunction
function.
Below is an example of a triggering value (at .../user) and a response value (at .../echo-bot) written by Echo bot. If configured correctly, the Echo bot will respond to your message by writing a value automatically.
Step 9. Write values
Everything is ready! You can now write data with the setValue
function to trigger the Echo bot function. Use the getValue
function to check the response value.
Last updated