Skip to content

Commit

Permalink
docs: Add tuple enum JS client documentation (#2631)
Browse files Browse the repository at this point in the history
  • Loading branch information
acheroncrypto authored Sep 18, 2023
1 parent b5f4796 commit fa9f960
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 71 deletions.
66 changes: 25 additions & 41 deletions docs/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

70 changes: 40 additions & 30 deletions docs/src/pages/docs/javascript-anchor-types.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,17 +25,17 @@ This reference shows you how anchor maps rust types to javascript/typescript typ
* `u64/u128/i64/i128`
* `anchor.BN`
* ```javascript
await program
await program
.methods
.init(new anchor.BN(99))
.rpc();
```
* [https://github.com/indutny/bn.js/](https://github.com/indutny/bn.js/ )
* [https://github.com/indutny/bn.js](https://github.com/indutny/bn.js )
---
* `u8/u16/u32/i8/i16/i32`
* `number`
* ```javascript
await program
await program
.methods
.init(99)
.rpc();
Expand All @@ -44,69 +44,79 @@ This reference shows you how anchor maps rust types to javascript/typescript typ
* `f32/f64`
* `number`
* ```javascript
await program
await program
.methods
.init(1.0)
.rpc();
```
---
* `Enum`
* `{ variantName: {} }`
* ```rust
enum MyEnum { One, Two };
```
```javascript
await program
* `object`
* ```rust
enum MyEnum {
One,
Two { val: u32 },
Three(u8, i16),
};
```
```javascript
// Unit variant
await program
.methods
.init({ one: {} })
.rpc();
```
```rust
enum MyEnum { One: { val: u64 }, Two };
```
```javascript
await program
// Named variant
await program
.methods
.init({ one: { val: 99 } })
.init({ two: { val: 99 } })
.rpc();
```
// Unnamed(tuple) variant
await program
.methods
.init({ three: [12, -34] })
.rpc();
```
---
* `Struct`
* `{ val: {} }`
* ```rust
struct MyStruct { val: u64 };
```
struct MyStruct {
val: u16,
}
```
```javascript
await program
await program
.methods
.init({ val: 99 })
.rpc();
```
```
---
* `[T; N]`
* `[ T ]`
* ```javascript
await program
await program
.methods
.init([1,2,3])
.init([1, 2, 3])
.rpc();
```
```
---
* `String`
* `string`
* ```javascript
await program
await program
.methods
.init("hello")
.rpc();
```
```
---
* `Vec<T>`
* `[ T ]`
* ```javascript
await program
await program
.methods
.init([1,2,3])
.init([1, 2, 3])
.rpc();
```
```
{% /table %}

1 comment on commit fa9f960

@vercel
Copy link

@vercel vercel bot commented on fa9f960 Sep 18, 2023

Choose a reason for hiding this comment

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

Successfully deployed to the following URLs:

anchor-docs – ./

anchor-lang.com
www.anchor-lang.com
anchor-docs-git-master-200ms.vercel.app
anchor-docs-200ms.vercel.app

Please sign in to comment.