Skip to content
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

Merged
merged 2 commits into from
Sep 13, 2021
Merged

Conversation

orkunkl
Copy link
Contributor

@orkunkl orkunkl commented Sep 11, 2021

Implements essential send and sendFrom for cw20-base/helpers.ts

@orkunkl orkunkl changed the title Add send and sendFrom to cw20 helpers.ts Add send and sendFrom to cw20-base helpers.ts Sep 11, 2021
Copy link
Member

@ethanfrey ethanfrey left a 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?

@@ -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);
Copy link
Member

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

}

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);
Copy link
Member

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

Copy link
Member

@ethanfrey ethanfrey left a 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.

@ethanfrey ethanfrey merged commit 36d5457 into main Sep 13, 2021
@ethanfrey ethanfrey deleted the cw20-helper-send branch September 13, 2021 09:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants