Skip to content
This repository has been archived by the owner on Aug 1, 2023. It is now read-only.

Update to Stacks 2.0 transactions #40

Open
wants to merge 25 commits into
base: master
Choose a base branch
from
Open

Conversation

yknl
Copy link
Contributor

@yknl yknl commented Apr 3, 2020

This PR updates the send_tokens and make_keychain commands for Stacks 2.0 and adds deploy_contract and call_contract_func commands to publish and call smart contracts. The PR also adds the bin name blockstack so commands can be called using just blockstack instead of blockstack-cli

send_tokens new usage:

send_tokens ADDRESS AMOUNT FEE_RATE NONCE PAYMENT_KEY [MEMO] 

$ blockstack send_tokens ST1WZ69T99RHQMQX3D91ZH2R37GV5NK8KDS5D5VDZ 1000 1 0 381314da39a45f43f45ffd33b5d8767d1a38db0da71fea50ed9508e048765cf301 -t

To estimate the transaction fee needed without broadcasting the transaction, add the -e flag.

To see the raw signed transaction without broadcasting, add the -x flag.

make_keychain returns

{
  "mnemonic": "private unhappy random runway boil scissors remove harvest fatigue inherit inquiry still before mountain pet tail mad accuse second milk client rebuild salt chase",
  "keyInfo": {
    "privateKey": "381314da39a45f43f45ffd33b5d8767d1a38db0da71fea50ed9508e048765cf301",
    "address": "ST1BG7MHW2R524WMF7X8PGG3V45ZN040EB9EW0GQJ",
    "btcAddress": "n4X37UmRZYk9HawtS1w4xRtqJWhByxiz3c",
    "index": 0
  }
}

deploy_contract usage:

deploy_contract SOURCE_FILE CONTRACT_NAME FEE NONCE PAYMENT_KEY

$ blockstack deploy_contract ./my_contract_source.clar hello_world 660 0 381314da39a45f43f45ffd33b5d8767d1a38db0da71fea50ed9508e048765cf301 -t

To estimate the transaction fee needed without broadcasting the transaction, add the -e flag.
To see the raw signed transaction without broadcasting, add the -x flag.

call_contract_func usage:

call_contract_func CONTRACT_ADDRESS CONTRACT_NAME FUNCTION_NAME FEE NONCE PAYMENT_KEY

blockstack call_contract_func ST1WZ69T99RHQMQX3D91ZH2R37GV5NK8KDS5D5VDZ hello_world my_func 300 0 381314da39a45f43f45ffd33b5d8767d1a38db0da71fea50ed9508e048765cf301 -t

To estimate the transaction fee needed without broadcasting the transaction, add the -e flag.
To see the raw signed transaction without broadcasting, add the -x flag.

The command will fetch the contract ABI and prompt for arguments to the function call.

? Enter value for function argument "myBoolArg" of type bool (Use arrow keys)
❯ True 
  False 

Testing Instructions:

  1. Use the make_keychain command with the testnet option to generate a new key.
blockstack make_keychain -t
  1. Spin up a local testnet with the side car. Plug the address generated above into the genesis configuration. Alternatively, use the testnet faucet to send tokens to the address generated above.

  2. Use the send_tokens command to send tokens to any address. Using the -t option for testnet. By default using the -t flag sets the Stacks blockchain node that the CLI communicates with to http://neon.blockstack.org:20443. You can specify an alternate node using: -H "<Your local core node URL>"

blockstack send_tokens ST16KX11KMXWG9NRVCM1D5CHZGR3HFRQBK0DN9XAT 10000 300 0 381314da39a45f43f45ffd33b5d8767d1a38db0da71fea50ed9508e048765cf301 -t 
  1. Verify balances using the balance command
blockstack balance ST16KX11KMXWG9NRVCM1D5CHZGR3HFRQBK0DN9XAT -t

You can also specify a node to look up balances on using the -H flag here.

  1. Test contract deploy using the deploy_contract command:
blockstack deploy_contract ./my_contract_source.clar hello_world 800 1 381314da39a45f43f45ffd33b5d8767d1a38db0da71fea50ed9508e048765cf301 -t
  1. Test calling the function that was just deployed using the call_contract_func command:
blockstack call_contract_func ST16KX11KMXWG9NRVCM1D5CHZGR3HFRQBK0DN9XAT hello_world test_function 400 2 381314da39a45f43f45ffd33b5d8767d1a38db0da71fea50ed9508e048765cf301 -t

Verify that function was successfully called and processed.

@yknl yknl marked this pull request as ready for review April 14, 2020 04:18
@yknl yknl requested a review from zone117x April 14, 2020 04:21
@yknl yknl requested a review from timstackblock April 21, 2020 14:32
@timstackblock
Copy link
Contributor

Currently testing this PR locally

@timstackblock
Copy link
Contributor

timstackblock commented Apr 22, 2020

I am able to make_keychain without issue but, making a request to the faucet endpoint to send tokens to the address generated above, is hanging but not throwing an error.

Screen Shot 2020-04-22 at 10 59 53 AM

@timstackblock
Copy link
Contributor

@yknl @zone117x please take a look at the issue above

@timstackblock
Copy link
Contributor

The balance seems to be incorrect, this is what I am receiving

Screen Shot 2020-04-22 at 11 56 01 AM

This is what is in the stacks.toml file

Screen Shot 2020-04-22 at 11 55 07 AM

@timstackblock timstackblock added the bug Something isn't working label Apr 22, 2020
Copy link
Contributor

@timstackblock timstackblock left a comment

Choose a reason for hiding this comment

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

The commands listed on the PR do not work as expected. Please update the PR with the updated commands and the default local URL you are using. We may need to update this documentation as well https://docs.blockstack.org/core/smart/cli-wallet-quickstart.html

@yknl yknl requested a review from timstackblock May 19, 2020 14:32
@yknl yknl reopened this Jun 22, 2020
export async function getStacksWalletKeyInfo(network: CLINetworkAdapter, mnemonic : string): Promise<StacksKeyInfoType> {
const seed = await bip39.mnemonicToSeed(mnemonic);
const master = bip32.fromSeed(seed);
const child = master.derivePath('m/44\'/5757\'/0\'/0/0'); // taken from stacks-wallet. See https://github.com/blockstack/stacks-wallet
Copy link

@kyranjamie kyranjamie Jul 8, 2020

Choose a reason for hiding this comment

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

Suggested change
const child = master.derivePath('m/44\'/5757\'/0\'/0/0'); // taken from stacks-wallet. See https://github.com/blockstack/stacks-wallet
const child = master.derivePath(`m/44'/5757'/0'/0/0`); // taken from stacks-wallet. See https://github.com/blockstack/stacks-wallet

autoformatted to the escaped string?

Some of this code is in the keychain library, too (Copied from here).

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants