Git Product home page Git Product logo

trustsdk-react-native's Introduction

@trustwallet/rn-sdk

npm version CI

@trustwallet/rn-sdk is Trust Wallet's react native SDK, it allows you to request accounts, sign messages and transactions.

Installation

npm i @trustwallet/rn-sdk @trustwallet/wallet-core

Configuring Android

Make sure you have set up intent-filter for your app (documentation here)

The example app settings:

<activity
  android:name=".MainActivity"
  android:launchMode="singleTask"
    <intent-filter>
        <action android:name="android.intent.action.VIEW" />
        <category android:name="android.intent.category.DEFAULT" />
        <data android:scheme="trust-rn-example"/>
    </intent-filter>
</activity>

Configuring iOS

Make sure you have set up url scheme for your app (Open Xcode an click on your project. Go to the 'Info' tab and expand the 'URL Types' group).

The example app settings:

<key>CFBundleURLTypes</key>
<array>
  <dict>
    <key>CFBundleTypeRole</key>
    <string>Editor</string>
    <key>CFBundleURLSchemes</key>
    <array>
      <string>trust-rn-example</string>
    </array>
  </dict>
</array>
// iOS 9.x or newer
#import <React/RCTLinkingManager.h>

- (BOOL)application:(UIApplication *)application
   openURL:(NSURL *)url
   options:(NSDictionary<UIApplicationOpenURLOptionsKey,id> *)options
{
  return [RCTLinkingManager application:application openURL:url options:options];
}

// If your app is using Universal Links
- (BOOL)application:(UIApplication *)application continueUserActivity:(NSUserActivity *)userActivity
 restorationHandler:(void (^)(NSArray * _Nullable))restorationHandler
{
 return [RCTLinkingManager application:application
                  continueUserActivity:userActivity
                    restorationHandler:restorationHandler];
}

Example

Checkout the example typescript project in example folder.

git clone [email protected]:TrustWallet/react-native-trust-sdk.git
cd react-native-trust-sdk/example
npm install && npm start

Run iOS

react-native run-ios

Run Android

react-native run-android
iOS demo Android tx demo
demo ios gif demo android gif

Usage

import the package:

import TrustWallet, {CoinType} from '@trustwallet/rn-sdk'

initialize an instance, e.g. in componentDidMount:

const wallet = new TrustWallet('<your_app_scheme>://');

request ETH/BNB accounts:

wallet.requestAccounts([CoinType.ethereum, CoinType.binance])
.then((accounts) => {
  Alert.alert('Accounts', accounts.join('\n'))
}).catch(error => {
  Alert.alert('Error', JSON.stringify(error))
})

sign an Ethereum message:

const message = utils.keccak256(this.ethereumMessage("Some message"))
wallet.signMessage(message, CoinType.ethereum)
.then((result) => {
  Alert.alert('Signature', result)
}).catch(error => {
  Alert.alert('Error', JSON.stringify(error))
})

sign an Ethereum transaction:

// tx should comply TW.Ethereum.Proto.ISigningInput from @trustwallet/wallet-core
const tx = {
  toAddress: '0x728B02377230b5df73Aa4E3192E89b6090DD7312',
  chainId: Buffer.from('0x01', 'hex'),
  nonce: this.serializeBigInt('447'),
  gasPrice: this.serializeBigInt('2112000000'),
  gasLimit: this.serializeBigInt('21000'),
  amount: this.serializeBigInt('100000000000000')
}
wallet.signTransaction(tx, CoinType.ethereum, send)
.then(result =>{
  Alert.alert('Transaction', result)
}).catch(error => {
  Alert.alert('Error', JSON.stringify(error))
})

clean up all resolve handlers, e.g. incomponentWillUnmount:

wallet.cleanup();

Contributing

You are welcome! Create pull requests and help to improve the package.

License

MIT

trustsdk-react-native's People

Contributors

dependabot[bot] avatar hewigovens avatar vcoolish avatar vikmeup avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

trustsdk-react-native's Issues

CRITICAL: Can't get accounts anymore - sdk_get_accounts

Recently, the function for getting an account is deleted. For sending crypto via https://developer.trustwallet.com/deeplinking#send-payment we need to know the destination and if both users have TrustWallet it becomes a ridiculously stupid flow where the user has to go and copy address manually.

Is this done by mistake or its intended behaviour? And if it's intended - then why we can't get public info as we did before?
https://web.archive.org/web/20201107135200/https://developer.trustwallet.com/trust-sdk/trust-sdk-specs

sdk_get_accounts

@vcoolish do you have any ideas?

Getting "No application found" when signing transaction

I'm trying to sign and complete a transaction via Trust Wallet from my react-native app, but I get this error after clicking the "sign" button on the transaction confirmation page. Can you tell me what the source of the issue might be?

I am using version 0.0.6 of the react-native-trust-sdk.

screen shot 2019-02-26 at 8 27 42 pm

My react-native code:

`
ToAddress = '0x3408a7c8B4104B2ee03F70a15d705256fDF97605';
amount = '1000000000000000';
appScheme = 'com.myapp://';

wallet = new TrustWallet(appScheme);
payload = new TransactionPayload(toAddress, amount, 'test payment');

wallet.signTransaction(payload)
.then((result) => {
  console.log('Transaction Signed', result);
})
.catch((error) => {
  console.log('Error', error);
});

}`

Deep Link is not supported

Whenever I try to do any kind of action but installed, I'm getting redirected into the wallet and alert message appears "Deep Link is not supported". I test on iOS 14.4.1. I also enabled dApp browser if it matters. SDK version is 0.2.3

Trust Wallet not installed Error

Hi. I posted before as well regarding this issue. I tried both the example and made my own app too but i keep on getting (Trust wallet is not installed) even tho it is installed on my phone.
Can someone guide me in how to resolve this?
WhatsApp Image 2020-07-09 at 22 33 39

This is my android app scheme code



and this is my main file code
image

the response i get
{"app": {"AppStoreURL": "https://itunes.apple.com/us/app/trust-ethereum-wallet/id1288339409", "GooglePlayURL": "https://play.google.com/store/apps/details?id=com.wallet.crypto.trustapp", "name": "Trust", "scheme": "trust://"}, "callbackId": 1594315992400, "callbackScheme": "com.web3example://", "rejectors": {}, "resolvers": {}}

Any sort of help will be appreciated.

"urlString" doesn't contain "id" param

Hi, I think I found a bug. I had tried to sign Transaction in example project, but alert with signed data didn't appear. I think the problem in parseURL(urlString) function:

    function parseURL(urlString) {
        const url = new whatwg_url_1.URL(urlString);
        const id = url.searchParams.get('id') || '';
        let result = url.searchParams.get('result') || '';
        result = result.replace(/ /g, '+');
        return {
            'id': id,
            'result': buffer_1.Buffer.from(result, 'base64').toString('hex')
        };
    }

"urlString" in response looks like this:

trust-rn-example://sign-transaction?result=+HkFhDuaygCCUgiU5HSUN5wdSO5zRUwl…X19fGHQozQt2DqKcCciQcPQUSdbxG/oAWNtubEbQFsWWBesQyl278qdo1tt0Lk3IhYkWK9oYvl

It doesn't contain "id" param, but this code tries to parse this from response:

const id = url.searchParams.get('id') || '';

Problem with deeplink

Hello)
I have a problem with deeplink.
When I push button to redirect with data to your app, I see only main screen.
Maybe I must to setup deeplink on right route or something like this to get on transaction screen. Or I must to update react-native-trust-sdk to latest version.

React native trust sdk: ^0.0.2

missing script: start

When I run "npm start". It's throwing npm: error! missing script: start.

Please could you fix this. I am new to react native and android

Not able to Sign Transactions

Hi. I'm not navigated to the Trust Wallet Transaction screen but instead it just gives me a response back of my data.

WhatsApp Image 2020-09-04 at 22 34 08

I'm not sure why. But if i press on Ethereum Button. It navigates me to Trust Wallet but not in the case of Sign Ethereum Message.

  <intent-filter>
    <action android:name="android.intent.action.MAIN" />
    <category android:name="android.intent.category.LAUNCHER" />
  </intent-filter>
  <intent-filter>
    <action android:name="android.intent.action.VIEW" />
    <category android:name="android.intent.category.DEFAULT" />
    <data android:scheme="trust-rn-example"/>
  </intent-filter>

  <intent-filter>
    <action android:name="android.intent.action.VIEW" />
    <category android:name="android.intent.category.DEFAULT" />
    <data android:scheme="trust"/>
  </intent-filter>

Untitled

"@trustwallet/rn-sdk": "^0.2.2",
"@trustwallet/wallet-core": "0.0.6",
"buffer": "^5.6.0",
"console": "^0.7.2",
"ethers": "^5.0.8",
"react": "16.9.0",
"react-native": "0.61.4",

Help is appreciated.

have no auth screen

hi,
when SignMessage or SignTransaction, can open the trust wallet App,
but there have no auth screen in the trust App.

HIMW9137 2019-03-29 15_39_31

Request Account return empty Array

wallet?.requestAccounts(coins: CoinType[]) .then((accounts) => { Alert.alert('Accounts', accounts.join('\n')); }) .catch((error) => { console.log(error); Alert.alert('Error', JSON.stringify(error)); });

I've cloned the example provided. I've also installed Trust wallet.

On pressing the a coin (let's say BTC), I'm redirected to Trust wallet for permission. When I accept, it gets redirected to app but on alert I'm receiving an empty array.
Kindly Help

WhatsApp.Video.2021-06-09.at.9.15.03.PM.mp4

White screen when try sign transaction on Android

Hi! I run example project from this repository: on ios sign transaction and sign message work fine, but on android when i try sign transaction TrustWallet open white screen:
ezgif-5-54ffce6fb239

click sign transaction -> empty screen (word at header means sign ). I can only return back.

Tested at real devices: 7 and 8 versions.

I am able to open trust wallet but not able to sign message

Hi,
I have installed trustwallet in ios and was able to run the app in the emulator. I ran the example from trustwallet sdk when i click sign message it is opening the trustwallet and nothing after that. How do i make transactions or how do i use web3 to get the logged in user details.

Absolutely ridiculous

How do you put a wallet out that doesn’t work properly ? My money is stuck in a vault and I can’t get it out because I keep getting deep link not supported. I wrote trust wallet support over a week ago and still no response!!! Please help !

I got error when i run example on ios sumilator

I got an error when I run the example on ios simulator.

I have no idea what is going on.

I think I have the mistake of installing phase but I cannot figure it out.

trust-sdk

And also, I do not have trust wallet app in my simulator.
How can react-native-trust-SDK work in simulator without trust app

Blank white screen on signMessage and signTransaction

This is what i have done.

export default class Home extends React.Component {
signMsg() {
        const payload = new MessagePayload('hello trust');
        wallet.signMessage(payload).then((result) => {
            console.log('Message Signed '+ result);
        }).catch((error) => {
            console.log('Error '+ error);
        });
    }

    signTrnx() {
        const payload = new TransactionPayload('0xe47494379c1d48ee73454c251a6395fdd4f9eb43', '1', 'hello trust');
        wallet.signTransaction(payload).then((result) => {
            console.log('Transaction Signed '+ result);
        })
        .catch((error) => {
            console.log('Error '+ error);
        });
    }
    render() {
        return(
                 <View>
                            <button title='Sign message'  onPress={() => this.signMsg()} />
                </View>
       )
    }
}

Wallet creation

Hello! Is it possible to create trustwallet using this sdk?

time and network

In doing all online activities it is better to first check the appropriate network and time.

Unable to sign transactions on BSC

Hello!

Can TrustSDK sign transactions for BSC BNB token (c714 universal asset id https://developer.trustwallet.com/trust-sdk/trust-sdk-specs#sign-simple-transaction)?

If I pass only to address – it responds with "sign_error". If I pass to and from addresses – it responds with "account_error", but both accounts are mine, with enough amount of BNB to make transactions/transfers.

Another side, I cannot sign transaction Sign Arbitrary Transaction (https://developer.trustwallet.com/trust-sdk/trust-sdk-specs#sign-arbitrary-transaction) with data field produced from WalletCore Swift SDK (BSC network):

    let signerInput = EthereumSigningInput.with {
      $0.chainID = Data(hexString: "38")!
      $0.gasPrice = Data(hexString: "09184e72a000")!
      $0.gasLimit = Data(hexString: "2710")!
      $0.toAddress = "0x73feaa1ee314f8c655e354234017be2193c9e24e"
      
      $0.transaction = EthereumTransaction.with {
        $0.contractGeneric = EthereumTransaction.ContractGeneric.with {
          $0.data = Data(hexString:"41441d3b00000000000000000000000000000000000000000000000000354a6ba7a18000")!
        }
      }
    }
  
    let data: Data
    
    do {
      try data = signerInput.serializedData()
      print("TW data: ", data.hexString)
    } catch {
      print("TW error")
    }

If I try to call PancakeSwap contract method to stake with payload built on the native Swift WalletCore SDK and properly encoded – no success too, TrustWallet said "coin_not_supported".

Can anyone help with this? Or just proof that TrustSDK cannot work with BNB (BSC).

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.