Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def swap(klaytn_api, public_key, eth_amount, usdt_amount):
- """ Uses the KlaySwap Protocol smart contract
- (address: 0xc6a2ad8cc6e4a7e08fc37cc5954be07d499e7654) to make a swap of
- ETH vs USDT.
- """
- # This is the web3.py client.
- w3py = Web3Client(provider=MAINNET, public_key=public_key)
- trade_contract = w3py.w3.eth.contract(
- abi=w3py.swap_contract_ABI, address=w3py.ksp_contract_address)
- # Get the encoded hash of the contract's function and its parameters.
- contract_data = w3py.trade_contract.encodeABI(
- fn_name="exchangeKctNeg",
- args=[
- w3py.kusdt_contract_address,
- usdt_amount,
- w3py.keth_contract_address,
- eth_amount,
- []
- ]
- )
- # Construct a TxTypeSmartContractExecution object for Klaytn.
- sc_tx = {
- "type": '0x30',
- "nonce": klaytn_api.account.get_transaction_count(),
- "gasPrice": klaytn_api.configuration.gas_price(),
- "gas": w3py.w3.toHex(5000000),
- "from": public_key,
- "to": w3py.kethusdt_contract_address,
- "data": contract_data
- }
- # Run the contract on Klaytn and get the result.
- result = klaytn_api.transaction.call(sc_tx)
- return result
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement