sdk
sdk copied to clipboard
Difference between one and 0x address when calling transfer and contract methods respectively.
Two functions: one to transfer ONE tokens and the other to transfer HRC-20 (HRC) smart contract tokens.
I feel like developers will have some trouble switching between bech32Address and address formats and fields in our SDK.
Is there any way to abstract away the ambiguity? Feel free to chat with me on discord mattlock.
export const transferONE = ({ amount, address }) => async (dispatch, getState) => {
const tx = hmy.transactions.newTx({
to: address, // <--- address is of one format
value: new hmy.utils.Unit(amount).asEther().toWei(),
gasLimit: '210000',
shardID: 0,
toShardID: 0,
gasPrice: new hmy.utils.Unit('10').asGwei().toWei(),
});
...
}
export const transferHRC = ({ amount, address }) => async (dispatch, getState) => {
const tx = contract.methods.transfer(address, parseInt(amount)).send({
from: active.address, // <--- address is of 0x format
gasLimit: '1000000',
gasPrice: new hmy.utils.Unit('10').asGwei().toWei(),
})
...
}
in newTx. We accept both 0xchecksumed and bech32 addr. In contract params, currently it supports 0xchecksumed addr.
To convert address format for now. we can use crypto.getAddress(addr).checksum to convert.
I can convert the address internally when constructing the params. However there are risks such as user input raw base16(without checksumed).
I need further discussion about this issue, because currently encoding solidity contract is using eth‘s method.
one more thing.
const tx = contract.methods.transfer(address, parseInt(amount)).send({
from: active.address, // <--- address is of 0x format
gasLimit: '1000000',
gasPrice: new hmy.utils.Unit('10').asGwei().toWei(),
})
The from here is not necessarily needed. Because when the txn is signed, it will be replaced as signer’s address.
@mattlockyer would you try this branch to see if it works for you.
https://github.com/harmony-one/sdk/tree/neeboo/contract