Skip to content

Commit

Permalink
soroban update
Browse files Browse the repository at this point in the history
  • Loading branch information
paulfears committed Sep 11, 2023
1 parent 3b96a73 commit 88fdfe4
Show file tree
Hide file tree
Showing 11 changed files with 811 additions and 73 deletions.
105 changes: 105 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -128,8 +128,113 @@ const success = await ethereum.request({
}
})
```
### 'signTransaction'
This method signs an Arbitary Transaction
```javascript
async function signTransaction(){
const transaction = new StellarSdk.TransactionBuilder(account, { fee, networkPassphrase: "Test SDF Network ; September 2015" });
// Add a payment operation to the transaction
console.log("transaction builder initilazed");
await transaction.addOperation(StellarSdk.Operation.payment({
destination: receiverPublicKey,
// The term native asset refers to lumens
asset: StellarSdk.Asset.native(),
// Specify 350.1234567 lumens. Lumens are divisible to seven digits past
// the decimal. They are represented in JS Stellar SDK in string format
// to avoid errors from the use of the JavaScript Number data structure.
amount: '350.1234567',
}));
console.log("operations added")
// Make this transaction valid for the next 30 seconds only
await transaction.setTimeout(30);
console.log("timeout set");
// Uncomment to add a memo (https://www.stellar.org/developers/learn/concepts/transactions.html)
// .addMemo(StellarSdk.Memo.text('Hello world!'))
const endTransaction = await transaction.build();
const xdrTransaction = endTransaction.toXDR();
console.log(xdrTransaction);
const response = await ethereum.request({
method: 'wallet_invokeSnap',
params:{snapId:snapId, request:{
method: 'signTransaction',
params:{
transaction: xdrTransaction,
testnet: testnet
}
}}
})
console.log(response);
}
```
### 'Soroban'
The Wallet also supports sorroban, To sign a SorobanCall
futurenet must be set to true on the params object.
```javascript
async function callContract() {
console.log("here in callContract");
const sourcePublicKey = await ethereum.request({
method: 'wallet_invokeSnap',
params: {snapId:snapId, request:{
method: 'getAddress',
}}
})
const server = new SorobanClient.Server('https://rpc-futurenet.stellar.org');

console.log("getting account")
const account = await server.getAccount(sourcePublicKey);
console.log("account is: ")
console.log(account);

console.log(SorobanClient);

const contract = new SorobanClient.Contract("CCNLUNUY66TU4MB6JK4Y4EHVQTAO6KDWXDUSASQD2BBURMQT22H2CQU7")
console.log(contract)
const arg = SorobanClient.nativeToScVal("world")
console.log("arg is: ")
console.log(arg)
let call_operation = contract.call('hello', arg);
console.log(call_operation)

let transaction = new SorobanClient.TransactionBuilder(account, { fee: "150", networkPassphrase: SorobanClient.Networks.FUTURENET })
.addOperation(call_operation) // <- funds and creates destinationA
.setTimeout(30)
.build();

console.log(transaction)


const preparedTransaction = await server.prepareTransaction(transaction, SorobanClient.Networks.FUTURENET);
console.log("prepairedTxn: ");
console.log(preparedTransaction);
const tx_XDR = preparedTransaction.toXDR();
const signedXDR = await ethereum.request(
{method: 'wallet_invokeSnap',
params: {
snapId:snapId,
request:{
method: 'signTransaction',
params:{
transaction: tx_XDR,
futurenet: true
}
}
}
}
)
console.log(signedXDR)
try{

const transactionResult = await server.sendTransaction(signedXDR);
console.log(JSON.stringify(transactionResult, null, 2));
console.log('\nSuccess! View the transaction at: ');
console.log(transactionResult)
} catch (e) {
console.log('An error has occured:');
console.log(e);
}
}

```
## building from Source

```shell
Expand Down
Loading

0 comments on commit 88fdfe4

Please sign in to comment.