# CW20 Tokens
Paloma.py enables developers to create and interact with CW20 tokens (opens new window) without knowing Rust. The SDK allows you to bypass learning CosmWasm and simply staying in Python.
There are 4 functions for CW20 that are implemented in paloma.py.
# instantiate()
Create a new CW20 by instantiating a CW20 smart contract. You'll need the the code id of a deployed CW20 compatible wasm code. You can find the deployed CW20 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 CW20 creator, you'll choose the name, symbol and the total supply amount which is minted to deployer wallet.
Arguments:
wallet
(Paloma address): CW20 deployer wallet addresscode_id
(int): Code_id of CW20 wasm codename
(str): CW20 token namesymbol
(str): CW20 token symboldecimals
(int): CW20 token decimalstotal_supply
(int): CW20 token total supply
Returns: BlockTxBroadcastResult: Transaction Broadcast Result
# send()
This function allows you to send an amount
of an existing CW20 token to a CW20 compatible contract along with a message.
Arguments:
wallet
(Paloma address): CW20 sender wallet addresstoken
(str): CW20 token addresscontract
(str): token receiver contract addressamount
(str): send amountmsg
(str): base64 encoded message
Returns: BlockTxBroadcastResult: Transaction Broadcast Result
# transfer()
With the transfer function, you can send any amount of an existing CW20 token to another wallet address.
Arguments:
wallet
(Paloma address): CW20 sender wallettoken
(str): CW20 token addressrecipient
(str): token receiver addressamount
(str): send amount
Returns: BlockTxBroadcastResult: Transaction Broadcast Result
# burn()
This removes amount
CW20 tokens from the balance of the specified wallet and reduces the total supply by the same amount.
Arguments:
wallet
(Paloma Address): wallet from which the tokens should be removedtoken
(str): CW20 token addressamount
(str): amount 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 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, read_file_as_b64
async def main():
paloma = AsyncLCDClient(url="https://lcd.testnet.palomaswap.com/", chain_id="paloma-testnet-13")
paloma.gas_prices = "0.01ugrain"
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)
store_code_tx = await test1.create_and_sign_tx(
CreateTxOptions(
msgs=[
MsgStoreCode(
test1.key.acc_address,
read_file_as_b64(Path(__file__).parent / "./cw20_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)
print(f"code_id:{code_id}")
result = await paloma.cw20.instantiate(
test1, code_id, "CW20 Token", "CWFT", 9, 1_000_000_000_000_000
)
print(result)
contract_address = result.logs[0].events_by_type["instantiate"][
"_contract_address"
][0]
print(contract_address)
result = await paloma.cw20.transfer(
test1, contract_address, test2.key.acc_address, 1_000_000_000
)
print(result)
result = await paloma.cw20.burn(
test1, contract_address, 500_000_000
)
print(result)
await paloma.session.close()
uvloop.install()
asyncio.run(main())