-
Notifications
You must be signed in to change notification settings - Fork 353
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add send and sendFrom to cw20-base helpers.ts #415
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good to add this. Can you ensure base64 encoding?
contracts/cw20-base/helpers.ts
Outdated
@@ -265,6 +268,16 @@ export const CW20 = (client: SigningCosmWasmClient, fees: Options["fees"]): CW20 | |||
return result.transactionHash; | |||
} | |||
|
|||
const send = async (senderAddress: string, recipient: string, amount: string, msg: Record<string, unknown>): Promise<string> => { | |||
const result = await client.execute(senderAddress, contractAddress, {send: {recipient, amount, msg: toUtf8(JSON.stringify(msg))}}, fees.exec); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One more step needed here (maybe you can pull this out to a function jsonToBinary
msg: toBase64(toUtf8(JSON.stringify(msg)))
We want to explicitly make it a base64-encoded string. I think the default JSON serialisation in JS land for Uint8Array is [43, 91, 81, ...]
, which is not what we want
contracts/cw20-base/helpers.ts
Outdated
} | ||
|
||
const sendFrom = async (senderAddress: string, owner: string, recipient: string, amount: string, msg: Record<string, unknown>): Promise<string> => { | ||
const result = await client.execute(senderAddress, contractAddress, {send_from: {owner, recipient, amount, msg: toUtf8(JSON.stringify(msg))}}, fees.exec); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same here with the msg encoding
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the update.
Looks good.
Implements essential
send
andsendFrom
for cw20-base/helpers.ts