CW20 Tokens | Official Paloma Protocol Documentation

CW20 Tokens

Paloma.py enables developers to create and interact with CW20 tokens 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 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:

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:

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:

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:

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"].get("_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())