Skip to content

Commit

Permalink
Merge pull request #24 from CityOfZion/CU-86a15fpmw
Browse files Browse the repository at this point in the history
CU-86a15fpmw - Document NeonDappkit: signing transactions with different wallets
  • Loading branch information
luc10921 authored Nov 23, 2023
2 parents 47b419f + 17bbf2d commit cb962eb
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"changes": [
{
"packageName": "@cityofzion/neon-dappkit",
"comment": "",
"type": "none"
}
],
"packageName": "@cityofzion/neon-dappkit"
}
53 changes: 53 additions & 0 deletions packages/neon-dappkit/NEON-INVOKER.md
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,59 @@ const resp = await invoker.calculateFee({
console.log(resp) // will print an object with `networkFee`, `systemFee` and `total`
```

### Signing a Transaction using multiple Accounts of different Environments/Wallets
It's very interesting to allow different accounts to sign the same transaction. It might be a backend paying for the user
transaction or a transaction that must be signed by two different individuals to be valid.

It's possible to call `signTransaction` using the same arguments of `invokeFunction`. It will not send the transaction to
the blockchain, instead, it will only sign the transaction. The returned information can be used to invoke the function,
or it can be resigned to add even more signers on the transaction.

On the following example we are sending GAS from the "owner" to the "payer", but the "payer" is paying the
transaction fees:
```ts

const accountPayer = new wallet.Account('fb1f57cc1347ae5b6251dc8bae761362d2ecaafec4c87f4dc9e97fef6dd75014') // NbnjKGMBJzJ6j5PHeYhjJDaQ5Vy5UYu4Fv
const accountOwner = new wallet.Account('3bd06d95e9189385851aa581d182f25de34af759cf7f883af57030303ded52b8') // NhGomBpYnKXArr55nHRQ5rzy79TwKVXZbr

const invokerPayer = await NeonInvoker.init({
rpcAddress: NeonInvoker.TESTNET,
account: accountPayer,
})

const builtTransaction = await invokerPayer.signTransaction({
invocations: [
{
scriptHash: '0xd2a4cff31913016155e38e474a2c06d08be276cf',
operation: 'transfer',
args: [ // the owner is sending to payer but the payer is paying for the tx
{ type: 'Hash160', value: accountOwner.address },
{ type: 'Hash160', value: accountPayer.address },
{ type: 'Integer', value: '100000000' },
{ type: 'Array', value: [] },
],
},
],
signers: [
{
account: accountPayer.scriptHash,
scopes: 'CalledByEntry',
},
{ // this can be retrived using NeonParser.accountInputToScripthash(addressOrPublicKey)
account: accountOwner.scriptHash,
scopes: 'CalledByEntry',
},
],
})

const invokerOwner = await NeonInvoker.init({
rpcAddress: NeonInvoker.TESTNET,
account: accountOwner,
})

const txId = await invokerOwner.invokeFunction(builtTransaction)
```

### More Details

For more details on the methods signature, check the auto-generated
Expand Down

0 comments on commit cb962eb

Please sign in to comment.