Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: remove near-api-js account object dependency from change functions #38

3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@
<img alt="GitHub Pre-release" src="https://img.shields.io/github/v/release/NEARBuilders/near-social-js?include_prereleases&label=pre-release&logo=github">
</a>
<a href="https://github.com/NEARBuilders/near-social-js/releases">
<img alt="GitHub Pre-release Date - Published At" src="https://img.shields.io/github/release-date-pre/NEARBuilders/near-social-js?label=pre-release%20date&logo=github
">
<img alt="GitHub Pre-release Date - Published At" src="https://img.shields.io/github/release-date-pre/NEARBuilders/near-social-js?label=pre-release%20date&logo=github">
</a>
</p>

Expand Down
81 changes: 28 additions & 53 deletions docs/advanced/granting-write-permission.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -32,20 +32,17 @@ Accounts can grant write permission to other accounts for a set of keys.
```js
const { Social } = require('@builddao/near-social-js');

const grantee = await nearConnection.account('alice.near');
const granter = await nearConnection.account('bob.near');
const accessKeys = await granter.getAccessKeys();
const social = new Social();
const transaction = await social.grantWritePermission({
blockHash: accessKeys[0].block_hash,
granteeAccountId: grantee.accountId,
granteeAccountId: 'alice.near',
keys: [
'alice.near/profile/name',
'alice.near/profile/image/url',
],
nonce: BigInt(accessKeys[0].nonce + 1), // the nonce to be used for the transaction, must be greater than the access key nonce
publicKey: accessKeys[0].public_key,
signer: granter,
signer: {
accountID: 'bob.near',
publicKey: 'ed25519:H9k5eiU4xXS3M4z8HzKJSLaZdqGdGwBG49o7orNC4eZW',
},
});

// ...sign the returned transaction and post to the network
Expand All @@ -56,41 +53,22 @@ Accounts can grant write permission to other accounts for a set of keys.
<TabItem value="javascript-via-cdn">

```js
var accessKeys;
var grantee;
var granter;
var social;

nearConnection.account('alice.near')
.then((_granter) => {
granter = _granter;

return nearConnection.account('bob.near');
})
.then((_grantee) => {
grantee = _grantee;

return granter.getAccessKeys();
})
.then((_accessKeys) => {
accessKeys = _accessKeys;
social = new NEARSocialSDK();

return social.grantWritePermission({
blockHash: accessKeys[0].block_hash,
granteeAccountId: grantee.accountId,
keys: [
'alice.near/profile/name',
'alice.near/profile/image/url',
],
nonce: BigInt(accessKeys[0].nonce + 1), // the nonce to be used for the transaction, must be greater than the access key nonce
publicKey: accessKeys[0].public_key,
signer: granter,
});
})
.then((transaction) => {
// ...sign the returned transaction and post to the network
});
var social = new NEARSocialSDK();

social.grantWritePermission({
granteeAccountId: 'alice.near',
keys: [
'alice.near/profile/name',
'alice.near/profile/image/url',
],
signer: {
accountID: 'bob.near',
publicKey: 'ed25519:H9k5eiU4xXS3M4z8HzKJSLaZdqGdGwBG49o7orNC4eZW'
}
})
.then((transaction) => {
// ...sign the returned transaction and post to the network
});
```

</TabItem>
Expand All @@ -99,20 +77,17 @@ Accounts can grant write permission to other accounts for a set of keys.
```typescript
import { Social } from '@builddao/near-social-js';

const grantee = await nearConnection.account('alice.near');
const granter = await nearConnection.account('bob.near');
const accessKeys = await granter.getAccessKeys();
const social = new Social();
const transaction = await social.grantWritePermission({
blockHash: accessKeys[0].block_hash,
granteeAccountId: grantee.accountId,
granteeAccountId: 'alice.near',
keys: [
'alice.near/profile/name',
'alice.near/profile/image/url',
],
nonce: BigInt(accessKeys[0].nonce + 1), // the nonce to be used for the transaction, must be greater than the access key nonce
publicKey: accessKeys[0].public_key,
signer: granter,
signer: {
accountID: 'bob.near',
publicKey: 'ed25519:H9k5eiU4xXS3M4z8HzKJSLaZdqGdGwBG49o7orNC4eZW',
},
});

// ...sign the returned transaction and post to the network
Expand All @@ -124,12 +99,12 @@ Accounts can grant write permission to other accounts for a set of keys.

:::caution

If the grantee account ID or the account ID in each key is not a valid account ID then a [`InvalidAccountIdError`](../../api-reference/errors#invalidaccountiderror) is thrown.
If the grantee account ID or the account ID in each key is not a valid account ID then a [`InvalidAccountIdError`](../api-reference/errors#invalidaccountiderror) is thrown.

:::

:::caution

If a key does is not owned by the granter, then a [`KeyNotAllowedError`](../../api-reference/errors#keynotallowederror) is thrown.
If a key does is not owned by the granter, then a [`KeyNotAllowedError`](../api-reference/errors#keynotallowederror) is thrown.

:::
6 changes: 0 additions & 6 deletions docs/advanced/reading-data.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ Getting specific values, like the example from above, you can use a set of keys:
'alice.near/profile/image/url',
'bob.near/profile/name',
],
rpcURL //rpc url for your network.
});

console.log(result);
Expand Down Expand Up @@ -95,7 +94,6 @@ Getting specific values, like the example from above, you can use a set of keys:
'alice.near/profile/image/url',
'bob.near/profile/name',
],
rpcURL //rpc url for your network.
}).then((result) => {
console.log(result);
/*
Expand Down Expand Up @@ -135,7 +133,6 @@ Getting specific values, like the example from above, you can use a set of keys:
'alice.near/profile/image/url',
'bob.near/profile/name',
],
rpcURL //rpc url for your network.
});

console.log(result);
Expand Down Expand Up @@ -186,7 +183,6 @@ The [`get`](../api-reference/social#getoptions) function also supports wildcard
keys: [
'alice.near/profile/**',
],
rpcURL //rpc url for your network.
});

console.log(result);
Expand Down Expand Up @@ -214,7 +210,6 @@ The [`get`](../api-reference/social#getoptions) function also supports wildcard
keys: [
'alice.near/profile/**',
],
rpcURL, //rpc url for your network.
}).then((result) => {
console.log(result);
/*
Expand Down Expand Up @@ -243,7 +238,6 @@ The [`get`](../api-reference/social#getoptions) function also supports wildcard
keys: [
'alice.near/profile/**'
],
rpcURL, //rpc url for your network.
});

console.log(result);
Expand Down
Loading