Skip to main content
deleted 81 characters in body
Source Link

For larger programs, the pattern I prefer and have seen some otherBigger projects typically use is to splitthe multiple files template added in Anchor 0.29. You can do this for new projects with:

anchor init counter --template=multiple

This splits up state/ and instructions/. Under these folders, you can create files for each account type and instruction respectivelyhandler.

For example, a simple counter program might look like:

src/
  instructions/
    decrement.rs
    increment.rs
    initialize.rs
    mod.rs
  state/
    counter.rs
    mod.rs
  lib.rs
  errors.rs
Cargo.toml
README.md

You can do this for new projects with:

anchor init counter --template=multiple

See 'Multiple files template' in the Anchor Release Notes

For larger programs, the pattern I prefer and have seen some other projects use is to split up state/ and instructions/. Under these folders, you can create files for each account type and instruction respectively.

For example, a simple counter program might look like:

src/
  instructions/
    decrement.rs
    increment.rs
    initialize.rs
    mod.rs
  state/
    counter.rs
    mod.rs
  lib.rs
  errors.rs
Cargo.toml
README.md

You can do this for new projects with:

anchor init counter --template=multiple

See 'Multiple files template' in the Anchor Release Notes

Bigger projects typically use the multiple files template added in Anchor 0.29. You can do this for new projects with:

anchor init counter --template=multiple

This splits up state/ and instructions/. Under these folders, you can create files for each account type and instruction handler.

For example, a simple counter program might look like:

src/
  instructions/
    decrement.rs
    increment.rs
    initialize.rs
    mod.rs
  state/
    counter.rs
    mod.rs
  lib.rs
  errors.rs
Cargo.toml
README.md
added 95 characters in body
Source Link

For larger programs, the pattern I prefer and have seen some other projects use is to split up state/ and instructions/. Under these folders, you can create files for each account type and instruction respectively.

For example, a simple counter program might look like:

src/
  instructions/
    decrement.rs
    increment.rs
    initialize.rs
    mod.rs
  state/
    counter.rs
    mod.rs
  lib.rs
  errors.rs
Cargo.toml
README.md

You can do this for new projects with:

anchor init counter --template=multiple

See 'Multiple files template' in the Anchor Release Notes

For larger programs, the pattern I prefer and have seen some other projects use is to split up state/ and instructions/. Under these folders, you can create files for each account type and instruction respectively.

For example, a simple counter program might look like:

src/
  instructions/
    decrement.rs
    increment.rs
    initialize.rs
    mod.rs
  state/
    counter.rs
    mod.rs
  lib.rs
  errors.rs
Cargo.toml
README.md

For larger programs, the pattern I prefer and have seen some other projects use is to split up state/ and instructions/. Under these folders, you can create files for each account type and instruction respectively.

For example, a simple counter program might look like:

src/
  instructions/
    decrement.rs
    increment.rs
    initialize.rs
    mod.rs
  state/
    counter.rs
    mod.rs
  lib.rs
  errors.rs
Cargo.toml
README.md

You can do this for new projects with:

anchor init counter --template=multiple

See 'Multiple files template' in the Anchor Release Notes

deleted 6 characters in body
Source Link

For larger programs, the pattern I prefer and have seen some other projects replicateuse is to split up state/ and instructions/. Under these folders, you can create files for each account type and instruction respectively.

For example, a simple counter program might look like:

src/
  instructions/
    decrement.rs
    increment.rs
    initialize.rs
    mod.rs
  state/
    counter.rs
    mod.rs
  lib.rs
  errors.rs
Cargo.toml
README.md

For larger programs, the pattern I prefer and have seen some other projects replicate is to split up state/ and instructions/. Under these folders, you can create files for each account type and instruction respectively.

For example, a simple counter program might look like:

src/
  instructions/
    decrement.rs
    increment.rs
    initialize.rs
    mod.rs
  state/
    counter.rs
    mod.rs
  lib.rs
  errors.rs
Cargo.toml
README.md

For larger programs, the pattern I prefer and have seen some other projects use is to split up state/ and instructions/. Under these folders, you can create files for each account type and instruction respectively.

For example, a simple counter program might look like:

src/
  instructions/
    decrement.rs
    increment.rs
    initialize.rs
    mod.rs
  state/
    counter.rs
    mod.rs
  lib.rs
  errors.rs
Cargo.toml
README.md
Source Link
Loading