Get Started or Add to an Existing Project
Getting started with Kin is incredibly straightforward. Just follow the steps below to start transacting with Kin in your app.
Installation
pip install kinetic-sdk
Instantiate the Kinetic Client
The Kinetic Client will give you access to all the methods you need to work with Kin on the blockchain.
We recommend starting with Devnet before moving on to Mainnet.
from kinetic_sdk import KineticSdk
kinetic_client = KineticSdk.setup(
environment='devnet', # the name of your environment, e.g. devnet, mainnet,
index=1, # your App Index
endpoint='https://sandbox.kinetic.host', # devnet endpoint
)
Don't have an App Index? Register your app on our Developer Portal so you can get your App Index that allows you to transact with our SDKs and earn via the KRE.
Register Your App
Learn how to register your app on the Kin Developer Portal
Kin Dev Portal
Go straight to the Kin Developer Portal and get started
While you're waiting for confirmation of your App Index, use 1
on devnet so you can get started.
Create Account
You can create accounts randomly or from existing mnemonics or secret keys. Below, we'll make a keypair and use that for creating an account on the blockchain.
You can also generate keypairs and create accounts on devnet via the Kin Laboratory.
from kinetic_sdk import Commitment
from kinetic_sdk.keypair import Keypair
mnemonic = Keypair.generate_mnemonic()
keypair = Keypair.from_secret(mnemonic)
# or keypair = Keypair.random()
kinetic_client.create_account(
owner=keypair,
commitment=Commitment('Finalized'), # Optional: "Confirmed", "Finalized", "Processed"
)
Close Account
It's good practice to close unneeded accounts. You can only close accounts that you have created and are currently empty.
from kinetic_sdk import Commitment
kinetic_client.close_account(
account=keypair.public_key,
commitment=Commitment('Finalized'), # Optional: "Confirmed", "Finalized", "Processed"
)
Check Balance
Check a user balance by passing in the public key of the account you want to check.
The response object includes your total Kin balance as well as detailing all of the Mints and Tokens held by that Public Key.
balance = kinetic_client.get_balance(account=keypair.public_key)
Airdrop Funds (devnet)
Send some test funds to a specific Public Key on Devnet.
Or visit the Kin Laboratory to do it with a click!
from kinetic_sdk import Commitment
airdrop = kinetic_client.request_airdrop(
account=keypair.public_key,
amount='1000',
commitment=Commitment('Finalized'), # Optional: "Confirmed", "Finalized", "Processed"
)
Transfer Kin
Transfer Kin from a Keypair to any Public Key.
Make sure to include your Transaction Type if you want it to count towards the KRE.
from kinetic_sdk import Commitment
from kinetic_sdk.models.transaction_type import TransactionType
transfer = kinetic_client.make_transfer(
amount='5000',
destination='BQJi5K2s4SDDbed1ArpXjb6n7yVUfM34ym9a179MAqVo',
owner=keypair,
commitment=Commitment('Finalized'), # Optional: "Confirmed", "Finalized", "Processed"
tx_type=TransactionType.P2P, # Optional, can be Unknown, None, Earn, Spend or P2P
reference='some reference', # Optional, stored off-chain and returned via webhooks
sender_create=False # Optional, will make a Kin Token Account at that destination if true
)
Note - reference
is stored off chain and will be passed back to the app via webhooks if they are set up.
Transfer Kin Batch
Make a batch transfer of Kin.
from kinetic_sdk import Commitment
destinations = []
destinations.append(
{
'amount': '500',
'destiation': 'BQJi5K2s4SDDbed1ArpXjb6n7yVUfM34ym9a179MA123'
})
destinations.append(
{
'amount': '600',
'destiation': 'BQJi5K2s4SDDbed1ArpXjb6n7yVUfM34ym9a179MA456'
})
destinations.append(
{
'amount': '700',
'destiation': 'BQJi5K2s4SDDbed1ArpXjb6n7yVUfM34ym9a179MA789'
})
batch_transfer = kinetic_client.make_transfer_batch(
owner=keypair,
destinations=destinations,
commitment=Commitment('Finalized'), # Optional: "Confirmed", "Finalized", "Processed"
reference_id='some id', # Optional, stored off-chain and returned via webhooks
reference_type='some reference', # Optional, stored off-chain, returned via webhooks
sender_create=False # Optional, will make a Kin Token Account at that destination
)
Get Transaction Details
Get the details of any transaction by passing in the transaction signature.
transaction = kinetic_client.get_transaction(signature='transaction id string')
Get Solana Explorer URL
explorer_url = kinetic_client.get_explorer_url('transaction id string')
Get Account History
Get the full transaction history of any account by passing in the account's Public Key.
history = kinetic_client.get_history(account=keypair.publicKey)
Get Account Info
Easily get the main info of any account by passing in the account's Public Key.
account_info = kinetic_client.get_account_info(account=keypair.publicKey)
Get Token Accounts
Get the full list of Token Accounts held by a Keypair on Solana.
token_accounts = kinetic_client.get_token_accounts(account=keypair.publicKey)
Webhooks
Whether you are using Kinetic As A Service or Self-Hosting to connect to Kinetic, once you're up and running, you'll be able to access Kinetic Manager to manage your app's settings.
This includes allowing you to configure your app to use a number of webhooks.
Balance Webhook
The balance webhook allows you to receive an alert when your app's hotwallet is running low on Sol so you can top it up and ensure your app can continue to keep transacting.
E.g. In a python server:
@cross_origin()
@app.route('/balance', methods=['POST'])
def events():
print('request_body: ', request.body)
# DO STUFF WITH BALANCE ALERT
response = '', 200
return response
Event Webhook
The event webhook allows you to receive alerts when actions have been confirmed on the Solana blockchain.
E.g. In a python server:
@cross_origin()
@app.route('/events', methods=['POST'])
def events():
print('request_body: ', request.body)
# DO STUFF WITH EVENT DATA
response = '', 200
return response
Verify Webhook
The verify webhook allows you to have fine-grained control over transactions, making sure they meet your own criteria before allowing them to proceed.
E.g. In a python server return a 200
status code to approve the transaction or a 400
to reject it:
@cross_origin()
@app.route('/verify', methods=['POST'])
def events():
print('request_body: ', request.body)
# CHECK THAT YOU WANT THIS TRANSACTION TO PROCEED
# Return 200 if you do
response = '', 200
return response
Demos and Starter Kits
Created to help get you up and running as quickly as possible, these projects can be a great reference point when you get stuck or even a starter for your own project. Happy coding!
Kinetic Python Starter
This starter shows how to implement a simple API that allows you to send KIN to a Solana account using Kinetic.
Kinetic Python Demo Server
A full-fat server based implementation of Kin Kinetic.
This server is compatible with the Kinetic Playground Front End.
Ready for Production?
If your app is ready for production, this is the place for you!
Production
Get your app ready and running on the Solana Mainnet so you can earn Kin via the KRE
Earn Kin via the KRE
Kin Rewards Engine
Earn Kin by using it in your App
Contribute
Kinetic Python SDK
Want to contribute to the Kinetic Python SDK?
What If I Get Stuck?
Getting Help
Stuck? No problem, we have an amazing community waiting to help out.
Developer Discord
Join our fantastic developer community.
Developer Best Practices
Once you're ready to code, have a quick look at our Developer Best Practices where we cover some useful topics that you'll want to keep in mind as you build out your Kin application.
Best Practices
Some key information you'll want to keep in mind as you develop your App
Upgrading to Kinetic from Agora?
Upgrading to Kinetic
Here's some extra info that will help you complete your upgrade.
Agora
Prior to the release of Kinetic, our Kin SDKs were powered by a now-deprecated technology called Agora. Check out our old docs site if you want to see more.
Here, we will outline the key API changes from the old version of our SDK to the new Kinetic version.
General notes
- For methods that request Kin be transferred,
amount
is the amount of Kin, not quarks. - Response objects from requests have updated / changed.
Instantiate the Kin Client
# Kinetic
from kinetic_sdk import KineticSdk
kinetic_client = KineticSdk.setup(
environment='devnet', # the name of your environment, e.g. devnet, mainnet,
index=1, # your App Index
endpoint='https://sandbox.kinetic.host', # devnet endpoint
)
# Agora
from agora.client import Client, Environment
env = Environment.TEST
app_index = 1
kin_client = Client(env, app_index)
Create Account
# Kinetic
from kinetic_sdk import Commitment
from kinetic_sdk.keypair import Keypair
mnemonic = Keypair.generate_mnemonic()
keypair = Keypair.from_secret(mnemonic) # or Keypair.random()
account = kinetic_client.create_account(
owner=keypair,
commitment=Commitment('Finalized'), # Optional: "Confirmed", "Finalized", "Processed"
)
# Agora
from agora.keys import PrivateKey
private_key = PrivateKey.random()
account = kin_client.create_account(private_key)
Check Balance
# Kinetic
balance = kinetic_client.get_balance(account=keypair.public_key)
# Agora
balance = kin_client.get_balance(public_key)
Airdrop Funds (devnet)
# Kinetic
from kinetic_sdk import Commitment
airdrop = kinetic_client.request_airdrop(
account=keypair.public_key,
amount='1000',
commitment=Commitment('Finalized'), # Optional: "Confirmed", "Finalized", "Processed"
)
# Agora
from agora.utils import kin_to_quarks
token_account='kin token account for that keypair'
amount = '1000'
quarks = kin_to_quarks(amount)
airdrop = kin_client.request_airdrop(token_account, quarks)
Transfer Kin
# Kinetic
from kinetic_sdk import Commitment
from kinetic_sdk.models.transaction_type import TransactionType
transfer = kinetic_client.make_transfer(
amount='5000',
destination='BQJi5K2s4SDDbed1ArpXjb6n7yVUfM34ym9a179MAqVo',
owner=keypair,
commitment=Commitment('Finalized'), # Optional: "Confirmed", "Finalized", "Processed"
tx_type=TransactionType.P2P, # Optional, can be Unknown, None, Earn, Spend or P2P
reference_id='some id', # Optional, stored off-chain and returned via webhooks
reference_type='some reference', # Optional, stored off-chain and returned via webhooks
sender_create=False # Optional, will make a Kin Token Account at that destination if true
)
# Agora
from agora.model import Payment, TransactionType
from agora.utils import kin_to_quarks
sender = some_private_key
destination = some_public_key
transaction_type = TransactionType.P2P
amount = '1000'
quarks = kin_to_quarks(amount)
payment = Payment(sender, destination, transaction_type, quarks)
transfer = kin_client.submit_payment(payment)
# The Agora invoice option has been replaced by 'reference'
Transfer Kin Batch
# Kinetic
from kinetic_sdk import Destination, Commitment
destinations = []
destinations.append(
{
'amount': '500',
'destiation': 'BQJi5K2s4SDDbed1ArpXjb6n7yVUfM34ym9a179MA123'
})
destinations.append(
{
'amount': '600',
'destiation': 'BQJi5K2s4SDDbed1ArpXjb6n7yVUfM34ym9a179MA456'
})
destinations.append(
{
'amount': '700',
'destiation': 'BQJi5K2s4SDDbed1ArpXjb6n7yVUfM34ym9a179MA789'
})
batch_transfer = kinetic_client.make_transfer_batch(
owner=keypair,
destinations=destinations,
commitment=Commitment('Finalized'), # Optional: "Confirmed", "Finalized", "Processed"
reference_id='some id', # Optional, stored off-chain and returned via webhooks
reference_type='some reference', # Optional, stored off-chain, returned via webhooks
sender_create=False # Optional, will make a Kin Token Account at that destination
)
# Agora
from agora.model import Payment, TransactionType, Earn, EarnBatch
earns = []
earns.append(
Earn('BQJi5K2s4SDDbed1ArpXjb6n7yVUfM34ym9a179MA123', kin_to_quarks('500'))
)
earns.append(
Earn('BQJi5K2s4SDDbed1ArpXjb6n7yVUfM34ym9a179MA456', kin_to_quarks('600'))
)
earns.append(
Earn('BQJi5K2s4SDDbed1ArpXjb6n7yVUfM34ym9a179MA789', kin_to_quarks('700'))
)
sender = some_private_key
batch = EarnBatch(sender, earns)
batch_transfer = kin_client.submit_earn_batch(earns)
Get Transaction Details
# Kinetic
transaction = kinetic_client.get_transaction(signature='transaction id string')
# Agora
import base58
decoded = base58.b58decode('transaction_id')
transaction = kin_client.get_transaction(decoded)
Webhooks
In Agora, we used the sign_transaction
webhook. That's been deprecated and we now have the verify
webhook that can simply return a 200 status code to confirm verification of a request.
Was this page helpful to you?
Provide feedback