Skip to content

Commit

Permalink
docs(taquito, conseiljs, fa2, values): Adds value documentation and u…
Browse files Browse the repository at this point in the history
…sage examples
  • Loading branch information
RomarQ committed Jan 31, 2022
1 parent a6cee77 commit b5c6c23
Show file tree
Hide file tree
Showing 8 changed files with 996 additions and 18 deletions.
99 changes: 99 additions & 0 deletions documentation/docs/FA2.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
# FA2 Interface

## Entrypoint Parameter

### transfer

- [Using Taquito](./taquito#transfer)
- [Using ConseilJS](./conseiljs#transfer)

```ts
const { Record, Address, List, Nat } = require('@tezwell/michelson-sdk/literal');

const parameters = List(
[
Record({
from_: Address("tz1gTnKMA65qaKVpp6x4cgMLU2UyKF2zjHYN"),
txs: List(
[
Record({
to_: Address("KT1JehYdejjvFf1BqdXzTPt1QWqqSd3xS4JF"),
token_id: Nat(0),
amount: Nat(10),
})
]
),
})
]
).toJSON();
```

### balance_of

- [Using Taquito](./taquito#balance_of)
- [Using ConseilJS](./conseiljs#balance_of)

```ts
const { Record, Address, List, Nat } = require('@tezwell/michelson-sdk/literal');

const parameters = Record({
requests: List(
[
Record({
owner: Address("KT1JehYdejjvFf1BqdXzTPt1QWqqSd3xS4JF"),
token_id: Nat(0)
}),
Record({
owner: Address("tz1gTnKMA65qaKVpp6x4cgMLU2UyKF2zjHYN"),
token_id: Nat(0)
})
]
),
callback: Contract("KT1SiSomCunxkq3g7vQKYpPpWBHodhH5pJkU", "receive_balances")
}).toJSON();
```

### update_operators

- [Using Taquito](./taquito#update_operators)
- [Using ConseilJS](./conseiljs#update_operators)

```ts
const { Record, Address, List, Nat, Variant } = require('@tezwell/michelson-sdk/literal');
const { TRecord, TAddress, TNat, TVariant } = require('@tezwell/michelson-sdk/type');

const VariantType = TVariant({
add_operator: TRecord({
owner: TAddress(),
operator: TAddress(),
token_id: TNat(),
}),
remove_operator: TRecord({
owner: TAddress(),
operator: TAddress(),
token_id: TNat(),
})
});
const parameters = List(
[
Variant(
"add_operator",
Record({
owner: Address("tz1gTnKMA65qaKVpp6x4cgMLU2UyKF2zjHYN"),
operator: Address("KT1JehYdejjvFf1BqdXzTPt1QWqqSd3xS4JF"),
token_id: Nat(0),
}),
VariantType
),
Variant(
"remove_operator",
Record({
owner: Address("tz1gTnKMA65qaKVpp6x4cgMLU2UyKF2zjHYN"),
operator: Address("KT1JehYdejjvFf1BqdXzTPt1QWqqSd3xS4JF"),
token_id: Nat(0),
}),
VariantType
)
]
).toJSON();
```
195 changes: 195 additions & 0 deletions documentation/docs/conseiljs.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,195 @@
# Using with ConseilJS

## Install dependencies

```shell
npm install @tezwell/michelson-sdk conseiljs conseiljs-softsigner node-fetch loglevel
```

## Interact with an FA2 contract

### transfer

```ts
import fetch from 'node-fetch';
import log from 'loglevel';

import { registerFetch, registerLogger, TezosMessageUtils, TezosParameterFormat, TezosNodeWriter } from 'conseiljs';
import { KeyStoreUtils, SoftSigner } from 'conseiljs-softsigner';
import { Record, Address, List, Nat } from '@tezwell/michelson-sdk/literal';

const logger = log.getLogger('conseiljs');
logger.setLevel('debug', false); // to see only errors, set to 'error'
registerLogger(logger);
registerFetch(fetch);

const RPC = 'https://ithacanet.visualtez.com';
const contract = 'KT1JehYdejjvFf1BqdXzTPt1QWqqSd3xS4JF'

const parameters = List(
[
Record({
from_: Address('tz1gTnKMA65qaKVpp6x4cgMLU2UyKF2zjHYN'),
txs: List(
[
Record({
to_: Address('KT1JehYdejjvFf1BqdXzTPt1QWqqSd3xS4JF'),
token_id: Nat(0),
amount: Nat(10),
})
]
),
})
]
).toJSON();

(async () => {
const keyStore = await KeyStoreUtils.restoreIdentityFromSecretKey('edskS83aZUK3ijLrW5tTs1sDY3qLjSsMGyebKKLWP4RXSBh4LCivG2s1TezyZB5rEvvdqepXMg1MLcfBhS8VSJESN7L27hDpsX');
const signer = await SoftSigner.createSigner(TezosMessageUtils.writeKeyWithHint(keyStore.secretKey, 'edsk'), -1);

const result = await TezosNodeWriter.sendContractInvocationOperation(
RPC,
signer,
keyStore,
contract,
10_000,
100_000,
10_000,
100_000,
'transfer',
JSON.stringify(parameters),
TezosParameterFormat.Micheline
);
console.log("Injected operation: ", result.operationGroupID);
})();
```

### balance_of

```ts
import fetch from 'node-fetch';
import log from 'loglevel';

import { registerFetch, registerLogger, TezosMessageUtils, TezosParameterFormat, TezosNodeWriter } from 'conseiljs';
import { KeyStoreUtils, SoftSigner } from 'conseiljs-softsigner';
import { Record, Address, List, Nat, Contract } from '@tezwell/michelson-sdk/literal';

const logger = log.getLogger('conseiljs');
logger.setLevel('debug', false); // to see only errors, set to 'error'
registerLogger(logger);
registerFetch(fetch);

const RPC = 'https://ithacanet.visualtez.com';
const contract = 'KT1JehYdejjvFf1BqdXzTPt1QWqqSd3xS4JF'

const parameters = Record({
requests: List(
[
Record({
owner: Address("KT1JehYdejjvFf1BqdXzTPt1QWqqSd3xS4JF"),
token_id: Nat(0)
}),
Record({
owner: Address("tz1gTnKMA65qaKVpp6x4cgMLU2UyKF2zjHYN"),
token_id: Nat(0)
})
]
),
callback: Contract("KT1SiSomCunxkq3g7vQKYpPpWBHodhH5pJkU", "receive_balances")
}).toJSON();

(async () => {
const keyStore = await KeyStoreUtils.restoreIdentityFromSecretKey('edskS83aZUK3ijLrW5tTs1sDY3qLjSsMGyebKKLWP4RXSBh4LCivG2s1TezyZB5rEvvdqepXMg1MLcfBhS8VSJESN7L27hDpsX');
const signer = await SoftSigner.createSigner(TezosMessageUtils.writeKeyWithHint(keyStore.secretKey, 'edsk'), -1);

const result = await TezosNodeWriter.sendContractInvocationOperation(
RPC,
signer,
keyStore,
contract,
10_000,
100_000,
10_000,
100_000,
'balance_of',
JSON.stringify(parameters),
TezosParameterFormat.Micheline
);
console.log("Injected operation: ", result.operationGroupID);
})();
```

### update_operators

```ts
import fetch from 'node-fetch';
import log from 'loglevel';

import { registerFetch, registerLogger, TezosMessageUtils, TezosParameterFormat, TezosNodeWriter } from 'conseiljs';
import { KeyStoreUtils, SoftSigner } from 'conseiljs-softsigner';
import { Record, Address, List, Nat, Variant } from '@tezwell/michelson-sdk/literal';
import { TRecord, TAddress, TNat, TVariant } from '@tezwell/michelson-sdk/type';

const logger = log.getLogger('conseiljs');
logger.setLevel('debug', false); // to see only errors, set to 'error'
registerLogger(logger);
registerFetch(fetch);

const RPC = 'https://ithacanet.visualtez.com';
const contract = 'KT1JehYdejjvFf1BqdXzTPt1QWqqSd3xS4JF'

const VariantType = TVariant({
add_operator: TRecord({
owner: TAddress(),
operator: TAddress(),
token_id: TNat(),
}),
remove_operator: TRecord({
owner: TAddress(),
operator: TAddress(),
token_id: TNat(),
})
});
const parameters = List(
[
Variant(
"add_operator",
Record({
owner: Address("tz1gTnKMA65qaKVpp6x4cgMLU2UyKF2zjHYN"),
operator: Address("KT1JehYdejjvFf1BqdXzTPt1QWqqSd3xS4JF"),
token_id: Nat(0),
}),
VariantType
),
Variant(
"remove_operator",
Record({
owner: Address("tz1gTnKMA65qaKVpp6x4cgMLU2UyKF2zjHYN"),
operator: Address("KT1JehYdejjvFf1BqdXzTPt1QWqqSd3xS4JF"),
token_id: Nat(0),
}),
VariantType
)
]
).toJSON();

(async () => {
const keyStore = await KeyStoreUtils.restoreIdentityFromSecretKey('edskS83aZUK3ijLrW5tTs1sDY3qLjSsMGyebKKLWP4RXSBh4LCivG2s1TezyZB5rEvvdqepXMg1MLcfBhS8VSJESN7L27hDpsX');
const signer = await SoftSigner.createSigner(TezosMessageUtils.writeKeyWithHint(keyStore.secretKey, 'edsk'), -1);

const result = await TezosNodeWriter.sendContractInvocationOperation(
RPC,
signer,
keyStore,
contract,
10_000,
100_000,
10_000,
100_000,
'update_operators',
JSON.stringify(parameters),
TezosParameterFormat.Micheline
);
console.log("Injected operation: ", result.operationGroupID);
})();
```
Loading

0 comments on commit b5c6c23

Please sign in to comment.