Skip to content

This repository contains smart contract demo to interact with celo-blockchain

Notifications You must be signed in to change notification settings

Tero-Labs/smart-contract-demo

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

16 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Smart Contract Demo

This repository contains smart contract demo to interact with celo-blockchain.

The Python Demo uses the Python ContractKit developed by Blaize Tech.

Some lending pool configuration parameters have been tweaked in the JS Demo to fetch user account data.

Getting Started: Python Demo

To install:

pip install .

You need in Python version 3.8 or higher.

To start working with python contractkit you need a Kit instance:

from celo_sdk.kit import Kit

kit = Kit('https://alfajores-forno.celo-testnet.org')

To access web3:

kit.w3.eth.getBalance(some_address)

Setting Default Tx Options

Kit allows you to set default transaction options:

from celo_sdk.kit import Kit

kit = Kit('https://alfajores-forno.celo-testnet.org')
currency_address = kit.base_wrapper.registry.load_contract_by_name('StableToken')['address']
kit.wallet_fee_currency = currency_address

Interacting with CELO & cUSD

celo-blockchain has two initial coins: CELO and cUSD (stableToken). Both implement the ERC20 standard, and to interact with them is as simple as:

gold_token = kit.base_wrapper.create_and_get_contract_by_name('GoldToken')
balance = gold_token.balance_of(address)

To send funds:

one_gold = kit.w3.toWei(1, 'ether')
tx_hash = gold_token.transfer(address, one_gold)

To interact with cUSD, is the same but with a different contract:

stable_token = kit.base_wrapper.create_and_get_contract_by_name('StableToken')

If you would like to pay fees in cUSD, set the gas price manually:

stable_token = kit.base_wrapper.create_and_get_contract_by_name('StableToken')
gas_price_contract = kit.base_wrapper.create_and_get_contract_by_name('GasPriceMinimum')
gas_price_minimum = gas_price_contract.get_gas_price_minimum(stable_token.address)
gas_price = int(gas_price_minimum * 1.3) # Wiggle room if gas price minimum changes before tx is sent
kit.wallet_fee_currency = stable_token.address # Default to paying fees in cUSD
kit.wallet_gas_price = gas_price

tx = stable_token.transfer(recipient, wei_transfer_amount)

About

This repository contains smart contract demo to interact with celo-blockchain

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published