Testnet Access and Javascript SDK examples

Below was the original question

Hello, I found this on the onflow javascript sdk example. Is this up to date? I read on the onflow website that in order to deploy to testnet I needed to create an account on Faucet.

When I use Blocto it doesn’t seem to connect as well

Also, the example listed here https://docs.onflow.org/guides/dapp-deployment/testnet-deployment/ when using Testnet is with the Go SDK. Is there a Javascript example as well? Also, is there a built out example of how to deploy contracts in Javascript SDK? Thanks again

@Tim @Mackenzie probably can share additional info on new Testnet access documentation
@JeffreyDoyle or @qvvg might be able to help with Javascript SDK examples to deploy contracts to Testnet

Thanks unlocked. All of my questions still stand, but my biggest concern is that last part about deploying contracts in Javascript now. When I was a part of the bootcamp during the summer it was done the same way a transaction was sent. Now it looks different because you can deploy multiple contracts to 1 account and I keep getting an error message about “setCode.” I tried looking here Contracts | Cadence but it’s too confusing for me because I can’t find a Javascript example.

My end goal is really just to deploy a contract that mints test NFTs on the testnet, so whatever would help get me there is great hahahah. Thanks again :slight_smile:

Deploying contracts from JavaScript is done the same way you did it in the bootcamp, but with a small change to the Cadence code you use in the transaction itself.
Previously, you would have used a transaction like this:

const CODE = 
`transaction(code: String) {
    prepare(acct: AuthAccount) {
        acct.setCode(code.decodeHex())
    }
}`

Now that accounts have multi-contract support, your transaction should look something like this:

const CODE = 
`transaction(code: String) {
    prepare(acct: AuthAccount) {
       acct.contracts.add(
           name: "Test",
           code: code.decodeHex(),
           message: "I'm a new contract in an existing account"
        )
    }
}`

Hi Jacob, I think the error you’re getting about setCode is happening because @onflow/fcl's ‘stored interactions’ have not been updated with this new transaction code. You can still send the transaction without using a ‘stored interaction’ in the meantime. Multi-contract support in Cadence is a recent addition, and we’re working on bringing all the tooling up-to-date.

It’s true that the documentation is lacking good JavaScript examples, at the moment. We’re also working on making a guide for JavaScript developers to follow, using the latest Cadence features!

1 Like

This repo might be of use, its up to date as of yesterday. : https://github.com/orodio/flow-node-deploy-contract-example

1 Like

Thank you! That helped me very much in deploying a Contract! Now I am trying to deploy a contract to an account using the Testnet and I can’t seem to get it to work. This link https://docs.onflow.org/guides/dapp-deployment/testnet-deployment/#getting-started-on-testnet suggests using this command using the Flow CLI:

flow accounts create \
  --host access.devnet.nodes.onflow.org:9000 \
  --signer testnet \
  --code MyContract.cdc

However it returns an error everytime that the code flag doesn’t exist. I tried updating the CLI and everything. I’m not quite sure what to make of this. Thanks for your help again.

Hi Jacob!

We’ve just recently updated the CLI to support multiple contracts per account.

Please update to CLI v0.12 (by reinstalling the CLI, i.e. running the installation command you used again).

The --code flag has been replaced by the --contract flag, so if you have a contract contract MyContract { ... } in a file MyContract.cdc, then:

--contract MyContract:MyContract.cdc

should work.

1 Like