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

[TypeScript SDK] Implement transfer coin #1865

Merged
merged 2 commits into from
May 9, 2022
Merged

[TypeScript SDK] Implement transfer coin #1865

merged 2 commits into from
May 9, 2022

Conversation

666lcz
Copy link
Contributor

@666lcz 666lcz commented May 9, 2022

This PR implements the logic for transferring coin using this rpc function

Tested through the example App:

import React, { useState } from "react";
import {
  Base64DataBuffer,
  Ed25519Keypair,
  JsonRpcProvider,
  RawSigner,
} from "@mysten/sui.js";
import { getAppConfig } from "./config";

const SEED = [
  180, 107, 26, 32, 169, 88, 248, 46, 88, 100, 108, 243, 255, 87, 146, 92, 42,
  147, 104, 2, 39, 200, 114, 145, 37, 122, 8, 37, 170, 238, 164, 236,
];

export function RawSignerDemo() {
  const [message, setMessage] = useState("");

  const handleSubmit = async (evt: React.SyntheticEvent) => {
    evt.preventDefault();
    const keypair = Ed25519Keypair.fromSeed(new Uint8Array(SEED));
    const { endpoint } = getAppConfig();
    const signerWithProvider = new RawSigner(
      keypair,
      new JsonRpcProvider(endpoint)
    );
    const txn = await signerWithProvider.transferCoin({
      signer: pubKey.toSuiAddress(),
      objectId: "5015b016ab570df14c87649eda918e09e5cc61e0",
      gasPayment: "0a8c2a0fd59bf41678b2e22c3dd2b84425fb3673",
      gasBudget: 10000,
      recipient: "BFF6CCC8707AA517B4F1B95750A2A8C666012DF3",
    });
    console.log("txn", txn);
  };
  return (
    <form onSubmit={handleSubmit}>
      <label>
        Data to sign:
        <input
          type="text"
          value={message}
          onChange={(e) => setMessage(e.target.value)}
        />
      </label>
      <input type="submit" value="Sign" />
    </form>
  );
}

Observe the following result

{
    "EffectResponse": {
        "certificate": {
            "data": {
                "kind": {
                    "Single": {
                        "Transfer": {
                            "recipient": "bff6ccc8707aa517b4f1b95750a2a8c666012df3",
                            "object_ref": [
                                "5015b016ab570df14c87649eda918e09e5cc61e0",
                                2,
                                "LuoJ/oAg+loz9yD+agoM1oYJY3UP4OgJbnruEnV8/Cc="
                            ]
                        }
                    }
                },
                "sender": "627ac02b685d506cbf38cda62cae63cb48a5ec75",
                "gas_payment": [
                    "0a8c2a0fd59bf41678b2e22c3dd2b84425fb3673",
                    3,
                    "QSrrbnsupX1mekh8vVrvi/Z0RYCzQPWtRqHsKfTbQn8="
                ],
                "gas_budget": 10000
            },
            "tx_signature": "iWGEAcO/ZudSVdv+anN8v9T/QsMe/I12NVXmHgCaS2z/NO9108c8W8D4FyP0qUWtiBm6POihd+oZco97AzGkBSu52zOcw4gyHSHN4VO3eg4nR2OXaH/g4qPKjO4cpceq",
            "auth_sign_info": {
                "epoch": 0,
                "signatures": [
                    [
                        "g56Z+LA/D1Vj1s2cw54QqM9IOtJ3Wuy7knAxNwkl704=",
                        "l3KT6JAKvHxOxudwNFcP0FQlJVnyLaYR+uCFJnHIaf2OcxwmsQOxSg4YGIy7nXFxo6OP92SyisfnqX1ZObVBDQ=="
                    ],
                    [
                        "FYTvK2d9b16WtX2sJ0TpJ4qiThF8e/1qwAv0PBEpx/0=",
                        "lqIfxXOkYMFl6k2P+LG0n9VhUjvHUfBqA6yqQQX5i0T9BcXyCr+3q1zLYby3owkeUjME5E2nG3UXVdiPxYM7AA=="
                    ],
                    [
                        "6XY4qeELnMRthbgRkaYKam/K5j2s2BHAdQLbnFz8VbU=",
                        "Hvr9wbGvybhPLprPrrSoXQ0Fd81UFPLS9G/hav3+jwH7hyaCFLz7Kq9XjJbJ0GrjAqZ3pFrbdH3p/xZXIXJGBg=="
                    ]
                ]
            }
        },
        "effects": {
            "status": {
                "Success": {
                    "gas_cost": {
                        "computation_cost": 41,
                        "storage_cost": 30,
                        "storage_rebate": 30
                    }
                }
            },
            "shared_objects": [],
            "transaction_digest": "6os/2BIW6UIoY/RMeosq0Oq5pwB6E/o5ifAH5e2zJ4M=",
            "created": [],
            "mutated": [
                [
                    [
                        "0a8c2a0fd59bf41678b2e22c3dd2b84425fb3673",
                        4,
                        "OxxxkWHQkFjdFUl87LqDVJQttR2Ep1QJQ5eUGA+ry/0="
                    ],
                    {
                        "AddressOwner": "627ac02b685d506cbf38cda62cae63cb48a5ec75"
                    }
                ],
                [
                    [
                        "5015b016ab570df14c87649eda918e09e5cc61e0",
                        3,
                        "bWPaB/63MXkOmQt/+j0cDEUI9BjV6uT0xtJALsq+jnk="
                    ],
                    {
                        "AddressOwner": "bff6ccc8707aa517b4f1b95750a2a8c666012df3"
                    }
                ]
            ],
            "unwrapped": [],
            "deleted": [],
            "wrapped": [],
            "gas_object": [
                [
                    "0a8c2a0fd59bf41678b2e22c3dd2b84425fb3673",
                    4,
                    "OxxxkWHQkFjdFUl87LqDVJQttR2Ep1QJQ5eUGA+ry/0="
                ],
                {
                    "AddressOwner": "627ac02b685d506cbf38cda62cae63cb48a5ec75"
                }
            ],
            "events": [],
            "dependencies": [
                "RiJW+Ht/2b9Rsb4qi8hGR6IUw7WZJVANwX4FpnpztTQ=",
                "VoqKCrgL+YtDrmGgg7myrtxoUDbbFBGVuC9M1pgTVQk="
            ]
        }
    }
}

You can also view the Transferred Coin on https://explorer.devnet.sui.io/objects/5015b016ab570df14c87649eda918e09e5cc61e0

@666lcz 666lcz force-pushed the chris-new-transfer branch 2 times, most recently from 98cffd5 to 48a80d9 Compare May 9, 2022 07:14
@666lcz 666lcz changed the title [TypeScript SDK] Implement new transfer coin [TypeScript SDK] Implement transfer coin May 9, 2022
@666lcz 666lcz force-pushed the chris-new-transfer branch from 48a80d9 to 0742cac Compare May 9, 2022 07:26
@666lcz 666lcz marked this pull request as ready for review May 9, 2022 07:30
@666lcz 666lcz requested a review from Clay-Mysten as a code owner May 9, 2022 07:30
);
const txn = await signer.transferCoin({
signer: keypair.getPublicKey().toSuiAddress(),
objectId: '5015b016ab570df14c87649eda918e09e5cc61e0',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this now have an 0x prefix per?
#1867

Copy link
Contributor

@Clay-Mysten Clay-Mysten left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, Chris. The README looks good with one question/comment.

@666lcz 666lcz force-pushed the chris-new-transfer branch from 0742cac to e311d32 Compare May 9, 2022 21:20
@666lcz 666lcz enabled auto-merge (squash) May 9, 2022 21:23
@666lcz 666lcz merged commit 0bd01d0 into main May 9, 2022
@666lcz 666lcz deleted the chris-new-transfer branch May 9, 2022 21:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants