Skip to content

Instantly share code, notes, and snippets.

@laalaguer
Created August 24, 2021 03:40
Show Gist options
  • Save laalaguer/844d9f8286e97242687b4f49ca651957 to your computer and use it in GitHub Desktop.
Save laalaguer/844d9f8286e97242687b4f49ca651957 to your computer and use it in GitHub Desktop.
Over Transfer VTHO using transfer() method
from thor_requests.connect import Connect
from thor_requests.wallet import Wallet
connector = Connect("https://sync-testnet.vechain.org")
# wallet address: 0x7567d83b7b8d80addcb281a71d54fc7b3364ffed
_wallet = Wallet.fromPrivateKey(bytes.fromhex("dce1443bd2ef0c2631adc1c67e5c93f13dc23a41c18b536effbbdcbcdb96fb65"))
# View the vtho this wallet has (in Wei):
vtho_balance = connector.get_vtho_balance(_wallet.getAddress())
# transfer more vtho (110%) over what this account has out to 0x000...
connector.transfer_vtho(_wallet, to="0x0000000000000000000000000000000000000000", vtho_in_wei=int(vtho_balance * 1.1))
# Exception: Tx will revert: [{'data': '0x08c379a00000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000001d6275696c74696e3a20696e73756666696369656e742062616c616e6365000000',
#'events': [], 'transfers': [], 'gasUsed': 1071, 'reverted': True,
# 'vmError': 'evm: execution reverted', 'decoded': {'revertReason': 'builtin: insufficient balance'}}]
@laalaguer
Copy link
Author

解释:
唯链特性:VTHO 合约是一个ERC20合约,但是它本身实现方法是节点程序自带的Go语言实现的。有固定的合约地址。
实现过程中,transfer()方法在过量的时候返回了 revert 和 revertReason,所以不用safeTransfer()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment