-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
docs(taquito, conseiljs, fa2, values): Adds value documentation and u…
…sage examples
- Loading branch information
Showing
8 changed files
with
996 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
})(); | ||
``` |
Oops, something went wrong.