A python module for deso
Project description
DesoPy - A python module to interact with DeSo Blockchain.
Run pip install deso
to install the module!
The module uses node.deso.org API (by default) and can be changed to any Deso node URL
by passing the argument nodeURL
to any of the classes.
For example:
import deso
desoUser = deso.User(nodeURL="https://love4src.com/api/v0/")
Developed by ItsAditya
How to Use:
Metadata
- Getting Deso Price
import deso
# takes two optional Argument; publicKey and nodeURL. By default NodeURL is https://node.deso.org/api/v0/"
desoMetadata = deso.Metadata()
response = desoMetadata.getExchangeRate() # returns a response object.
print(response.json()) # you can also use response.status_code to check if request was succesful
- Getting Node Health
import deso
desoMetadata = deso.Metadata()
print(desoMetadata.getNodeHealth().json())
- Getting App State which includes node fee, diamond level map and other info related to node
import deso
desoMetadata = deso.Metadata()
print(desoMetadata.getAppState().json())
- Getting value of each diamond
import deso
desoMetadata = deso.Metadata()
print(desoMetadata.getDiamondLevelMap()) # getDiamondLevelMap takes optional inDesoNanos argument which is by default True.
User
- Getting user profile
import deso
desoUser = deso.User()
print(desoUser.getSingleProfile(username="ItsAditya").json())
# you can set username to "" and use publicKey instead. Like: getSingleProfiel(publicKey = "BBC1YLhBLE1834FBJbQ9JU23JbPanNYMkUsdpJZrFVqNGsCe7YadYiUg")
- Getting publicKey info
import deso
desoUser = deso.User()
publicKeyList = ["BC1YLhBLE1834FBJbQ9JU23JbPanNYMkUsdpJZrFVqNGsCe7YadYiUg",
"BC1YLhGyi3t6ppCMARk3pmXGTkrSJXw3GWxQsYwQp58897ho8Nbr1it"]
print(desoUser.getUsersStateless(listOfPublicKeys=publicKeyList).json())
- Getting profile pic URL
import deso
desoUser = deso.User()
print(desoUser.getProfilePicURL(
"BC1YLhBLE1834FBJbQ9JU23JbPanNYMkUsdpJZrFVqNGsCe7YadYiUg"))
- Getting User Messages
import deso
desoUser = deso.User()
userPublicKey = "BC1YLhBLE1834FBJbQ9JU23JbPanNYMkUsdpJZrFVqNGsCe7YadYiUg"
print(desoUser.getMessagesStateless(
publicKey=userPublicKey, numToFetch=10).json())
# There are more argument in getMessagesStateless like sortAlgorithm, followersOnly, followingOnly, holdersOnly, holdingsOnly, fetchAfterPublicKey
- Getting user notifications
import deso
desoUser = deso.User()
userPublicKey = "BC1YLhBLE1834FBJbQ9JU23JbPanNYMkUsdpJZrFVqNGsCe7YadYiUg"
print(desoUser.getNotifications(userPublicKey, numToFetch=1000).json())
# There are other argument in getNotifications() like startIndex, filterOutNotificationCategories, etc.
- Getting User NFTs
import deso
desoUser = deso.User()
userPublicKey = "BC1YLhBLE1834FBJbQ9JU23JbPanNYMkUsdpJZrFVqNGsCe7YadYiUg"
print(desoUser.getNFTs(userPublicKey = userPublicKey, isForSale=True).json())
- Get derived keys of a user
import deso
desoUser = deso.User()
userPublicKey = "BC1YLhBLE1834FBJbQ9JU23JbPanNYMkUsdpJZrFVqNGsCe7YadYiUg"
print(desoUser.getDerivedKeys(userPublicKey).json())
- Getting transaction info of a user
import deso
desoUser = deso.User()
userPublicKey = "BC1YLhBLE1834FBJbQ9JU23JbPanNYMkUsdpJZrFVqNGsCe7YadYiUg"
print(desoUser.getTransactionInfo(userPublicKey).json())
# There are other arguments in getTransactionInfo() like limit, lastPublicKeyTransactionIndex and lastTransactionIDBase58Check
- Getting holders for a public key
import deso
desoUser = deso.User()
userPublicKey = "BC1YLhBLE1834FBJbQ9JU23JbPanNYMkUsdpJZrFVqNGsCe7YadYiUg"
print(desoUser.getHoldersForPublicKey(userPublicKey).json())
# There are other arugments in getHoldersForPublicKey like username, fetchAll, numToFetch, fetchHodlings, isDAOCOIN, lastPublicKey
- Getting DAO coin limit orders of a DAO coin
import deso
desoUser = deso.User()
daoCoinPublicKey = "BC1YLj3zNA7hRAqBVkvsTeqw7oi4H6ogKiAFL1VXhZy6pYeZcZ6TDRY"
print(desoUser.getDaoCoinLimitOrders(daoCoinPublicKey))
- Getting DAO coin price (market price)
import deso
desoUser = deso.User()
daoCoinPublicKey = "BC1YLj3zNA7hRAqBVkvsTeqw7oi4H6ogKiAFL1VXhZy6pYeZcZ6TDRY"
print(desoUser.getDaoCoinPrice(daoCoinPublicKey))
- Geting user followings/followers
import deso
desoUser = deso.User()
print(desoUser.getFollowsStateless(username = "ItsAditya").json())
The default behavior from the above code will return the users the account is following.
To get the list of the account's followers, you must set getFollowing to False.
print(desoUser.getFollowsStateless(username = "ItsAditya", getFollowing = False).json())
- Getting diamonds sent/received by a publicKey
import deso
desoUser = deso.User()
publicKey = "BC1YLhBLE1834FBJbQ9JU23JbPanNYMkUsdpJZrFVqNGsCe7YadYiUg"
print(desoUser.getDiamondsForPublicKey(publicKey, received=False).json())
# set received = True to get diamonds given to a publicKey
Posts
- Get posts stateless - getting info about post
import deso
desoPosts = deso.Posts()
postHashHex = "74d50e4d33b7512941a2ada91a947aecfc2f9fd179d67eb1e0008d4812597196"
print(desoPosts.getPostsStateless(postHashHex= postHashHex, numToFetch=10).json())
# There are other functions in getPostsStateless that can be used to get more information about a post.
- Get single post information
import deso
desoPosts = deso.Posts()
postHashHex = "74d50e4d33b7512941a2ada91a947aecfc2f9fd179d67eb1e0008d4812597196"
print(desoPosts.getSinglePost(postHashHex).json())
# There are other functions in getSinglePost() that can be used to get more information about a post.
- Get posts by publicKey or user
import deso
desoPosts = deso.Posts()
postHashHex = "74d50e4d33b7512941a2ada91a947aecfc2f9fd179d67eb1e0008d4812597196"
print(desoPosts.getPostsForPublicKey(username="ItsAditya").json())
# getPostsForPublicKey() has more arguments like publicKey, mediaRequired, numToFetch, lastPostHashHex, readerPublicKey etc.
- Get serials of NFT post include other info
import deso
desoPosts = deso.Posts()
postHashHex = "74d50e4d33b7512941a2ada91a947aecfc2f9fd179d67eb1e0008d4812597196"
print(desoPosts.getNFTEntriesForNFTPost(postHashHex).json())
- Get likes for post
import deso
desoPosts = deso.Posts()
postHashHex = "74d50e4d33b7512941a2ada91a947aecfc2f9fd179d67eb1e0008d4812597196"
print(desoPosts.getLikesForPost(postHashHex).json())
# getLikesForPost has more arguments like limit, offset etc.
- Get diamonds for post
import deso
desoPosts = deso.Posts()
postHashHex = "74d50e4d33b7512941a2ada91a947aecfc2f9fd179d67eb1e0008d4812597196"
print(desoPosts.getDiamondsForPost(postHashHex).json())
# getDiamondsForPost has more arguments like limit, offset etc.
- Get getQuoteRepostsForPost for post
import deso
desoPosts = deso.Posts()
postHashHex = "74d50e4d33b7512941a2ada91a947aecfc2f9fd179d67eb1e0008d4812597196"
print(desoPosts.getQuoteRepostsForPost(postHashHex).json())
# getQuoteRepostsForPost has more arguments like limit, offset etc.
- Get Hot feed/ Posts mentioning any @ username
import deso
desoPosts = deso.Posts()
print(desoPosts.getHotFeed(taggedUsername="ItsAditya").json())
- Get NFT info along with all the bids made to that NFT
import deso
desoPosts = deso.Posts()
postHashHex = "74d50e4d33b7512941a2ada91a947aecfc2f9fd179d67eb1e0008d4812597196"
print(desoPosts.getNFTBidsForNFTPost(postHashHex).json())
Social
To perform all the WRITE actions to DeSo Blockchain you need SEED_HEX and DESO Public Key.
This is how you generate SEED_HEX using your 12 word mnemonic phrase.
from deso import Identity
SEED_PHRASE = 'YOUR 12 WORD DESO SEED PHRASE'
SEED_HEX = Identity.getSeedHexFromSeedPhrase(SEED_PHRASE)
print(SEED_HEX)
You can also generate brand new DeSo seed phrase using this code.
from deso import Identity
seedPhrase = Identity.generateDesoSeedPhrase()
print(seedPhrase)
- Making post to deso blockchain
import deso
SEED_HEX = 'YOUR SEED SEED_HEX'
PUBLIC_KEY = 'YOUR PUBLIC_KEY'
desoSocial = deso.Social(PUBLIC_KEY, SEED_HEX)
'''In the above deso.Social() constructor, you can pass `derivedPublicKey` and `derivedSeedHex`
to make the transactions using derived keys.
NOTE: YOU MUST PASS ORIGINAL PUBLIC KEY TO CREATE THE TRANSACTION
''''
# submitPost() takes many optional argument like imageURLs, videoURLs, postExtraData etc.
# you will use the same function to make comment and quote any post.
print(desoSocial.submitPost("This is a test post")) #returns a response object. add .json() in end to see complete response
- Follow user
import deso
SEED_HEX = 'YOUR SEED SEED_HEX'
PUBLIC_KEY = 'YOUR PUBLIC_KEY'
desoSocial = deso.Social(nodeURL="https://diamondapp.com/api/v0/", publicKey = PUBLIC_KEY, seedHex = SEED_HEX)
print(desoSocial.follow("BC1YLhBLE1834FBJbQ9JU23JbPanNYMkUsdpJZrFVqNGsCe7YadYiUg", isFollow=True).json())
- Repost a post
import deso
SEED_HEX = 'YOUR SEED SEED_HEX'
PUBLIC_KEY = 'YOUR PUBLIC_KEY'
desoSocial = deso.Social(publicKey=PUBLIC_KEY, seedHex=SEED_HEX)
postHashHexToRepost = "bd292216e8cc1b7f2dd2cc6bba5afa20b65a4b9966ea191644c90254bedbe177"
print(desoSocial.repost(postHashHexToRepost).json())
- Quote a post
import deso
SEED_HEX = 'YOUR SEED SEED_HEX'
PUBLIC_KEY = 'YOUR PUBLIC_KEY'
desoSocial = deso.Social(publicKey=PUBLIC_KEY, seedHex=SEED_HEX)
postHashHexToQuote = "bd292216e8cc1b7f2dd2cc6bba5afa20b65a4b9966ea191644c90254bedbe177"
print(desoSocial.quote(body = "this is quoted post", postHashHexToQuote).json())
- Like a post
import deso
SEED_HEX = 'YOUR SEED SEED_HEX'
PUBLIC_KEY = 'YOUR PUBLIC_KEY'
desoSocial = deso.Social(publicKey=PUBLIC_KEY, seedHex=SEED_HEX)
postHashHex = "bd292216e8cc1b7f2dd2cc6bba5afa20b65a4b9966ea191644c90254bedbe177"
print(desoSocial.like(postHashHex, isLike=True).json())
- Diamond a post
import deso
SEED_HEX = 'YOUR SEED SEED_HEX'
PUBLIC_KEY = 'YOUR PUBLIC_KEY'
desoSocial = deso.Social(publicKey=PUBLIC_KEY, seedHex=SEED_HEX)
postHashHex = "bd292216e8cc1b7f2dd2cc6bba5afa20b65a4b9966ea191644c90254bedbe177"
receiverPublicKey = "BC1YLhBLE1834FBJbQ9JU23JbPanNYMkUsdpJZrFVqNGsCe7YadYiUg"
print(desoSocial.diamond(postHashHex, receiverPublicKey, diamondLevel=2).json())
- Update Profile
import deso
SEED_HEX = 'YOUR SEED SEED_HEX'
PUBLIC_KEY = 'YOUR PUBLIC_KEY'
desoSocial = deso.Social(publicKey=PUBLIC_KEY, seedHex=SEED_HEX)
print(desoSocial.updateProfile(FR=10, description="This is my description",
username="NotItsAditya", profilePicBase64='').json())
# In the above example, make sure profilePicBase64 is BASE64 encoded image otherwise it wont' work.
# you can also pass `extraData`, a dict argument for extra data in profile
- Send Private Message
import deso
SEED_HEX = 'YOUR SEED SEED_HEX'
PUBLIC_KEY = 'YOUR PUBLIC_KEY'
desoSocial = deso.Social(publicKey=PUBLIC_KEY, seedHex=SEED_HEX)
receiverPublicKey = "BC1YLhBLE1834FBJbQ9JU23JbPanNYMkUsdpJZrFVqNGsCe7YadYiUg"
print(desoSocial.sendPrivateMessage(receiverPublicKey, "This DM is send using DesoPy library").json())
- Minting a postHashHex as NFT
import deso
SEED_HEX = 'YOUR SEED SEED_HEX'
PUBLIC_KEY = 'YOUR PUBLIC_KEY'
desoSocial = deso.Social(publicKey=PUBLIC_KEY, seedHex=SEED_HEX)
postHashHex = "bd292216e8cc1b7f2dd2cc6bba5afa20b65a4b9966ea191644c90254bedbe177"
print(desoSocial.mint(postHashHex, minBidDeSo=1, copy=2, creatorRoyality=10, coinHolderRoyality=4, isForSale=True).json())
- Updating NFT to put it on sale, or as buy now etc.
import deso
SEED_HEX = 'YOUR SEED SEED_HEX'
PUBLIC_KEY = 'YOUR PUBLIC_KEY'
desoSocial = deso.Social(publicKey=PUBLIC_KEY, seedHex=SEED_HEX)
postHashHex = "bd292216e8cc1b7f2dd2cc6bba5afa20b65a4b9966ea191644c90254bedbe177"
print(desoSocial.updateNFT(postHashHex, buyNowPriceInDeso=2,
buyNow=True, minBidDeso=1.5, forSale=2, serialNumber=1).json())
- Burn an NFT
import deso
SEED_HEX = 'YOUR SEED SEED_HEX'
PUBLIC_KEY = 'YOUR PUBLIC_KEY'
desoSocial = deso.Social(publicKey=PUBLIC_KEY, seedHex=SEED_HEX)
postHashHex = "bd292216e8cc1b7f2dd2cc6bba5afa20b65a4b9966ea191644c90254bedbe177"
print(desoSocial.burnNFT(postHashHex, serialNumber=2).json())
- Create NFT Bid
import deso
SEED_HEX = 'YOUR SEED SEED_HEX'
PUBLIC_KEY = 'YOUR PUBLIC_KEY'
desoSocial = deso.Social(publicKey=PUBLIC_KEY, seedHex=SEED_HEX)
postHashHex = "bd292216e8cc1b7f2dd2cc6bba5afa20b65a4b9966ea191644c90254bedbe177"
print(desoSocial.createNFTBid(NFTPostHashHex=postHashHex, serialNumber=1, bidAmountDeso=2).json())
- Transfer NFT
import deso
SEED_HEX = 'YOUR SEED SEED_HEX'
PUBLIC_KEY = 'YOUR PUBLIC_KEY'
desoSocial = deso.Social(publicKey=PUBLIC_KEY, seedHex=SEED_HEX)
postHashHex = "bd292216e8cc1b7f2dd2cc6bba5afa20b65a4b9966ea191644c90254bedbe177"
receiverPublicKey = "BC1YLhBLE1834FBJbQ9JU23JbPanNYMkUsdpJZrFVqNGsCe7YadYiUg"
print(desoSocial.transferNFT(postHashHex, receiverPublicKey, serialNumber=1).json())
Deso Identity
- Getting JWT token
import deso
SEED_HEX = 'YOUR SEED SEED_HEX'
PUBLIC_KEY = 'YOUR PUBLIC_KEY'
desoIdentity = deso.Identity(publicKey=PUBLIC_KEY, seedHex=SEED_HEX)
print(desoIdentity.getJWT())
- Validate JWT token
import deso
desoIdentity = deso.Identity()
jwt_tokenn = "" # JWT TOKEN TO VALIDATE
userPublicKey = "" # User's public Key whoose JWT you wanna validate
print(desoIdentity.validateJWT(JWT=jwt_token, publicKey=userPublicKey))
- Sign transaction (OFFLINE OBVIOUSLY)
import deso
SEED_HEX = 'YOUR SEED SEED_HEX'
transactionHex = " Transaction Hex of the transaction created by public Key"
desoIdentity = deso.Identity()
print(desoIdentity.signTransaction(seedHex = SEED_HEX, transactionHex=transactionHex))
Media
- Upload image to images.deso.org
import deso
SEED_HEX = 'YOUR SEED SEED_HEX'
PUBLIC_KEY = 'YOUR PUBLIC_KEY'
desoMedia = deso.Media( PUBLIC_KEY, SEED_HEX)
imageFileList = [
('file', ('screenshot.jpg', open("img.png", "rb"), 'image/png'))
] # 'img.png' is the image we are uploading to images.bitclout.com
urlResponse = desoMedia.uploadImage(imageFileList)
print(urlResponse.json())
Trade
- Send deso to public Key
import deso
SEED_HEX = 'YOUR SEED SEED_HEX'
PUBLIC_KEY = 'YOUR PUBLIC_KEY'
desoTrade = deso.Trade(PUBLIC_KEY, SEED_HEX )
print(desoTrade.sendDeso( recieverPublicKeyOrUsername = "BC1YLhBLE1834FBJbQ9JU23JbPanNYMkUsdpJZrFVqNGsCe7YadYiUg", desoToSend = 0.01).json())
- Buy creator coin
import deso
SEED_HEX = 'YOUR SEED SEED_HEX'
PUBLIC_KEY = 'YOUR PUBLIC_KEY'
desoTrade = deso.Trade(PUBLIC_KEY, SEED_HEX)
creatorPublicKey = "BC1YLhBLE1834FBJbQ9JU23JbPanNYMkUsdpJZrFVqNGsCe7YadYiUg"
print(desoTrade.buyCreatorCoin(creatorPublicKey=creatorPublicKey, desoAmountToBuy=2).json())
- get creator coins held by a publicKey
import deso
desoTrade = deso.Trade()
creatorPublicKey = "BC1YLhBLE1834FBJbQ9JU23JbPanNYMkUsdpJZrFVqNGsCe7YadYiUg"
print(desoTrade.getHeldCoinsOfCreator(publicKeyOfCoin=creatorPublicKey).json())
- Get selling amount of a creator coin
import deso
desoTrade = deso.Trade()
coinsInCirculationNanos = 3857329848
balanceNanons = 34938
desoLockedNanos = 12948584035
print(desoTrade.amountOnSell(desoLockedNanos = desoLockedNanos, coinsInCirculation=coinsInCirculationNanos, balanceNanos=balanceNanos))
- Selling a creator coin
import deso
SEED_HEX = 'YOUR SEED SEED_HEX'
PUBLIC_KEY = 'YOUR PUBLIC_KEY'
desoTrade = deso.Trade(PUBLIC_KEY, SEED_HEX)
coinsToSellNanons = 34938
creatorPublicKey = "BC1YLhBLE1834FBJbQ9JU23JbPanNYMkUsdpJZrFVqNGsCe7YadYiUg"
print(desoTrade.sellCreatorCoin(
creatorPublicKey=creatorPublicKey, coinsToSellNanos=coinsToSellNanons).json())
- Send creator coin
import deso
SEED_HEX = 'YOUR SEED SEED_HEX'
PUBLIC_KEY = 'YOUR PUBLIC_KEY'
desoTrade = deso.Trade(PUBLIC_KEY, SEED_HEX)
coinsToSendNanos = 34938
creatorPublicKey = "BC1YLhBLE1834FBJbQ9JU23JbPanNYMkUsdpJZrFVqNGsCe7YadYiUg"
print(desoTrade.sendCreatorCoins(creatorPublicKey=creatorPublicKey,
receiverUsernameOrPublicKey="Octane", creatorCoinNanosToSend=coinsToSendNanos).json())
- Send DAO coins
import deso
SEED_HEX = "Your seed Hex here"
PUBLIC_KEY = "Your public key"
'''Sends DAO coin to publicKey or username. Use the hex() function to convert a number to hexadecimal
for Example, if you want to send 15 DAO coin, set coinsToTransfer to hex(int(15*1e18))'''
desoTrade = deso.Trade(publicKey=PUBLIC_KEY, seedHex=SEED_HEX)
coinsToTransfer = 15
coinsToTransferInRequiredForamt = hex(int(coinsToTransfer * 1e18))
transferStatus = desoTrade.sendDAOCoins(coinsToTransfer=coinsToTransferInRequiredForamt,
daoPublicKeyOrName="CockyClout", receiverPublicKeyOrUsername="ItsAditya")
print(transferStatus)
- Burn DAO coins
import deso
SEED_HEX = "Your seed Hex here"
PUBLIC_KEY = "Your public key"
'''Burns DAO coin of daoPublicKeyOrName. Use the hex() function to convert a number to hexadecimal
for Example, if you want to burn 15 DAO coin, set coinsToBurn to hex(int(15*1e18))'''
desoTrade = deso.Trade(publicKey=PUBLIC_KEY, seedHex=SEED_HEX)
coinsToBurn = 5000000
coisToBurnInRequiredFormat = hex(int(coinsToBurn * 1e18))
burnStatus = desoTrade.burnDAOCoins(coinsToBurn=coisToBurnInRequiredFormat,
daoPublicKeyOrName="CockyClout")
print(burnStatus)
- Mint DAO coins
import deso
SEED_HEX = "Your seed Hex here"
PUBLIC_KEY = "Your public key"
'''Mint DAO coins. Use the hex() function to convert a number to hexadecimal
for Example, if you want to mint 15 DAO coin, set coinsToBurn to hex(int(15*1e18))'''
desoTrade = deso.Trade(publicKey=PUBLIC_KEY, seedHex=SEED_HEX)
coinsToMint = 1000000
coinsToBurnInRequiredFormat = hex(int(coinsToMint * 1e18))
mintStatus = desoTrade.mintDAOCoins(coinsToBurnInRequiredFormat)
print(mintStatus)
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
File details
Details for the file deso-2.3.6.tar.gz
.
File metadata
- Download URL: deso-2.3.6.tar.gz
- Upload date:
- Size: 24.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.10.8
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | a79f0020e0af4d1c6774f723a07bf9deb42f2fb713c09c1a546175eeeaca0970 |
|
MD5 | 7ba4a40726522172f4500c6b7eb8a551 |
|
BLAKE2b-256 | 5cdae4f5a0706536d9946878d24dc12b6cf36456982bc3c59eb125a3510142f8 |