Learning to use the demo endpoint

parse is not giving me any output to the console no matter what input I try.

Does it write to somewhere else, not to the console?
Or is there some issue that make it kick out?

It looks like there are line breaks in your hex, so it is probably just failing to parse it. It isn’t really user friendly enough to give errors. :smile:

When I run this it gives the output below

go run cmd/smartcontract/main.go parse 006a02bd000e746573742e746f6b656e697a6564041a0243314cc50a1b31307856656e7475726573202d205341464520436f6e747261637410021a3a5468697320697320612073616d706c6520546f6b656e697a656420636f6e747261637420616e6420686173206e6f207265616c2076616c75652e222953696d706c652041677265656d656e7420666f7220467574757265204571756974792028534146452952220a0c3130782056656e7475726573120149720f0805120b4461766964204c79706b61b00101c20115207259fb40c57acfc817d3a5e046fc83b9e1387cde

Uses Test Protocol Signature
Action type : C1

{
    "ContractName": "10xVentures - SAFE Contract",
    "BodyOfAgreementType": 2,
    "BodyOfAgreement": "5468697320697320612073616d706c6520546f6b656e697a656420636f6e747261637420616e6420686173206e6f207265616c2076616c75652e",
    "ContractType": "Simple Agreement for Future Equity (SAFE)",
    "Issuer": {
        "Name": "10x Ventures",
        "Type": "I",
        "Management": [
            {
                "Type": 5,
                "Name": "David Lypka"
            }
        ]
    },
    "HolderProposal": true,
    "MasterAddress": "207259fb40c57acfc817d3a5e046fc83b9e1387cde"
}

So I tried to replicate your successful run but still no output:
[email protected]:~/go/src/github.com/tokenized/smart-contract$ ~/go/bin/smartcontract parse 006a02bd000e746573742e746f6b656e697a6564041a0243314cc50a1b31307856656e7475726573202d205341464520436f6e747261637410021a3a54686
97320697320612073616d706c6520546f6b656e697a656420636f6e747261637420616e6420686173206e6f207265616c2076616c75652e222953696d706c652041677265656d656e7420666f7220467574757265204571756974792028534146452952220a0c3130782056656e747572
6573120149720f0805120b4461766964204c79706b61b00101c20115207259fb40c57acfc817d3a5e046fc83b9e1387cde
[email protected]:~/go/src/github.com/tokenized/smart-contract$

Do I need to update to the latest code? If so, can I just overcopy all the .go files? or do I have to rebuild something?

I don’t think our build process updates “~/go/bin/”. Run make dist and then dist/smartcontract parse or go run cmd/smartcontract/main.go parse

Are you talking about steps to do if I overcopy the .go files with the latest code?

And did you run the script I sent you? Did it output the correct result?

I also tried to debug cmd_parse.go by adding print statements.
But now it does not run anymore even when I remove my print statements.
I get this error output:
[email protected]:~/go/src/github.com/tokenized/smart-contract$ go run ./cmd/smartcontract/main.go parse

github.com/tokenized/smart-contract/cmd/smartcontract/cmd

cmd/smartcontract/cmd/cmd_parse2.go:20:5: cmdParse redeclared in this block
previous declaration at cmd/smartcontract/cmd/cmd_parse.go:20:5
cmd/smartcontract/cmd/cmd_parse2.go:57:6: parseTx redeclared in this block
previous declaration at cmd/smartcontract/cmd/cmd_parse.go:53:59
cmd/smartcontract/cmd/cmd_parse2.go:77:6: parseScript redeclared in this block
previous declaration at cmd/smartcontract/cmd/cmd_parse.go:73:64
cmd/smartcontract/cmd/cmd_parse_Crash.go:20:5: cmdParse redeclared in this block
previous declaration at cmd/smartcontract/cmd/cmd_parse2.go:20:5
cmd/smartcontract/cmd/cmd_parse_Crash.go:57:6: parseTx redeclared in this block
previous declaration at cmd/smartcontract/cmd/cmd_parse2.go:57:59
cmd/smartcontract/cmd/cmd_parse_Crash.go:77:6: parseScript redeclared in this block
previous declaration at cmd/smartcontract/cmd/cmd_parse2.go:77:64

Can I fix it by running make again? What should my current directory be in order to run that make again?

No, I think the binary executable you were executing is old and doesn’t update from our build process.

The script you posted is fine minus that and the line breaks, which I assume are a result of you pasting into the forum.

Just git pull to make sure you have the latest code in smart-contract and specification, then use go run cmd/smartcontract/main.go parse

OK I applied the latest code as you instructed and now the parse command works. Thanks.
[email protected]:~/go/src/github.com/tokenized/smart-contract$ go run ./cmd/smartcontract/main.go parse
go: downloading github.com/tokenized/specification v0.2.2-0.20191219061451-ecd0fc17c3ca
go: downloading github.com/pkg/errors v0.8.1
go: extracting github.com/pkg/errors v0.8.1
:
:
go: finding github.com/btcsuite/btclog v0.0.0-20170628155309-84c8d2346e9f
go: finding github.com/btcsuite/go-socks v0.0.0-20170105172521-4720035b7bfd
go: finding github.com/btcsuite/websocket v0.0.0-20150119174127-31079b680792
Enter hex to decode: 006a02bd000e746573742e746f6b656e697a6564041a0243314cc50a1b31307856656e7475726573202d205341464520436f6e747261637410021a3a5468697320697320612073616d706c6520546f6b656e697a656420636f6e747261637420616e6420686173206e6f207265616c2076616c75652e222953696d706c652041677265656d656e7420666f7220467574757265204571756974792028534146452952220a0c3130782056656e7475726573120149720f0805120b4461766964204c79706b61b00101c20115207259fb40c57acfc817d3a5e046fc83b9e1387cde

Uses Test Protocol Signature
Action type : C1

{
    "ContractName": "10xVentures - SAFE Contract",
    "BodyOfAgreementType": 2,
    "BodyOfAgreement": "5468697320697320612073616d706c6520546f6b656e697a656420636f6e747261637420616e6420686173206e6f207265616c2076616c75652e",
    "ContractType": "Simple Agreement for Future Equity (SAFE)",
    "Issuer": {
        "Name": "10x Ventures",
        "Type": "I",
        "Management": [
            {
                "Type": 5,
                "Name": "David Lypka"
            }
        ]
    },
    "HolderProposal": true,
    "MasterAddress": "207259fb40c57acfc817d3a5e046fc83b9e1387cde"
}

[email protected]:~/go/src/github.com/tokenized/smart-contract$

2 Likes

Now I am trying to setup my own BSV Node to resume following the Quick Start Examples.
For using the node only for Tokenized purposes, it an pruned node adequate?
I am thinking of only loading blocks from when I started using MoneyButton a few months ago.
Is that enough for the smart contracts to work?

Yes, you only need to load blocks that have transactions related to your wallet and contract.

In dev.env:

What is

The address to pay fees to

export FEE_ADDRESS=16GgqN2sWSTZAZobNkR6uLVUUmD8LnnSPM

Is it supposed to be my contract wallet address?

It should be a separate address. It is the address that tokenized request fees get put into. Like those specified in the ContractFee field in the ContractOffer.

I have my own BSV 1.01 Full-node syncd and running on my laptop.
I am now running smartcontractd locally using
source ./conf/dev.env && make run
Now I am confused what should I put for the CLIENT_CONTRACT_ADDRESS in the .env when it is local?
I thought the endpoint supplied on your server was smartcontractd running on your side.
for example: {“address”:“1EJYUA1QswgV5bXeXTFWphGYBdmr48dGT”,“contract_fee”:2000}

What is the contract address from my local smartcontractd instance?

CLIENT_CONTRACT_ADDRESS is an environment variable for the smartcontract (command line interface). It should be the address associated with the PRIV_KEY value from your smartcontractd (daemon). When you configure smartcontractd yourself, you should generate your own private key for PRIV_KEY.

I do not follow your explanation because you say that PRIV_KEY comes from the smartcontractd daemon, but the only private key I know is the WIF and that comes from
go run ./cmd/smartcontract/main.go gen

Why are you saying that PRIV_KEY comes from smartcontractd daemon??
The daemon only gives a contract address, not a wallet WIF, right?

So I asking for a more clear and detailed explanation about what will be the CLIENT_CONTRACT_ADDRESS when I run smartcontractd locally?
Right now it seems I can continue using the CLIENT_CONTRACT_ADDRESS that I got from the old endpoint as far as the sync goes. Or will it cause a failure when I try to build more parts of the contract on my local instance?

I ran sync last night and at least it the the bitcoin in the Wallet I put for the CLIENT_CONTRACT_ADDRESS and the WIF I was using which I found from
my notes from the earlier runs on the daemon endpoint supplied by the tokenized server:

{“address”:“13gH6N3p8Rh6MnA7zy4sWY8sJf1k4reeWx”,“contract_fee”:2000} Got a good contract address

And the Wallet Address and WIF came from here:

run gen to get a client wallet address and wallet private key

[email protected]:~/go/src/github.com/tokenized/smart-contract$ go run ./cmd/smartcontract/main.go gen

WIF : 5JwYL4PordffyGsdu6jPCG9TYRfaskkMhoy72u7zJDQarqsPBNU

PubKey : A/dnYp+MCynhFiQtG6qKkFApuDiP9IdWTFNLkRntnKTT

Addr : 16GgqN2sWSTZAZobNkR6uLVUUmD8LnnSPM

AND HERE IS THE RUN ON MY LOCAL INSTALL:

sudo ./bitcoind

~/go/src/github.com/tokenized/smart-contract$ source ./conf/dev.env && make run
go run cmd/smartcontractd/main.go

[email protected]:~/go/src/github.com/tokenized/smart-contract$ source ./conf/cli.dev.env

[email protected]:~/go/src/github.com/tokenized/smart-contract$ go run ./cmd/smartcontract/main.go sync

2020/02/27 01:01:38.258299 [Main] wallet.go:161 Info - Loaded wallet with 0 outputs, 0 unspent, and balance of 0.00000000

2020/02/27 01:01:38.314273 [Main] wallet.go:164 Info - Wallet address : 16GgqN2sWSTZAZobNkR6uLVUUmD8LnnSPM

2020/02/27 01:01:38.314345 [Main] node.go:114 Info - Contract address : 13gH6N3p8Rh6MnA7zy4sWY8sJf1k4reeWx

2020/02/27 01:01:46.402213 [SpyNode] node.go:112 Info - Loaded blocks to height 621999

2020/02/27 01:01:46.402380 [SpyNode] node.go:116 Info - Start block height 560000

2020/02/27 01:15:38.395083 [Main] node.go:382 Info - Synchronized 1846 new block(s) to height 623845

2020/02/27 01:15:38.395179 [Main] node.go:384 Info - Balance : 0.00098202

2020/02/27 01:15:38.395281 [Main] node.go:169 Info - Stopping

2020/02/27 01:15:38.395385 [SpyNode] node.go:277 Verbose - Requesting stop

2020/02/27 01:15:38.395468 [SpyNode] node.go:284 Info - Stopping

2020/02/27 01:15:38.395705 [SpyNode] node.go:710 Warn - ReadMessage : read tcp 127.0.0.1:51494->127.0.0.1:8333: use of closed network connection

2020/02/27 01:15:38.433019 [SpyNode] node.go:1072 Verbose - Waiting for 0 untrusted nodes to finish

2020/02/27 01:15:39.184488 [SpyNode] node.go:225 Verbose - Saving

2020/02/27 01:15:39.185517 [SpyNode] transactions.go:80 Verbose - Saving 0 unconfirmed txs

2020/02/27 01:15:39.185558 [SpyNode] peers.go:202 Verbose - Saving 16 peers

2020/02/27 01:15:39.185765 [SpyNode] node.go:140 Verbose - Stopped

2020/02/27 01:15:39.245424 [Main] wallet.go:180 Info - Saved wallet with 2 outputs and balance of 0.00098202

[email protected]:~/go/src/github.com/tokenized/smart-contract$

But I am not sure if the CLIENT_CONTRACT_ADDRESS will be correct now.
AND how to make any new CLIENT_CONTRACT_ADDRESS on any new contracts on my local setup?
To generate a fresh contract address locally, is there a way to make my local smartcontractd output the similar JSON containing the CLIENT_CONTRACT_ADDRESS just like the endpoint provided?

I mean the PRIV_KEY value is in the smartcontractd config file and used by smartcontractd.

The CLIENT_CONTRACT_ADDRESS is in the smartcontract config file, but should be the address derived from the PRIV_KEY in the smartcontractd config file.

When you run smartcontract sync, it syncs txs related to your administration address derived from CLIENT_WALLET_KEY in your smartcontract config, not your contract address. These need to be different keys/addresses.

So when it says “Balance : 0.00098202” above, it means that is the balance in “Wallet address : 16GgqN2sWSTZAZobNkR6uLVUUmD8LnnSPM”.

Yes I know all that, but the question remains: right now I set PRIV_KEY in dev.env to be the WIF that came from running smarcontract gen.
So I think you are saying no, I need to create another WIF there.

So how to create the additional WIF and related bitcoin address?
Can I run smartcontract gen to get them?

But what values to use if I want to resume working on the same contract that I was working on when I was using your supplied endpoint?

Yes, you can just run smartcontract gen again to produce more keys/addresses.

If you are running your own smartcontractd, then you can’t use our endpoint’s contract address because you don’t have the private key. You have to start with a new contract address/key.

It is safe to run smartcontract sync in one command shell and then run smartcontract transactions from another commandshell in parallel? It is worth it to keep sync running most of the time?