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

Expose helper functions #38

Merged
merged 1 commit into from
May 22, 2024
Merged

Expose helper functions #38

merged 1 commit into from
May 22, 2024

Conversation

drohit-cb
Copy link
Contributor

Description Of Change

As I work on enhancing our QuickStart guide to add a concrete example to do a e2e stake tx, I realized that having helper functions around reading unsigned txs given a workflow and then ability to sign unsigned txs given wallet's private key would be very helpful.

Testing Procedure

Created a demo app to import the newly exported functions and get a signed staking tx. This is the example that will go into our Quickstart guide.

import { StakingClient, TxSignerFactory, getUnsignedTx } from '@coinbase/staking-client-library-ts';

// Set your api key name and private key here. Get your keys from here: https://portal.cdp.coinbase.com/access/api
const apiKeyName: string = 'YOUR_API_KEY_NAME';
const apiPrivateKey: string = 'YOUR_API_PRIVATE_KEY';

// Set your wallet details
const walletAddress: string = 'YOUR_WALLET_ADDRESS';
const walletPrivateKey: string = 'YOUR_WALLET_PRIVATE_KEY';

const client = new StakingClient(apiKeyName, apiPrivateKey);

async function stake() {
    // Step 1 - Get an unsigned tx corresponding to a
    // stake of 11 wei ETH from your wallet on network Holesky.
    let workflow = await client.Ethereum.stake('holesky', walletAddress, '11');
    let unsignedTx = getUnsignedTx(workflow);
    console.log('Unsigned tx %s', unsignedTx);

    // Step 2 - Sign the unsigned tx with your wallet's private key.
    // Note: In production, this part would be performed via a wallet-sdk of your choice.
    const signer = TxSignerFactory.getSigner('ethereum');
    const signedTx = await signer.signTransaction(walletPrivateKey, unsignedTx);
    console.log('Signed tx %s', signedTx);

    console.log('You can use this UI https://holesky.etherscan.io/pushTx or ' +
    'APIs you are familiar with to help broadcast the signed tx on Holesky.');
}

stake().catch((error) => {
    console.error(error);
});

@drohit-cb drohit-cb changed the title Expose helper functions to help get an e2e stake tx done very easily Expose helper functions May 21, 2024
@drohit-cb drohit-cb force-pushed the expose_helpers branch 2 times, most recently from 49acdc6 to 186e170 Compare May 21, 2024 22:48
@drohit-cb drohit-cb marked this pull request as ready for review May 21, 2024 23:03
@drohit-cb drohit-cb merged commit a5d06f9 into main May 22, 2024
3 checks passed
@drohit-cb drohit-cb deleted the expose_helpers branch May 22, 2024 09:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants