# CW721 Tokens
Paloma.py enables developers to create and interact with the Cosmos version of NFTs - CW721 tokens (opens new window) without knowing Rust. The SDK allows you to bypass learning CosmWasm and simply staying in Python.
There are 9 functions for CW721 that are implemented in paloma.py.
# instantiate()
Create a new CW721 by instantiating a CW721 smart contract. You'll need the the code id of a deployed CW20 compatible wasm code You can find the deployed CW721 compatible contracts in the resource section. You may also upload your own contract and use that instead. See the smart contract documentation for more details. As CW721 creator, you'll choose the name, symbol and the total supply amount which is minted to deployer wallet.
Arguments:
wallet
(Paloma address): CW721 deployer wallet addresscode_id
(int): Code_id of CW721 wasm codename
(str): CW721 token namesymbol
(str): CW721 token symbolminter
CW721 token minterdecimals
(int): CW721 token decimalstotal_supply
(int): CW721 token total supply
Returns: BlockTxBroadcastResult: Transaction Broadcast Result
# mint()
With this function you will be able to mint the NFTs
Arguments:
wallet
(Paloma address): CW721 sender wallet addresstoken
(str): CW721 token addresstoken_id
(str): CW721 token idowner
(str): owner who will receive the CW721 tokentoken_uri
(str): URI of the minting token used to construct the metadata
Returns: BlockTxBroadcastResult: Transaction Broadcast Result
# approve()
This allows the spender
to transfer or send the token from the owner's account. If expires
is set, then this allowance expires at the time/height limit.
Arguments:
wallet
(Paloma address): CW721 owner wallet addresstoken
(str): CW721 token addressspender
(str): the address who will get permission to the CW721 tokentoken_id
(str): token id of the CW721 tokenexpires
: (dict, optional) {"at_height": height(u64)} / {"at_time":timestamp(nanosecond, u64)}
Returns: BlockTxBroadcastResult: Transaction Broadcast Result
# revoke()
Removes previously granted approval from the spender
.
Arguments:
wallet
(Paloma address): CW721 sender wallet addressstoken
(str): token addressspender
(str): approved address for which approval should be revokedtoken_id
(str): CW721 token id
Returns BlockTxBroadcastResult: Transaction Broadcast Result
# approve_all()
This function allows an operator
to transfer or send any available token from the owner's account. If expires
is set, then this allowance has a time/height limit
Arguments:
wallet
(Paloma address): CW721 sender wallet addresstoken
(str): CW721 token addressoperator
(str): the address who will get permission to the CW721 tokensexpires
: (dict, optional) {"at_height": height(u64)} / {"at_time":timestamp(nanosecond, u64)}
Returns: BlockTxBroadcastResult: Transaction Broadcast Result
# revoke_all()
Removes previously granted approval from the operator
.
Arguments:
wallet
(Paloma address): CW721 sender wallet addresstoken
(str): CW721 token addressoperator
(str): approved address for which approval should be revoked
Returns: BlockTxBroadcastResult: Transaction Broadcast Result
# transfer_nft()
Allows to send a CW721 NFT token to another address
Arguments:
wallet
(Paloma address): CW721 sender wallet addresstoken
(str): CW721 token addressrecipient
(str): token receiver addresstoken_id
(str): token id
Returns: BlockTxBroadcastResult: Transaction Broadcast Result
# send_nft()
This function allows you to send a CW721 token to a CW721 compatible contract along with a message.
Arguments:
wallet
(Paloma address): CW721 sender wallet addresstoken
(str): CW721 token addresscontract
(str): token receiver contract addresstoken_id
(str): token idmsg
(str): base64 encoded message
Returns: BlockTxBroadcastResult: Transaction Broadcast Result
# burn()
This removes a specific CW721 token.
Arguments:
wallet
(Paloma Address): wallet from which the tokens should be removedtoken
(str): CW721 token addresstoken_id
(str): token id to be burnt
Returns: BlockTxBroadcastResult: Transaction Broadcast Result
# Example
See the example below for a sample use of the available functions.
import asyncio
from pathlib import Path
import uvloop
from terra_proto.cosmwasm.wasm.v1 import AccessType
from paloma_sdk.client.lcd import AsyncLCDClient
from paloma_sdk.client.lcd.api.tx import CreateTxOptions
from paloma_sdk.core.wasm import MsgInstantiateContract, MsgStoreCode
from paloma_sdk.key.mnemonic import MnemonicKey
from paloma_sdk.core.wasm.data import AccessConfig
from paloma_sdk.util.contract import get_code_id, get_contract_address, read_file_as_b64
async def main():
paloma = AsyncLCDClient(url="https://lcd.testnet.palomaswap.com/", chain_id="paloma-testnet-16")
paloma.gas_prices = "0.01ugrain"
# test1 = paloma.wallets["test1"]
acc = MnemonicKey(
mnemonic="notice oak worry limit wrap speak medal online prefer cluster roof addict wrist behave treat actual wasp year salad speed social layer crew genius"
)
acc2 = MnemonicKey(
mnemonic="index light average senior silent limit usual local involve delay update rack cause inmate wall render magnet common feature laundry exact casual resource hundred"
)
test1 = paloma.wallet(acc)
test2 = paloma.wallet(acc2)
# print(test1.key.acc_address)
store_code_tx = await test1.create_and_sign_tx(
CreateTxOptions(
msgs=[
MsgStoreCode(
test1.key.acc_address,
read_file_as_b64(Path(__file__).parent / "./cw721_base.wasm"),
AccessConfig(AccessType.ACCESS_TYPE_EVERYBODY, ""),
)
]
)
)
store_code_tx_result = await paloma.tx.broadcast(store_code_tx)
print(store_code_tx_result)
code_id = get_code_id(store_code_tx_result)
# code_id = 1
print(f"code_id:{code_id}")
result = await paloma.cw721.instantiate(
test1, code_id, "CW721 Token", "CWFT", test1.key.acc_address
)
print(result)
contract_address = result.logs[0].events_by_type["instantiate"][
"_contract_address"
][0]
print(contract_address)
result = await paloma.cw721.mint(
test1, contract_address, "1", test1.key.acc_address, "test uri"
)
print(result)
result = await paloma.cw721.approve(
test1, contract_address, test2.key.acc_address, "1"
)
print(result)
result = await paloma.cw721.revoke(
test1, contract_address, test2.key.acc_address, "1"
)
print(result)
result = await paloma.cw721.approve_all(
test1, contract_address, test2.key.acc_address
)
print(result)
result = await paloma.cw721.revoke_all(
test1, contract_address, test2.key.acc_address
)
print(result)
result = await paloma.cw721.transfer_nft(
test1, contract_address, test2.key.acc_address, "1"
)
print(result)
result = await paloma.cw721.burn(
test2, contract_address, "1"
)
print(result)
await paloma.session.close()
uvloop.install()
asyncio.run(main())